Skip to content

Commit

Permalink
cmake: add pthread dependency explicitly when linking to a Boost library
Browse files Browse the repository at this point in the history
Change-Id: I36695dfcaf58bef5e6b9738432f9a1e695f68d70
  • Loading branch information
riebl committed Jan 24, 2018
1 parent 28c75a4 commit 2a68b7b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Expand Up @@ -6,6 +6,11 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Look up threading library (usually pthread)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads MODULE)

# Build configuration
option(BUILD_USING_CONAN "Build with conan package manager" OFF)
if(BUILD_USING_CONAN)
Expand Down
9 changes: 6 additions & 3 deletions cmake/GoogleTestTargets.cmake
Expand Up @@ -40,9 +40,12 @@ target_link_libraries(${GTest_MAIN_LIBRARY} PUBLIC ${GTest_LIBRARY})
add_dependencies(${GTest_MAIN_LIBRARY} extract_gtest)

# Look for threading library and configure GTest accordingly
set(CMAKE_THREAD_PREFER_PTHREAD True)
set(THREADS_PREFER_PTHREAD_FLAG True)
find_package(Threads QUIET)
if(NOT DEFINED CMAKE_USE_PTHREADS_INIT)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads MODULE)
endif()

if(CMAKE_USE_PTHREADS_INIT)
message(STATUS "Build GTest with pthread support")
target_compile_definitions(${GTest_LIBRARY} PUBLIC "GTEST_HAS_PTHREAD=1")
Expand Down
5 changes: 5 additions & 0 deletions cmake/VanetzaConfig.cmake.in
Expand Up @@ -8,6 +8,7 @@ include(MacroFindDependencyComponents)

find_dependency_components(Boost VERSION @Boost_MAJOR_VERSION@.@Boost_MINOR_VERSION@ COMPONENTS @Boost_COMPONENTS@)
find_dependency(GeographicLib @GeographicLib_VERSION_STRING@)
find_dependency(Threads)

if(@CryptoPP_FOUND@)
find_dependency(CryptoPP @CryptoPP_VERSION_STRING@)
Expand All @@ -25,6 +26,10 @@ if(@OPENSSL_FOUND@)
find_dependency(OpenSSL ${OPENSSL_VERSION_WITHOUT_PATCH})
endif()

if(@THREADS_FOUND@)
find_dependency(Threads)
endif()

# Restore previous module path
list(REMOVE_AT CMAKE_MODULE_PATH -1)

Expand Down
1 change: 1 addition & 0 deletions cmake/VanetzaExportsConfig.cmake.in
Expand Up @@ -8,6 +8,7 @@ find_dependency_components(Boost VERSION @Boost_MAJOR_VERSION@.@Boost_MINOR_VERS
include(CompatBoostTargets)

find_dependency(GeographicLib @GeographicLib_VERSION_STRING@)
find_dependency(Threads)

if(@CryptoPP_FOUND@)
find_dependency(CryptoPP @CryptoPP_VERSION_STRING@)
Expand Down
4 changes: 4 additions & 0 deletions vanetza/common/CMakeLists.txt
Expand Up @@ -12,5 +12,9 @@ target_link_libraries(common
PUBLIC Boost::date_time
INTERFACE Boost::serialization)

if(TARGET Threads::Threads)
target_link_libraries(common INTERFACE Threads::Threads)
endif()

add_test_subdirectory(tests)

0 comments on commit 2a68b7b

Please sign in to comment.