comparison cmake/function/IrccdDefineLibrary.cmake @ 710:a17de53db29b

Misc: export libraries Export all libraries with CMake and install headers. While here, build Duktape as object library to avoid exporting it. Don't mix static/dynamic libraries anymore. closes #867 closes #439
author David Demelier <markand@malikania.fr>
date Sat, 07 Jul 2018 14:03:04 +0200
parents 65a54b126c08
children 8c44bbcbbab9
comparison
equal deleted inserted replaced
709:1b04ffb2b35e 710:a17de53db29b
20 # irccd_define_library 20 # irccd_define_library
21 # -------------------- 21 # --------------------
22 # 22 #
23 # irccd_define_library( 23 # irccd_define_library(
24 # TARGET target name 24 # TARGET target name
25 # EXPORT (Optional) set to true to export library through irccd
26 # EXTERN (Optional) set to true to mark library as external
27 # HEADERS (Optional) headers to install
28 # HEADERS_DIRECTORY (Optional) subdirectory where to install headers
25 # SOURCES src1, src2, srcn 29 # SOURCES src1, src2, srcn
26 # LOCAL (Optional) set to true to build a static library
27 # EXTERNAL (Optional) set to true if library is third party
28 # FLAGS (Optional) C/C++ flags (without -D) 30 # FLAGS (Optional) C/C++ flags (without -D)
29 # LIBRARIES (Optional) libraries to link 31 # LIBRARIES (Optional) libraries to link
30 # LOCAL_INCLUDES (Optional) local includes for the target only 32 # LOCAL_INCLUDES (Optional) local includes for the target only
31 # PUBLIC_INCLUDES (Optional) includes to share with target dependencies 33 # PUBLIC_INCLUDES (Optional) includes to share with target dependencies
32 # ) 34 # )
33 # 35 #
34 36
35 include(${CMAKE_CURRENT_LIST_DIR}/IrccdVeraCheck.cmake) 37 include(${CMAKE_CURRENT_LIST_DIR}/IrccdVeraCheck.cmake)
36 38
37 function(irccd_define_library) 39 function(irccd_define_library)
38 set(options EXTERNAL LOCAL) 40 set(options EXPORT)
39 set(oneValueArgs TARGET) 41 set(oneValueArgs HEADERS_DIRECTORY TARGET)
40 set(multiValueArgs SOURCES FLAGS LIBRARIES LOCAL_INCLUDES PUBLIC_INCLUDES) 42 set(multiValueArgs HEADERS SOURCES FLAGS LIBRARIES LOCAL_INCLUDES PUBLIC_INCLUDES)
41 set(mandatory TARGET SOURCES)
42 43
43 cmake_parse_arguments(LIB "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 44 cmake_parse_arguments(LIB "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
44 45
45 if (NOT LIB_TARGET) 46 if (NOT LIB_TARGET)
46 message(FATAL_ERROR "Please set TARGET") 47 message(FATAL_ERROR "Please set TARGET")
47 endif () 48 endif ()
48 if (NOT LIB_SOURCES) 49 if (NOT LIB_SOURCES)
49 message(FATAL_ERROR "Please set SOURCES") 50 message(FATAL_ERROR "Please set SOURCES")
50 endif () 51 endif ()
51 if (LIB_LOCAL)
52 set(type STATIC)
53 endif ()
54 52
55 add_library(${LIB_TARGET} ${type} ${LIB_SOURCES}) 53 add_library(${LIB_TARGET} ${LIB_SOURCES} ${LIB_HEADERS})
56 target_include_directories(${LIB_TARGET} PRIVATE ${LIB_LOCAL_INCLUDES} PUBLIC ${LIB_PUBLIC_INCLUDES}) 54 target_include_directories(${LIB_TARGET} PRIVATE ${LIB_LOCAL_INCLUDES} PUBLIC ${LIB_PUBLIC_INCLUDES})
57 target_compile_definitions( 55 target_compile_definitions(
58 ${LIB_TARGET} 56 ${LIB_TARGET}
59 PRIVATE 57 PRIVATE
60 CMAKE_BINARY_DIR="${CMAKE_BINARY_DIR}" 58 CMAKE_BINARY_DIR="${CMAKE_BINARY_DIR}"
76 PROPERTIES 74 PROPERTIES
77 RUNTIME_OUTPUT_DIRECTORY_${cu} ${CMAKE_BINARY_DIR}/bin/${c} 75 RUNTIME_OUTPUT_DIRECTORY_${cu} ${CMAKE_BINARY_DIR}/bin/${c}
78 ) 76 )
79 endforeach() 77 endforeach()
80 78
81 if (NOT ${LIB_EXTERNAL}) 79 if (NOT ${LIB_EXTERN})
82 irccd_vera_check(${LIB_TARGET} "${LIB_SOURCES}") 80 irccd_vera_check(${LIB_TARGET} "${LIB_SOURCES}")
83 endif () 81 endif ()
82
83 if (${LIB_EXPORT})
84 install(
85 TARGETS ${LIB_TARGET}
86 EXPORT irccd-targets
87 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
88 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
89 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
90 )
91 endif ()
92
93 if (LIB_HEADERS)
94 if (NOT LIB_HEADERS_DIRECTORY)
95 message(FATAL_ERROR "HEADERS_DIRECTORY must be defined")
96 endif ()
97
98 install(
99 FILES ${LIB_HEADERS}
100 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${LIB_HEADERS_DIRECTORY}
101 )
102 endif ()
84 endfunction() 103 endfunction()