Mercurial > malikania
diff cmake/function/MalikaniaDefineLibrary.cmake @ 49:2804ae55c70f
CMake: big cleanup, closes #598
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 09 Dec 2016 13:28:45 +0100 |
parents | |
children | 0edaba9986ba |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmake/function/MalikaniaDefineLibrary.cmake Fri Dec 09 13:28:45 2016 +0100 @@ -0,0 +1,72 @@ +# +# MalikaniaDefineLibrary.cmake -- CMake build system for malikania +# +# Copyright (c) 2013-2016 Malikania Authors +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +# +# malikania_define_library +# ------------------------ +# +# malikania_define_library( +# TARGET The target name +# SOURCES The sources +# ASSETS (Optional) Additional assets files +# FLAGS (Optional) List of flags +# PRIVATE_INCLUDES (Optional) List of includes only for building the library +# PUBLIC_INCLUDES (Optional) List of public includes to share with the library users +# LIBRARIES (Optional) List of libraries to link against +# ) +# +# Create a shared library. Follow the same specification as malikania_define_executable. +# However, additional PRIVATE_INCLUDES and PUBLIC_INCLUDES are available. +# + +include(CMakeParseArguments) + +include(${CMAKE_CURRENT_LIST_DIR}/MalikaniaBuildAssets.cmake) + +function(malikania_define_library) + set(singleArgs TARGET) + set(multiArgs ASSETS SOURCES FLAGS PRIVATE_INCLUDES PUBLIC_INCLUDES LIBRARIES) + set(mandatory TARGET SOURCES) + + cmake_parse_arguments(LIB "" "${singleArgs}" "${multiArgs}" ${ARGN}) + + if (NOT LIB_TARGET) + message(FATAL_ERROR "Missing TARGET parameter") + endif () + if (NOT LIB_SOURCES) + message(FATAL_ERROR "Missing SOURCES parameter") + endif () + + # Enable assets for libraries. + malikania_build_assets("${LIB_ASSETS}" assets) + + # Create the shared library. + add_library(${LIB_TARGET} SHARED ${LIB_SOURCES} ${assets}) + set_target_properties(${LIB_TARGET} PROPERTIES PREFIX "") + target_link_libraries(${LIB_TARGET} ${LIB_LIBRARIES}) + target_include_directories( + ${LIB_TARGET} + PRIVATE + ${CMAKE_CURRENT_BINARY_DIR}/assets + ${LIB_PRIVATE_INCLUDES} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${LIB_PUBLIC_INCLUDES} + ) + target_compile_definitions(${LIB_TARGET} PRIVATE ${LIB_FLAGS}) +endfunction()