| 1 |
cmake_minimum_required(VERSION 3.10) |
| 2 |
project(TestFindBoost CXX) |
| 3 |
include(CTest) |
| 4 |
|
| 5 |
set(Boost_NO_BOOST_CMAKE ON) |
| 6 |
find_package(Boost REQUIRED COMPONENTS filesystem thread |
| 7 |
OPTIONAL_COMPONENTS program_options foobar) |
| 8 |
|
| 9 |
if(Boost_FOOBAR_FOUND) |
| 10 |
message(FATAL_ERROR "Optional inexistent Boost component \"foobar\" found which is unexpected") |
| 11 |
endif(Boost_FOOBAR_FOUND) |
| 12 |
|
| 13 |
if(NOT Boost_PROGRAM_OPTIONS_FOUND) |
| 14 |
message(FATAL_ERROR "Optional Boost component \"program_options\" not found which is unexpected") |
| 15 |
endif(NOT Boost_PROGRAM_OPTIONS_FOUND) |
| 16 |
|
| 17 |
add_definitions(-DCMAKE_EXPECTED_BOOST_VERSION="${Boost_VERSION}") |
| 18 |
add_definitions(-DCMAKE_EXPECTED_BOOST_VERSION_COMPONENTS="${Boost_VERSION_STRING}") |
| 19 |
|
| 20 |
add_executable(test_boost_tgt main.cxx) |
| 21 |
target_link_libraries(test_boost_tgt |
| 22 |
Boost::dynamic_linking |
| 23 |
Boost::disable_autolinking |
| 24 |
Boost::filesystem |
| 25 |
Boost::thread) |
| 26 |
add_test(NAME test_boost_tgt COMMAND test_boost_tgt) |
| 27 |
|
| 28 |
add_executable(test_boost_var main.cxx) |
| 29 |
target_include_directories(test_boost_var PRIVATE ${Boost_INCLUDE_DIRS}) |
| 30 |
target_link_libraries(test_boost_var PRIVATE ${Boost_FILESYSTEM_LIBRARIES} ${Boost_SYSTEM_LIBRARIES} ${Boost_THREAD_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) |
| 31 |
add_test(NAME test_boost_var COMMAND test_boost_var) |