From 699238f08ffd9ebf1594c5692dc965c67c290817 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 17 Aug 2019 10:23:15 +0200 Subject: [PATCH] Fix build with older cmake --- CMakeLists.txt | 3 ++- CMakeModules/Boost/BoostConfig.cmake | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 CMakeModules/Boost/BoostConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 4394887..0966c95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,7 +136,8 @@ IF( WIN32 ) # iphlpapi.lib ENDIF(WIN32) -FIND_PACKAGE(Boost COMPONENTS ${BOOST_COMPONENTS} REQUIRED) +set(Boost_DIR "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/Boost") +FIND_PACKAGE(Boost CONFIG COMPONENTS ${BOOST_COMPONENTS} ) IF(NOT WIN32) MESSAGE(STATUS "Configuring fc to build on Unix/Apple") diff --git a/CMakeModules/Boost/BoostConfig.cmake b/CMakeModules/Boost/BoostConfig.cmake new file mode 100644 index 0000000..a5e01f2 --- /dev/null +++ b/CMakeModules/Boost/BoostConfig.cmake @@ -0,0 +1,18 @@ +# This overrides `find_package(Boost ... CONFIG ... )` calls +# - calls the CMake's built-in `FindBoost.cmake` and adds `pthread` library dependency + +MESSAGE(STATUS "Using custom FindBoost config") + +find_package(Boost 1.58 REQUIRED COMPONENTS ${Boost_FIND_COMPONENTS}) + +# Inject `pthread` dependency to Boost if needed +if (UNIX AND NOT CYGWIN) + list(FIND Boost_FIND_COMPONENTS thread _using_boost_thread) + if (_using_boost_thread GREATER -1) + find_library(BOOST_THREAD_LIBRARY NAMES pthread DOC "The threading library used by boost-thread") + if (BOOST_THREAD_LIBRARY) + MESSAGE(STATUS "Adding Boost thread lib dependency: ${BOOST_THREAD_LIBRARY}") + list(APPEND Boost_LIBRARIES ${BOOST_THREAD_LIBRARY}) + endif () + endif () +endif ()