comparison 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
comparison
equal deleted inserted replaced
48:3be179ba3226 49:2804ae55c70f
1 #
2 # MalikaniaDefineLibrary.cmake -- CMake build system for malikania
3 #
4 # Copyright (c) 2013-2016 Malikania Authors
5 #
6 # Permission to use, copy, modify, and/or distribute this software for any
7 # purpose with or without fee is hereby granted, provided that the above
8 # copyright notice and this permission notice appear in all copies.
9 #
10 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #
18
19 #
20 # malikania_define_library
21 # ------------------------
22 #
23 # malikania_define_library(
24 # TARGET The target name
25 # SOURCES The sources
26 # ASSETS (Optional) Additional assets files
27 # FLAGS (Optional) List of flags
28 # PRIVATE_INCLUDES (Optional) List of includes only for building the library
29 # PUBLIC_INCLUDES (Optional) List of public includes to share with the library users
30 # LIBRARIES (Optional) List of libraries to link against
31 # )
32 #
33 # Create a shared library. Follow the same specification as malikania_define_executable.
34 # However, additional PRIVATE_INCLUDES and PUBLIC_INCLUDES are available.
35 #
36
37 include(CMakeParseArguments)
38
39 include(${CMAKE_CURRENT_LIST_DIR}/MalikaniaBuildAssets.cmake)
40
41 function(malikania_define_library)
42 set(singleArgs TARGET)
43 set(multiArgs ASSETS SOURCES FLAGS PRIVATE_INCLUDES PUBLIC_INCLUDES LIBRARIES)
44 set(mandatory TARGET SOURCES)
45
46 cmake_parse_arguments(LIB "" "${singleArgs}" "${multiArgs}" ${ARGN})
47
48 if (NOT LIB_TARGET)
49 message(FATAL_ERROR "Missing TARGET parameter")
50 endif ()
51 if (NOT LIB_SOURCES)
52 message(FATAL_ERROR "Missing SOURCES parameter")
53 endif ()
54
55 # Enable assets for libraries.
56 malikania_build_assets("${LIB_ASSETS}" assets)
57
58 # Create the shared library.
59 add_library(${LIB_TARGET} SHARED ${LIB_SOURCES} ${assets})
60 set_target_properties(${LIB_TARGET} PROPERTIES PREFIX "")
61 target_link_libraries(${LIB_TARGET} ${LIB_LIBRARIES})
62 target_include_directories(
63 ${LIB_TARGET}
64 PRIVATE
65 ${CMAKE_CURRENT_BINARY_DIR}/assets
66 ${LIB_PRIVATE_INCLUDES}
67 PUBLIC
68 ${CMAKE_CURRENT_SOURCE_DIR}
69 ${LIB_PUBLIC_INCLUDES}
70 )
71 target_compile_definitions(${LIB_TARGET} PRIVATE ${LIB_FLAGS})
72 endfunction()