Skip to content

Commit

Permalink
Merge pull request #772
Browse files Browse the repository at this point in the history
cmake: improve linking to reduce unneeded dependencies
  • Loading branch information
arogge committed Apr 1, 2021
2 parents c78dc9b + 91e1ce9 commit a735e14
Show file tree
Hide file tree
Showing 17 changed files with 154 additions and 243 deletions.
27 changes: 3 additions & 24 deletions core/CMakeLists.txt
Expand Up @@ -294,8 +294,6 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")

set(HAVE_WIN32 1)

set(WINDOWS_LIBRARIES ws2_32)

set(Python2_LIBRARIES python27.dll)
set(Python3_LIBRARIES python38.dll)

Expand Down Expand Up @@ -652,7 +650,7 @@ if(${acl})
if(NOT HAVE_WIN32)
if(${HAVE_SYS_ACL_H})
set(HAVE_ACL 1)
message(STATUS "acl found, libs: ${ACL_LIBS}")
message(STATUS "acl found, libs: ${ACL_LIBRARIES}")
else()
message(FATAL_ERROR "build with acl requested, but lib not found")
endif()
Expand Down Expand Up @@ -682,13 +680,11 @@ set(have_glusterfs ${HAVE_GLUSTERFS_API_GLFS_H})
if(NOT HAVE_WIN32)
if(${ndmp})
set(HAVE_NDMP 1)
set(NDMP_LIBS bareosndmp)
endif()
endif()

if(${lmdb})
set(HAVE_LMDB 1)
set(LMDB_LIBS bareoslmdb)
endif()

# info what the config files need to be installed PLUGINS ############
Expand Down Expand Up @@ -875,7 +871,7 @@ message(" build-dird: ${build_dird} ")
message(" build-stored: ${build_stored} ")
message(" Plugin support: ${have_plugins} ")
message(" AFS support: ${have_afs} ")
message(" ACL support: ${HAVE_ACL} ${ACL_LIBS}")
message(" ACL support: ${HAVE_ACL} ${ACL_LIBRARIES}")
message(" XATTR support: ${have_xattr} ")
message(
" SCSI Crypto support: ${scsi-crypto} ${HAVE_LOWLEVEL_SCSI_INTERFACE} "
Expand All @@ -901,24 +897,7 @@ message(
message(" systemd support: ${WITH_SYSTEMD} ${SYSTEMD_UNITDIR}")
message(" Batch insert enabled: ${USE_BATCH_FILE_INSERT}")
message(" PostgreSQL Version: ${PostgreSQL_VERSION_STRING} ")
if(GTEST_FOUND)
message(
" gtest support: ${GTEST_FOUND} ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} "
)
if(GMOCK_FOUND)
message(
" gmock support: ${GMOCK_FOUND} ${GMOCK_LIBRARIES} "
)
else()
message(
" gmock support: ${GMOCK_FOUND} (some unit tests will be disabled)"
)
endif()
else()
message(
" gtest support: ${GTEST_FOUND} (unit tests will be disabled)"
)
endif()
message(" GTest enabled: ${GTest_FOUND}")
message(
" Intl support: ${Intl_FOUND} ${INTLINCLUDE_DIRS} ${INTL_LIBRARIES}"
)
Expand Down
5 changes: 1 addition & 4 deletions core/cmake/BareosFindAllLibraries.cmake
Expand Up @@ -188,11 +188,8 @@ bareosfindlibrary("tirpc")
bareosfindlibrary("util")
bareosfindlibrary("dl")
bareosfindlibrary("acl")
# BareosFindLibrary("wrap")
if(NOT ${CMAKE_CXX_COMPILER_ID} MATCHES SunPro)
bareosfindlibrary("gtest")
bareosfindlibrary("gtest_main")
bareosfindlibrary("gmock")
find_package(GTest 1.8 CONFIG)
endif()

bareosfindlibrary("pam_wrapper")
Expand Down
5 changes: 4 additions & 1 deletion core/cmake/thread.cmake
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2019-2019 Bareos GmbH & Co. KG
# Copyright (C) 2019-2021 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand All @@ -21,6 +21,9 @@ include(CheckIncludeFiles)
include(CheckCSourceCompiles)
include(CMakePushCheckState)

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

# check for extra non-portable header-file
check_include_files("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)

Expand Down
4 changes: 2 additions & 2 deletions core/src/CMakeLists.txt
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2017-2020 Bareos GmbH & Co. KG
# Copyright (C) 2017-2021 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -37,7 +37,7 @@ if(RUN_SYSTEMTESTS_ON_INSTALLED_FILES)
message(
status "Skipping unit tests as testing on installed files is requested"
)
elseif(NOT GTEST_FOUND)
elseif(NOT GTest_FOUND)
message(status "Skipping unit tests as gtest was not found")
else()
add_subdirectory(tests)
Expand Down
4 changes: 2 additions & 2 deletions core/src/console/CMakeLists.txt
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2017-2020 Bareos GmbH & Co. KG
# Copyright (C) 2017-2021 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -43,7 +43,7 @@ else()
set(CONSOLE_LINK_LIBRARIES console_objects bareos ${Readline_LIBRARY})
endif()

target_link_libraries(bconsole ${CONSOLE_LINK_LIBRARIES})
target_link_libraries(bconsole ${CONSOLE_LINK_LIBRARIES} ${JANSSON_LIBRARIES})

install(
TARGETS bconsole
Expand Down
36 changes: 25 additions & 11 deletions core/src/dird/CMakeLists.txt
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2017-2020 Bareos GmbH & Co. KG
# Copyright (C) 2017-2021 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -113,7 +113,6 @@ if(HAVE_WIN32)
${PROJECT_SOURCE_DIR}/src/win32/generic
${PROJECT_SOURCE_DIR}/src/win32/dird
)
list(APPEND DIRDSRCS ../win32/generic/main.cc ../win32/generic/service.cc)
endif()

set(DBCHKSRCS dbcheck.cc dird_conf.cc dird_globals.cc ua_acl.cc ua_audit.cc
Expand Down Expand Up @@ -145,28 +144,43 @@ set(DIRD_RESTYPES

# dird_objects is also used as library for unittests
add_library(dird_objects STATIC ${DIRD_OBJECTS_SRCS})
target_link_libraries(dird_objects ${NDMP_LIBS})
target_link_libraries(
dird_objects PRIVATE ${OPENSSL_LIBRARIES} Threads::Threads
${JANSSON_LIBRARIES}
)

add_executable(bareos-dir ${DIRDSRCS})
add_executable(bareos-dir)
target_sources(bareos-dir PRIVATE dird.cc)

set(BAREOS_DIR_LIBRARIES dird_objects bareos bareoscats bareossql bareosfind
${LMDB_LIBS} ${NDMP_LIBS}
target_link_libraries(
bareos-dir PRIVATE dird_objects bareos bareoscats bareossql bareosfind
)

if(HAVE_WIN32)
list(APPEND BAREOS_DIR_LIBRARIES comctl32)
target_sources(
bareos-dir PRIVATE ../win32/generic/main.cc ../win32/generic/service.cc
)
target_link_libraries(bareos-dir PRIVATE comctl32)
endif()

if(HAVE_NDMP)
target_link_libraries(dird_objects PRIVATE bareosndmp)
endif()

if(HAVE_LMDB)
target_link_libraries(dird_objects PRIVATE bareoslmdb)
endif()

if(HAVE_PAM)
target_link_libraries(bareos-dir ${BAREOS_DIR_LIBRARIES} ${PAM_LIBRARIES})
else()
target_link_libraries(bareos-dir ${BAREOS_DIR_LIBRARIES})
target_link_libraries(dird_objects PRIVATE ${PAM_LIBRARIES})
endif()

add_subdirectory(dbcopy)

add_executable(bareos-dbcheck ${DBCHKSRCS})
set(DBCHECK_LIBRARIES bareossql bareos bareosfind bareoscats)
set(DBCHECK_LIBRARIES bareossql bareos bareosfind bareoscats
${OPENSSL_LIBRARIES} ${JANSSON_LIBRARIES}
)

target_link_libraries(bareos-dbcheck ${DBCHECK_LIBRARIES})

Expand Down
3 changes: 1 addition & 2 deletions core/src/dird/dbcopy/CMakeLists.txt
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2020-2020 Bareos GmbH & Co. KG
# Copyright (C) 2020-2021 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -33,7 +33,6 @@ if(dynamic-cats-backends)
)
target_link_libraries(
bareos-dbcopy bareos dird_objects bareosfind bareoscats bareossql
$<$<BOOL:HAVE_PAM>:${PAM_LIBRARIES}> ${LMDB_LIBS}
)

install(TARGETS bareos-dbcopy DESTINATION "${sbindir}")
Expand Down
12 changes: 9 additions & 3 deletions core/src/filed/CMakeLists.txt
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2017-2020 Bareos GmbH & Co. KG
# Copyright (C) 2017-2021 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -64,11 +64,17 @@ endif()
include_directories(${OPENSSL_INCLUDE_DIR})

add_library(fd_objects STATIC ${FDSRCS})
target_link_libraries(fd_objects PUBLIC bareos)
target_link_libraries(
fd_objects PUBLIC bareos bareosfastlz ${ZLIB_LIBRARIES} ${JANSSON_LIBRARIES}
)

if(HAVE_LMDB)
target_link_libraries(fd_objects PRIVATE bareoslmdb)
endif()

add_executable(bareos-fd filed.cc)

set(BAREOS_FD_LIBRARIES bareosfind bareos pthread ${LMDB_LIBS})
set(BAREOS_FD_LIBRARIES bareosfind bareos Threads::Threads)
if(HAVE_WIN32)
target_sources(bareos-fd PRIVATE ../win32/generic/main.cc)
list(APPEND BAREOS_FD_LIBRARIES comctl32)
Expand Down
6 changes: 3 additions & 3 deletions core/src/findlib/CMakeLists.txt
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2017-2020 Bareos GmbH & Co. KG
# Copyright (C) 2017-2021 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -43,7 +43,7 @@ include_directories(${OPENSSL_INCLUDE_DIR})

add_library(bareosfind SHARED ${BAREOSFIND_SRCS})

target_link_libraries(bareosfind bareos ${ACL_LIBS})
target_link_libraries(bareosfind bareos ${ACL_LIBRARIES})

install(
TARGETS bareosfind
Expand All @@ -61,6 +61,6 @@ if(HAVE_WIN32)
set_target_properties(bareosfind PROPERTIES DEFINE_SYMBOL "BUILDING_DLL")
endif()

if(NOT HAVE_WIN32 AND GTEST_FOUND)
if(NOT HAVE_WIN32 AND GTest_FOUND)
# add_subdirectory(unittests)
endif()
5 changes: 2 additions & 3 deletions core/src/findlib/unittests/CMakeLists.txt
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2017-2020 Bareos GmbH & Co. KG
# Copyright (C) 2017-2021 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand All @@ -24,8 +24,7 @@ set(TEST_SRC # drivetype_test.cc

add_executable(test_findlib ${TEST_SRC})
target_link_libraries(
test_findlib bareosfind bareos ${JANSSON_LIBRARIES} ${GTEST_LIBRARIES}
${GTEST_MAIN_LIBRARIES}
test_findlib bareosfind bareos ${JANSSON_LIBRARIES} GTest::gtest_main
)

add_test(NAME test_findlib COMMAND "test_findlib")
Expand Down
16 changes: 4 additions & 12 deletions core/src/lib/CMakeLists.txt
Expand Up @@ -21,7 +21,6 @@ message("Entering ${CMAKE_CURRENT_SOURCE_DIR}")
include_directories(
${OPENSSL_INCLUDE_DIR} ${PTHREAD_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS}
${ACL_INCLUDE_DIRS} ${LZO2_INCLUDE_DIRS} ${CAP_INCLUDE_DIRS}
${WRAP_INCLUDE_DIRS}
)

set(BAREOS_SRCS
Expand Down Expand Up @@ -154,17 +153,9 @@ set_target_properties(version-obj PROPERTIES POSITION_INDEPENDENT_CODE ON)

target_link_libraries(
bareos
bareosfastlz
${OPENSSL_LIBRARIES}
${PTHREAD_LIBRARIES}
${ZLIB_LIBRARIES}
${ACL_LIBRARIES}
${LZO2_LIBRARIES}
${CAP_LIBRARIES}
${WRAP_LIBRARIES}
${CAM_LIBRARIES}
${WINDOWS_LIBRARIES}
${JANSSON_LIBRARIES}
PRIVATE bareosfastlz ${OPENSSL_LIBRARIES} Threads::Threads ${ZLIB_LIBRARIES}
${LZO2_LIBRARIES} ${CAP_LIBRARIES} ${JANSSON_LIBRARIES}
${CAM_LIBRARIES}
)

install(TARGETS bareos DESTINATION ${libdir})
Expand All @@ -176,4 +167,5 @@ set_target_properties(

if(HAVE_WIN32)
set_target_properties(bareos PROPERTIES DEFINE_SYMBOL "BUILDING_DLL")
target_link_libraries(bareos PUBLIC ws2_32)
endif()
6 changes: 4 additions & 2 deletions core/src/plugins/stored/CMakeLists.txt
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2017-2020 Bareos GmbH & Co. KG
# Copyright (C) 2017-2021 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -34,7 +34,9 @@ add_subdirectory(python)

add_library(autoxflate-sd MODULE autoxflate/autoxflate-sd.cc)
set_target_properties(autoxflate-sd PROPERTIES PREFIX "")
target_link_libraries(autoxflate-sd bareos)
target_link_libraries(
autoxflate-sd bareos bareosfastlz $<$<PLATFORM_ID:Windows>:${ZLIB_LIBRARIES}>
)
install(TARGETS autoxflate-sd DESTINATION ${plugindir})

if(NOT HAVE_WIN32 AND NOT HAVE_DARWIN_OS)
Expand Down
4 changes: 2 additions & 2 deletions core/src/qt-tray-monitor/CMakeLists.txt
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2017-2020 Bareos GmbH & Co. KG
# Copyright (C) 2017-2021 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -79,7 +79,7 @@ if(Qt5Widgets_FOUND)
qt5_use_modules(bareos-tray-monitor Widgets)
endif()

target_link_libraries(${TRAYMON_LIBRARIES})
target_link_libraries(${TRAYMON_LIBRARIES} ${JANSSON_LIBRARIES})

install(TARGETS bareos-tray-monitor DESTINATION "${bindir}")

Expand Down

0 comments on commit a735e14

Please sign in to comment.