Skip to content

Commit

Permalink
cmake: improve GTest and pthread usage
Browse files Browse the repository at this point in the history
Previously the raw libraries were used, now we use CMake's find_package
to find the GTest and Threads packages and use their targets for our
unit tests.
  • Loading branch information
arogge committed Mar 31, 2021
1 parent fecd524 commit f34f7f1
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 172 deletions.
19 changes: 1 addition & 18 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -901,24 +901,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion core/src/findlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit f34f7f1

Please sign in to comment.