]> granicus.if.org Git - icinga2/commitdiff
Use CMake object libraries for our libs 5993/head
authorGunnar Beutner <gunnar.beutner@icinga.com>
Wed, 17 Jan 2018 03:28:21 +0000 (04:28 +0100)
committerGunnar Beutner <gunnar.beutner@icinga.com>
Wed, 17 Jan 2018 03:28:21 +0000 (04:28 +0100)
19 files changed:
CMakeLists.txt
icinga-app/CMakeLists.txt
icinga-studio/CMakeLists.txt
lib/base/CMakeLists.txt
lib/checker/CMakeLists.txt
lib/cli/CMakeLists.txt
lib/compat/CMakeLists.txt
lib/config/CMakeLists.txt
lib/db_ido/CMakeLists.txt
lib/db_ido_mysql/CMakeLists.txt
lib/db_ido_pgsql/CMakeLists.txt
lib/icinga/CMakeLists.txt
lib/livestatus/CMakeLists.txt
lib/methods/CMakeLists.txt
lib/notification/CMakeLists.txt
lib/perfdata/CMakeLists.txt
lib/remote/CMakeLists.txt
plugins/CMakeLists.txt
test/CMakeLists.txt

index ec0fedc182ebc9c352cd526fcdf07e9db11c1264..c8bd97fbfb4903fb4805c714e2c66f96bab450b1 100644 (file)
@@ -142,6 +142,30 @@ include_directories(
   ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/lib
 )
 
+set(base_DEPS ${CMAKE_DL_LIBS} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${YAJL_LIBRARIES} mmatch socketpair)
+
+if(HAVE_LIBEXECINFO)
+  list(APPEND base_DEPS execinfo)
+endif()
+
+if(UNIX OR CYGWIN)
+  list(APPEND base_DEPS execvpe)
+endif()
+
+if(EDITLINE_FOUND)
+  list(APPEND base_DEPS ${EDITLINE_LIBRARIES})
+  include_directories(${EDITLINE_INCLUDE_DIR})
+endif()
+
+if(TERMCAP_FOUND)
+  list(APPEND base_DEPS ${TERMCAP_LIBRARIES})
+  include_directories(${TERMCAP_INCLUDE_DIR})
+endif()
+
+if(WIN32)
+  list(APPEND base_DEPS ws2_32 dbghelp shlwapi msi)
+endif()
+
 set(CMAKE_MACOSX_RPATH 1)
 
 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
@@ -177,21 +201,6 @@ if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
   endif()
 endif()
 
-if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
-  function(add_whole_static_library target library)
-    target_link_libraries(${target} -force_load ${library})
-  endfunction()
-elseif(MSVC)
-  function(add_whole_static_library target library)
-    target_link_libraries(${target} ${library})
-    set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS "/wholearchive:${library} ")
-  endfunction()
-else()
-  function(add_whole_static_library target library)
-    target_link_libraries(${target} -Wl,--whole-archive ${library} -Wl,--no-whole-archive)
-  endfunction()
-endif()
-
 include(CheckCXXCompilerFlag)
 
 function(check_cxx_linker_flag flag var)
index 2655b31bf65d01a3cdef46825603130b06648309..c599f2366c2ce5ef12b53a25c71452fb87dbf0ac 100644 (file)
@@ -31,49 +31,51 @@ add_dependencies(icingaloader base config cli)
 
 include_directories(${Boost_INCLUDE_DIRS})
 
-add_executable(icinga-app $<TARGET_OBJECTS:icingaloader>)
-
-add_whole_static_library(icinga-app base)
-add_whole_static_library(icinga-app config)
-add_whole_static_library(icinga-app remote)
-add_whole_static_library(icinga-app cli)
-
 if(ICINGA2_WITH_CHECKER)
-  add_whole_static_library(icinga-app checker)
+  list(APPEND icinga_app_SOURCES $<TARGET_OBJECTS:checker>)
 endif()
 
 if(ICINGA2_WITH_COMPAT)
-  add_whole_static_library(icinga-app compat)
+  list(APPEND icinga_app_SOURCES $<TARGET_OBJECTS:compat>)
 endif()
 
 if(ICINGA2_WITH_MYSQL OR ICINGA2_WITH_PGSQL)
-  add_whole_static_library(icinga-app db_ido)
+  list(APPEND icinga_app_SOURCES $<TARGET_OBJECTS:db_ido>)
 endif()
 
 if(ICINGA2_WITH_MYSQL)
-  add_whole_static_library(icinga-app db_ido_mysql)
+  list(APPEND icinga_app_SOURCES $<TARGET_OBJECTS:db_ido_mysql>)
 endif()
 
 if(ICINGA2_WITH_PGSQL)
-  add_whole_static_library(icinga-app db_ido_pgsql)
+  list(APPEND icinga_app_SOURCES $<TARGET_OBJECTS:db_ido_pgsql>)
 endif()
 
-add_whole_static_library(icinga-app icinga)
-
 if(ICINGA2_WITH_LIVESTATUS)
-  add_whole_static_library(icinga-app livestatus)
+  list(APPEND icinga_app_SOURCES $<TARGET_OBJECTS:livestatus>)
 endif()
 
-add_whole_static_library(icinga-app methods)
-
 if(ICINGA2_WITH_NOTIFICATION)
-  add_whole_static_library(icinga-app notification)
+  list(APPEND icinga_app_SOURCES $<TARGET_OBJECTS:notification>)
 endif()
 
 if(ICINGA2_WITH_PERFDATA)
-  add_whole_static_library(icinga-app perfdata)
+  list(APPEND icinga_app_SOURCES $<TARGET_OBJECTS:perfdata>)
 endif()
 
+add_executable(icinga-app
+  $<TARGET_OBJECTS:icingaloader>
+  $<TARGET_OBJECTS:base>
+  $<TARGET_OBJECTS:config>
+  $<TARGET_OBJECTS:remote>
+  $<TARGET_OBJECTS:cli>
+  $<TARGET_OBJECTS:icinga>
+  $<TARGET_OBJECTS:methods>
+  ${icinga_app_SOURCES}
+)
+
+target_link_libraries(icinga-app ${base_DEPS})
+
 set_target_properties (
   icinga-app PROPERTIES
   INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}/icinga2
index 6d281c79587503a29d5d52f31453e6323c5cd6bf..475fa595a15042c61ffdfb4354a5fbab105b9e4c 100644 (file)
@@ -32,14 +32,14 @@ set(icinga_studio_SOURCES
   connectform.cpp connectform.hpp
   mainform.cpp mainform.hpp
   icinga.icns ${WindowsSources}
+  $<TARGET_OBJECTS:base>
+  $<TARGET_OBJECTS:config>
+  $<TARGET_OBJECTS:remote>
 )
 
 add_executable(icinga-studio MACOSX_BUNDLE WIN32 ${icinga_studio_SOURCES})
 
-include_directories(${Boost_INCLUDE_DIRS})
-target_link_libraries(icinga-studio ${Boost_LIBRARIES} ${wxWidgets_LIBRARIES})
-add_whole_static_library(icinga-studio base)
-add_whole_static_library(icinga-studio remote)
+target_link_libraries(icinga-studio ${base_DEPS} ${wxWidgets_LIBRARIES})
 
 if(APPLE)
   set_source_files_properties(icinga.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
index e65a5d1faf224291e536178132f096e1de2f409f..48332ee6997c9410e5440cfda91998d1e5f995e6 100644 (file)
@@ -97,13 +97,7 @@ if(ICINGA2_UNITY_BUILD)
     mkunity_target(base base base_SOURCES)
 endif()
 
-add_library(base STATIC ${base_SOURCES})
-
-target_link_libraries(base ${CMAKE_DL_LIBS} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${YAJL_LIBRARIES} mmatch socketpair)
-
-if(HAVE_LIBEXECINFO)
-    target_link_libraries(base execinfo)
-endif()
+add_library(base OBJECT ${base_SOURCES})
 
 include_directories(${icinga2_SOURCE_DIR}/third-party/execvpe)
 link_directories(${icinga2_BINARY_DIR}/third-party/execvpe)
@@ -114,14 +108,6 @@ link_directories(${icinga2_BINARY_DIR}/third-party/mmatch)
 include_directories(${icinga2_SOURCE_DIR}/third-party/socketpair)
 link_directories(${icinga2_BINARY_DIR}/third-party/socketpair)
 
-if(UNIX OR CYGWIN)
-  target_link_libraries(base execvpe)
-endif()
-
-if(WIN32)
-  target_link_libraries(base ws2_32 dbghelp shlwapi msi)
-endif()
-
 set_target_properties (
   base PROPERTIES
   FOLDER Lib
index 0158562647f63bdff4c68184e88893d9d219ef71..f2a9f156c5e88297e3bae398ae61f06cf27711a2 100644 (file)
@@ -25,9 +25,9 @@ if(ICINGA2_UNITY_BUILD)
     mkunity_target(checker checker checker_SOURCES)
 endif()
 
-add_library(checker STATIC ${checker_SOURCES})
+add_library(checker OBJECT ${checker_SOURCES})
 
-target_link_libraries(checker ${Boost_LIBRARIES} base config icinga remote)
+add_dependencies(checker base config icinga remote)
 
 set_target_properties (
   checker PROPERTIES
index 3b946efb4e4ff18f044e42e604ba5475a584649e..4a89efa02357f19665bacec2750452e57589e842 100644 (file)
@@ -51,19 +51,9 @@ if(ICINGA2_UNITY_BUILD)
     mkunity_target(cli cli cli_SOURCES)
 endif()
 
-add_library(cli STATIC ${cli_SOURCES})
+add_library(cli OBJECT ${cli_SOURCES})
 
-target_link_libraries(cli ${Boost_LIBRARIES} base config remote)
-
-if(EDITLINE_FOUND)
-  target_link_libraries(cli ${EDITLINE_LIBRARIES})
-  include_directories(${EDITLINE_INCLUDE_DIR})
-endif()
-
-if(TERMCAP_FOUND)
-  target_link_libraries(cli ${TERMCAP_LIBRARIES})
-  include_directories(${TERMCAP_INCLUDE_DIR})
-endif()
+add_dependencies(cli base config remote)
 
 set_target_properties (
   cli PROPERTIES
index 6ad4d419590f7a42ac41b025c9f61aeee95aa33c..5dd249689c3196af3bede33b6f3189c51a328c91 100644 (file)
@@ -31,9 +31,9 @@ if(ICINGA2_UNITY_BUILD)
     mkunity_target(compat compat compat_SOURCES)
 endif()
 
-add_library(compat STATIC ${compat_SOURCES})
+add_library(compat OBJECT ${compat_SOURCES})
 
-target_link_libraries(compat ${Boost_LIBRARIES} base config icinga)
+add_dependencies(compat base config icinga)
 
 set_target_properties (
   compat PROPERTIES
index d78a313555c63b340f5617b9c16d6f3beb54964b..761cb8d6a49815b1c861da771d0f369adfc1569d 100644 (file)
@@ -52,9 +52,9 @@ if(ICINGA2_UNITY_BUILD)
     mkunity_target(config config config_SOURCES)
 endif()
 
-add_library(config STATIC ${config_SOURCES})
+add_library(config OBJECT ${config_SOURCES})
 
-target_link_libraries(config ${Boost_LIBRARIES} base)
+add_dependencies(config base)
 
 set_target_properties (
   config PROPERTIES
index 179e9d9a18eb0a0d59300aaeb3e5378f7beecfb6..b8f49fb288712bb49b1eeca2bb3d4e931df3e30b 100644 (file)
@@ -45,10 +45,9 @@ if(ICINGA2_UNITY_BUILD)
     mkunity_target(db_ido db_ido db_ido_SOURCES)
 endif()
 
-add_library(db_ido STATIC ${db_ido_SOURCES})
+add_library(db_ido OBJECT ${db_ido_SOURCES})
 
-include_directories(${Boost_INCLUDE_DIRS})
-target_link_libraries(db_ido ${Boost_LIBRARIES} base config icinga remote)
+add_dependencies(db_ido base config icinga remote)
 
 set_target_properties (
   db_ido PROPERTIES
index 326ac8f6f6fff54b9f4c305afb2decd61a90cee9..aedc19ddf5e640e315414b6f410b1b7e88d01762 100644 (file)
@@ -25,11 +25,11 @@ if(ICINGA2_UNITY_BUILD)
     mkunity_target(db_ido_mysql db_ido_mysql db_ido_mysql_SOURCES)
 endif()
 
-add_library(db_ido_mysql STATIC ${db_ido_mysql_SOURCES})
+add_library(db_ido_mysql OBJECT ${db_ido_mysql_SOURCES})
 
 include_directories(${MYSQL_INCLUDE_DIR})
 
-target_link_libraries(db_ido_mysql ${Boost_LIBRARIES} base config icinga db_ido)
+add_dependencies(db_ido_mysql base config icinga db_ido)
 
 set_target_properties (
   db_ido_mysql PROPERTIES
index 1b7d5ccbe6a4c94c3f56252d02e89f7a1f12e610..de7121da153d829d7acce2471b39a92dc3dca517 100644 (file)
@@ -25,11 +25,11 @@ if(ICINGA2_UNITY_BUILD)
     mkunity_target(db_ido_pgsql db_ido_pgsql db_ido_pgsql_SOURCES)
 endif()
 
-add_library(db_ido_pgsql STATIC ${db_ido_pgsql_SOURCES})
+add_library(db_ido_pgsql OBJECT ${db_ido_pgsql_SOURCES})
 
 include_directories(${PostgreSQL_INCLUDE_DIRS})
 
-target_link_libraries(db_ido_pgsql ${Boost_LIBRARIES} base config icinga db_ido)
+add_dependencies(db_ido_pgsql base config icinga db_ido)
 
 set_target_properties (
   db_ido_pgsql PROPERTIES
index fa2801e34317f00abf7bcf6e648295ec1578460c..25a1f0fe6f3d34fc1336952a2a096b5ea60d6bc0 100644 (file)
@@ -80,9 +80,9 @@ if(ICINGA2_UNITY_BUILD)
     mkunity_target(icinga icinga icinga_SOURCES)
 endif()
 
-add_library(icinga STATIC ${icinga_SOURCES})
+add_library(icinga OBJECT ${icinga_SOURCES})
 
-target_link_libraries(icinga ${Boost_LIBRARIES} base config remote)
+add_dependencies(icinga base config remote)
 
 set_target_properties (
   icinga PROPERTIES
index 36daacaa7c6e24c61355a347c3e85a6ca3e1dade..e2a0d98f7c2d22ad9c1e5321c696314e7b7ade72 100644 (file)
@@ -61,9 +61,9 @@ if(ICINGA2_UNITY_BUILD)
     mkunity_target(livestatus livestatus livestatus_SOURCES)
 endif()
 
-add_library(livestatus STATIC ${livestatus_SOURCES})
+add_library(livestatus OBJECT ${livestatus_SOURCES})
 
-target_link_libraries(livestatus ${Boost_LIBRARIES} base config icinga remote)
+add_dependencies(livestatus base config icinga remote)
 
 set_target_properties (
   livestatus PROPERTIES
index c59fde94f1b39cf7a284b5d9af6d97a30cdaf98b..e44116fbc55e4e25f929a451092edff434f6915b 100644 (file)
@@ -44,9 +44,9 @@ if(ICINGA2_UNITY_BUILD)
     mkunity_target(methods methods methods_SOURCES)
 endif()
 
-add_library(methods STATIC ${methods_SOURCES})
+add_library(methods OBJECT ${methods_SOURCES})
 
-target_link_libraries(methods ${Boost_LIBRARIES} base config icinga)
+add_dependencies(methods base config icinga)
 
 set_target_properties (
   methods PROPERTIES
index 88e6174a1cc973b84f13c8c48b7dd44e9d96a957..cf1a6d0ceafd66d2adf91cdab12a417ce161f044 100644 (file)
@@ -25,9 +25,9 @@ if(ICINGA2_UNITY_BUILD)
     mkunity_target(notification notification notification_SOURCES)
 endif()
 
-add_library(notification STATIC ${notification_SOURCES})
+add_library(notification OBJECT ${notification_SOURCES})
 
-target_link_libraries(notification ${Boost_LIBRARIES} base config icinga)
+add_dependencies(notification base config icinga)
 
 set_target_properties (
   notification PROPERTIES
index baf28a1a142b74a46ee72b436d94f3e75ae9190f..2072c3ddb51387c9be280bcb301d2588666507d6 100644 (file)
@@ -35,9 +35,9 @@ if(ICINGA2_UNITY_BUILD)
     mkunity_target(perfdata perfdata perfdata_SOURCES)
 endif()
 
-add_library(perfdata STATIC ${perfdata_SOURCES})
+add_library(perfdata OBJECT ${perfdata_SOURCES})
 
-target_link_libraries(perfdata ${Boost_LIBRARIES} base config icinga)
+add_dependencies(perfdata base config icinga)
 
 set_target_properties (
   perfdata PROPERTIES
index 2b5cbac8c07f352a62961102bbbef5d792a8ef4a..6877143a7e76893865766e0a4761a165eaf7f8ed 100644 (file)
@@ -67,10 +67,9 @@ if(ICINGA2_UNITY_BUILD)
     mkunity_target(remote remote remote_SOURCES)
 endif()
 
-add_library(remote STATIC ${remote_SOURCES})
+add_library(remote OBJECT ${remote_SOURCES})
 
-include_directories(${Boost_INCLUDE_DIRS})
-target_link_libraries(remote ${Boost_LIBRARIES} base config)
+add_dependencies(remote base config)
 
 set_target_properties (
   remote PROPERTIES
index e030029461d4837a2c45b8122c1e1f32c3ec56a8..34f0786bebe7495807b71543ca89f8532357a509 100644 (file)
 # along with this program; if not, write to the Free Software Foundation
 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
-add_executable ( check_nscp_api check_nscp_api.cpp  )
-target_link_libraries ( check_nscp_api ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_SYSTEM_LIBRARY})
-add_whole_static_library(check_nscp_api base)
-add_whole_static_library(check_nscp_api config)
-add_whole_static_library(check_nscp_api remote)
+add_executable(check_nscp_api
+  check_nscp_api.cpp
+  $<TARGET_OBJECTS:base>
+  $<TARGET_OBJECTS:config>
+  $<TARGET_OBJECTS:remote>
+)
+target_link_libraries(check_nscp_api ${base_DEPS})
 set_target_properties (
   check_nscp_api PROPERTIES
   INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}/icinga2
index a519fd1990b35595b81ce2c1a6013f48809f470f..8513cd6d220379d9aed073600ff25676750bf06e 100644 (file)
@@ -44,6 +44,10 @@ set(base_test_SOURCES
   icinga-notification.cpp
   icinga-perfdata.cpp
   remote-url.cpp
+  $<TARGET_OBJECTS:base>
+  $<TARGET_OBJECTS:config>
+  $<TARGET_OBJECTS:remote>
+  $<TARGET_OBJECTS:icinga>
 )
 
 if(ICINGA2_UNITY_BUILD)
@@ -52,6 +56,7 @@ endif()
 
 add_boost_test(base
   SOURCES test-runner.cpp ${base_test_SOURCES}
+  LIBRARIES ${base_DEPS}
   TESTS base_array/construct
         base_array/getset
         base_array/resize
@@ -137,14 +142,16 @@ add_boost_test(base
         remote_url/illegal_legal_strings
 )
 
-add_whole_static_library(${base_TARGET_NAME} base)
-add_whole_static_library(${base_TARGET_NAME} config)
-add_whole_static_library(${base_TARGET_NAME} icinga)
-
 if(ICINGA2_WITH_LIVESTATUS)
   set(livestatus_test_SOURCES
     livestatus-fixture.cpp
     livestatus.cpp
+    $<TARGET_OBJECTS:base>
+    $<TARGET_OBJECTS:config>
+    $<TARGET_OBJECTS:remote>
+    $<TARGET_OBJECTS:icinga>
+    $<TARGET_OBJECTS:livestatus>
+    $<TARGET_OBJECTS:methods>
   )
 
   if(ICINGA2_UNITY_BUILD)
@@ -153,19 +160,19 @@ if(ICINGA2_WITH_LIVESTATUS)
 
   add_boost_test(livestatus
     SOURCES test-runner.cpp ${livestatus_test_SOURCES}
+    LIBRARIES ${base_DEPS}
     TESTS livestatus/hosts livestatus/services
   )
-
-  add_whole_static_library(${livestatus_TARGET_NAME} base)
-  add_whole_static_library(${livestatus_TARGET_NAME} config)
-  add_whole_static_library(${livestatus_TARGET_NAME} icinga)
-  add_whole_static_library(${livestatus_TARGET_NAME} livestatus)
-  add_whole_static_library(${livestatus_TARGET_NAME} methods)
 endif()
 
 set(icinga_checkable_test_SOURCES
   icinga-checkable-fixture.cpp
   icinga-checkable-flapping.cpp
+  $<TARGET_OBJECTS:base>
+  $<TARGET_OBJECTS:config>
+  $<TARGET_OBJECTS:remote>
+  $<TARGET_OBJECTS:icinga>
+  $<TARGET_OBJECTS:cli>
 )
 
 if(ICINGA2_UNITY_BUILD)
@@ -174,13 +181,9 @@ endif()
 
 add_boost_test(icinga_checkable
   SOURCES test-runner.cpp ${icinga_checkable_test_SOURCES}
+  LIBRARIES ${base_DEPS}
   TESTS icinga_checkable_flapping/host_not_flapping
         icinga_checkable_flapping/host_flapping
         icinga_checkable_flapping/host_flapping_recover
         icinga_checkable_flapping/host_flapping_docs_example
 )
-
-add_whole_static_library(${icinga_checkable_TARGET_NAME} base)
-add_whole_static_library(${icinga_checkable_TARGET_NAME} config)
-add_whole_static_library(${icinga_checkable_TARGET_NAME} icinga)
-add_whole_static_library(${icinga_checkable_TARGET_NAME} cli)