CMakeLists.txt 1.1 KB

123456789101112131415161718192021222324252627
  1. cmake_minimum_required(VERSION 3.1)
  2. project(TestFindBoost CXX)
  3. include(CTest)
  4. find_package(Boost REQUIRED COMPONENTS filesystem thread
  5. OPTIONAL_COMPONENTS program_options foobar)
  6. if(Boost_FOOBAR_FOUND)
  7. message(FATAL_ERROR "Optional inexistent Boost component \"foobar\" found which is unexpected")
  8. endif(Boost_FOOBAR_FOUND)
  9. if(NOT Boost_PROGRAM_OPTIONS_FOUND)
  10. message(FATAL_ERROR "Optional Boost component \"program_options\" not found which is unexpected")
  11. endif(NOT Boost_PROGRAM_OPTIONS_FOUND)
  12. add_executable(test_boost_tgt main.cxx)
  13. target_link_libraries(test_boost_tgt
  14. Boost::dynamic_linking
  15. Boost::disable_autolinking
  16. Boost::filesystem
  17. Boost::thread)
  18. add_test(NAME test_boost_tgt COMMAND test_boost_tgt)
  19. add_executable(test_boost_var main.cxx)
  20. target_include_directories(test_boost_var PRIVATE ${Boost_INCLUDE_DIRS})
  21. target_link_libraries(test_boost_var PRIVATE ${Boost_FILESYSTEM_LIBRARIES} ${Boost_SYSTEM_LIBRARIES} ${Boost_THREAD_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
  22. add_test(NAME test_boost_var COMMAND test_boost_var)