From 2a9dceb3675c71475e0e95b204a319a5debfe808 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 17 Jan 2018 04:28:21 +0100 Subject: [PATCH] Use CMake object libraries for our libs --- CMakeLists.txt | 39 +++++++++++++++++++------------- icinga-app/CMakeLists.txt | 40 +++++++++++++++++---------------- icinga-studio/CMakeLists.txt | 8 +++---- lib/base/CMakeLists.txt | 16 +------------ lib/checker/CMakeLists.txt | 4 ++-- lib/cli/CMakeLists.txt | 14 ++---------- lib/compat/CMakeLists.txt | 4 ++-- lib/config/CMakeLists.txt | 4 ++-- lib/db_ido/CMakeLists.txt | 5 ++--- lib/db_ido_mysql/CMakeLists.txt | 4 ++-- lib/db_ido_pgsql/CMakeLists.txt | 4 ++-- lib/icinga/CMakeLists.txt | 4 ++-- lib/livestatus/CMakeLists.txt | 4 ++-- lib/methods/CMakeLists.txt | 4 ++-- lib/notification/CMakeLists.txt | 4 ++-- lib/perfdata/CMakeLists.txt | 4 ++-- lib/remote/CMakeLists.txt | 5 ++--- plugins/CMakeLists.txt | 12 +++++----- test/CMakeLists.txt | 33 ++++++++++++++------------- 19 files changed, 101 insertions(+), 111 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ec0fedc18..c8bd97fbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/icinga-app/CMakeLists.txt b/icinga-app/CMakeLists.txt index 2655b31bf..c599f2366 100644 --- a/icinga-app/CMakeLists.txt +++ b/icinga-app/CMakeLists.txt @@ -31,49 +31,51 @@ add_dependencies(icingaloader base config cli) include_directories(${Boost_INCLUDE_DIRS}) -add_executable(icinga-app $) - -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 $) endif() if(ICINGA2_WITH_COMPAT) - add_whole_static_library(icinga-app compat) + list(APPEND icinga_app_SOURCES $) endif() if(ICINGA2_WITH_MYSQL OR ICINGA2_WITH_PGSQL) - add_whole_static_library(icinga-app db_ido) + list(APPEND icinga_app_SOURCES $) endif() if(ICINGA2_WITH_MYSQL) - add_whole_static_library(icinga-app db_ido_mysql) + list(APPEND icinga_app_SOURCES $) endif() if(ICINGA2_WITH_PGSQL) - add_whole_static_library(icinga-app db_ido_pgsql) + list(APPEND icinga_app_SOURCES $) endif() -add_whole_static_library(icinga-app icinga) - if(ICINGA2_WITH_LIVESTATUS) - add_whole_static_library(icinga-app livestatus) + list(APPEND icinga_app_SOURCES $) endif() -add_whole_static_library(icinga-app methods) - if(ICINGA2_WITH_NOTIFICATION) - add_whole_static_library(icinga-app notification) + list(APPEND icinga_app_SOURCES $) endif() if(ICINGA2_WITH_PERFDATA) - add_whole_static_library(icinga-app perfdata) + list(APPEND icinga_app_SOURCES $) endif() +add_executable(icinga-app + $ + $ + $ + $ + $ + $ + $ + ${icinga_app_SOURCES} +) + +target_link_libraries(icinga-app ${base_DEPS}) + set_target_properties ( icinga-app PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}/icinga2 diff --git a/icinga-studio/CMakeLists.txt b/icinga-studio/CMakeLists.txt index 6d281c795..475fa595a 100644 --- a/icinga-studio/CMakeLists.txt +++ b/icinga-studio/CMakeLists.txt @@ -32,14 +32,14 @@ set(icinga_studio_SOURCES connectform.cpp connectform.hpp mainform.cpp mainform.hpp icinga.icns ${WindowsSources} + $ + $ + $ ) 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) diff --git a/lib/base/CMakeLists.txt b/lib/base/CMakeLists.txt index e65a5d1fa..48332ee69 100644 --- a/lib/base/CMakeLists.txt +++ b/lib/base/CMakeLists.txt @@ -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 diff --git a/lib/checker/CMakeLists.txt b/lib/checker/CMakeLists.txt index 015856264..f2a9f156c 100644 --- a/lib/checker/CMakeLists.txt +++ b/lib/checker/CMakeLists.txt @@ -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 diff --git a/lib/cli/CMakeLists.txt b/lib/cli/CMakeLists.txt index 3b946efb4..4a89efa02 100644 --- a/lib/cli/CMakeLists.txt +++ b/lib/cli/CMakeLists.txt @@ -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 diff --git a/lib/compat/CMakeLists.txt b/lib/compat/CMakeLists.txt index 6ad4d4195..5dd249689 100644 --- a/lib/compat/CMakeLists.txt +++ b/lib/compat/CMakeLists.txt @@ -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 diff --git a/lib/config/CMakeLists.txt b/lib/config/CMakeLists.txt index d78a31355..761cb8d6a 100644 --- a/lib/config/CMakeLists.txt +++ b/lib/config/CMakeLists.txt @@ -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 diff --git a/lib/db_ido/CMakeLists.txt b/lib/db_ido/CMakeLists.txt index 179e9d9a1..b8f49fb28 100644 --- a/lib/db_ido/CMakeLists.txt +++ b/lib/db_ido/CMakeLists.txt @@ -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 diff --git a/lib/db_ido_mysql/CMakeLists.txt b/lib/db_ido_mysql/CMakeLists.txt index 326ac8f6f..aedc19ddf 100644 --- a/lib/db_ido_mysql/CMakeLists.txt +++ b/lib/db_ido_mysql/CMakeLists.txt @@ -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 diff --git a/lib/db_ido_pgsql/CMakeLists.txt b/lib/db_ido_pgsql/CMakeLists.txt index 1b7d5ccbe..de7121da1 100644 --- a/lib/db_ido_pgsql/CMakeLists.txt +++ b/lib/db_ido_pgsql/CMakeLists.txt @@ -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 diff --git a/lib/icinga/CMakeLists.txt b/lib/icinga/CMakeLists.txt index fa2801e34..25a1f0fe6 100644 --- a/lib/icinga/CMakeLists.txt +++ b/lib/icinga/CMakeLists.txt @@ -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 diff --git a/lib/livestatus/CMakeLists.txt b/lib/livestatus/CMakeLists.txt index 36daacaa7..e2a0d98f7 100644 --- a/lib/livestatus/CMakeLists.txt +++ b/lib/livestatus/CMakeLists.txt @@ -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 diff --git a/lib/methods/CMakeLists.txt b/lib/methods/CMakeLists.txt index c59fde94f..e44116fbc 100644 --- a/lib/methods/CMakeLists.txt +++ b/lib/methods/CMakeLists.txt @@ -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 diff --git a/lib/notification/CMakeLists.txt b/lib/notification/CMakeLists.txt index 88e6174a1..cf1a6d0ce 100644 --- a/lib/notification/CMakeLists.txt +++ b/lib/notification/CMakeLists.txt @@ -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 diff --git a/lib/perfdata/CMakeLists.txt b/lib/perfdata/CMakeLists.txt index baf28a1a1..2072c3ddb 100644 --- a/lib/perfdata/CMakeLists.txt +++ b/lib/perfdata/CMakeLists.txt @@ -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 diff --git a/lib/remote/CMakeLists.txt b/lib/remote/CMakeLists.txt index 2b5cbac8c..6877143a7 100644 --- a/lib/remote/CMakeLists.txt +++ b/lib/remote/CMakeLists.txt @@ -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 diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index e03002946..34f0786be 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -15,11 +15,13 @@ # 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_link_libraries(check_nscp_api ${base_DEPS}) set_target_properties ( check_nscp_api PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}/icinga2 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a519fd199..8513cd6d2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -44,6 +44,10 @@ set(base_test_SOURCES icinga-notification.cpp icinga-perfdata.cpp remote-url.cpp + $ + $ + $ + $ ) 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 + $ + $ + $ + $ + $ + $ ) 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 + $ + $ + $ + $ + $ ) 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)