Skip to content

Commit 1f30141

Browse files
committed
cmake: Add BOOST_NO_CXX98_FUNCTION_BASE definition when needed
1 parent 6230d47 commit 1f30141

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

cmake/module/AddBoostIfNeeded.cmake

+22
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,28 @@ function(add_boost_if_needed)
3232
)
3333
endif()
3434

35+
# Prevent use of std::unary_function, which was removed in C++17,
36+
# and will generate warnings with newer compilers for Boost
37+
# older than 1.80.
38+
# See: https://github.com/boostorg/config/pull/430.
39+
include(CMakePushCheckState)
40+
cmake_push_check_state(RESET)
41+
set(CMAKE_REQUIRED_DEFINITIONS -DBOOST_NO_CXX98_FUNCTION_BASE)
42+
set(CMAKE_REQUIRED_INCLUDES ${Boost_INCLUDE_DIR})
43+
include(TryAppendCXXFlags)
44+
set(CMAKE_REQUIRED_FLAGS ${working_compiler_werror_flag})
45+
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
46+
check_cxx_source_compiles("
47+
#include <boost/config.hpp>
48+
" NO_DIAGNOSTICS_BOOST_NO_CXX98_FUNCTION_BASE
49+
)
50+
cmake_pop_check_state()
51+
if(NO_DIAGNOSTICS_BOOST_NO_CXX98_FUNCTION_BASE)
52+
target_compile_definitions(Boost::headers INTERFACE
53+
BOOST_NO_CXX98_FUNCTION_BASE
54+
)
55+
endif()
56+
3557
if(BUILD_TESTS)
3658
include(CheckCXXSourceCompiles)
3759
set(CMAKE_REQUIRED_INCLUDES ${Boost_INCLUDE_DIR})

0 commit comments

Comments
 (0)