Przeglądaj źródła

Merge topic 'boost-optional-components'

2557cad5 FindBoost: support OPTIONAL_COMPONENTS

Acked-by: Kitware Robot <[email protected]>
Acked-by: Paul "TBBle" Hampson <[email protected]>
Merge-request: !1660
Brad King 8 lat temu
rodzic
commit
5d13fa1010

+ 5 - 3
Modules/FindBoost.cmake

@@ -13,6 +13,9 @@
 #     [version] [EXACT]      # Minimum or EXACT version e.g. 1.36.0
 #     [REQUIRED]             # Fail with error if Boost is not found
 #     [COMPONENTS <libs>...] # Boost libraries by their canonical name
+#                            # e.g. "date_time" for "libboost_date_time"
+#     [OPTIONAL_COMPONENTS <libs>...]
+#                            # Optional Boost libraries by their canonical name)
 #     )                      # e.g. "date_time" for "libboost_date_time"
 #
 # This module finds headers and requested component libraries OR a CMake
@@ -1777,10 +1780,9 @@ if(Boost_FOUND)
   set(_boost_CHECKED_COMPONENT FALSE)
   set(_Boost_MISSING_COMPONENTS "")
   foreach(COMPONENT ${Boost_FIND_COMPONENTS})
-    string(TOUPPER ${COMPONENT} COMPONENT)
+    string(TOUPPER ${COMPONENT} UPPERCOMPONENT)
     set(_boost_CHECKED_COMPONENT TRUE)
-    if(NOT Boost_${COMPONENT}_FOUND)
-      string(TOLOWER ${COMPONENT} COMPONENT)
+    if(NOT Boost_${UPPERCOMPONENT}_FOUND AND Boost_FIND_REQUIRED_${COMPONENT})
       list(APPEND _Boost_MISSING_COMPONENTS ${COMPONENT})
     endif()
   endforeach()

+ 14 - 0
Tests/FindBoost/CMakeLists.txt

@@ -9,6 +9,20 @@ add_test(NAME FindBoost.Test COMMAND
   --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
   )
 
+add_test(NAME FindBoost.TestFail COMMAND
+  ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+  --build-and-test
+  "${CMake_SOURCE_DIR}/Tests/FindBoost/TestFail"
+  "${CMake_BINARY_DIR}/Tests/FindBoost/TestFail"
+  ${build_generator_args}
+  --build-project TestFailFindBoost
+  --build-options ${build_options}
+  --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+  )
+
+set_tests_properties(FindBoost.TestFail PROPERTIES
+  PASS_REGULAR_EXPRESSION "Could not find the following Boost libraries:[ \t\n]+boost_foobar")
+
 add_test(NAME FindBoost.TestHeaders COMMAND
   ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
   --build-and-test

+ 10 - 1
Tests/FindBoost/Test/CMakeLists.txt

@@ -2,7 +2,16 @@ cmake_minimum_required(VERSION 3.1)
 project(TestFindBoost CXX)
 include(CTest)
 
-find_package(Boost REQUIRED COMPONENTS filesystem thread)
+find_package(Boost REQUIRED COMPONENTS filesystem thread
+                   OPTIONAL_COMPONENTS program_options foobar)
+
+if(Boost_FOOBAR_FOUND)
+  message(FATAL_ERROR "Optional inexistent Boost component \"foobar\" found which is unexpected")
+endif(Boost_FOOBAR_FOUND)
+
+if(NOT Boost_PROGRAM_OPTIONS_FOUND)
+  message(FATAL_ERROR "Optional Boost component \"program_options\" not found which is unexpected")
+endif(NOT Boost_PROGRAM_OPTIONS_FOUND)
 
 add_executable(test_boost_tgt main.cxx)
 target_link_libraries(test_boost_tgt

+ 18 - 0
Tests/FindBoost/TestFail/CMakeLists.txt

@@ -0,0 +1,18 @@
+cmake_minimum_required(VERSION 3.1)
+project(TestFindBoost CXX)
+include(CTest)
+
+find_package(Boost REQUIRED COMPONENTS foobar filesystem thread)
+
+add_executable(test_boost_tgt main.cxx)
+target_link_libraries(test_boost_tgt
+                      Boost::dynamic_linking
+                      Boost::disable_autolinking
+                      Boost::filesystem
+                      Boost::thread)
+add_test(NAME test_boost_tgt COMMAND test_boost_tgt)
+
+add_executable(test_boost_var main.cxx)
+target_include_directories(test_boost_var PRIVATE ${Boost_INCLUDE_DIRS})
+target_link_libraries(test_boost_var PRIVATE ${Boost_FILESYSTEM_LIBRARIES} ${Boost_SYSTEM_LIBRARIES} ${Boost_THREAD_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
+add_test(NAME test_boost_var COMMAND test_boost_var)

+ 24 - 0
Tests/FindBoost/TestFail/main.cxx

@@ -0,0 +1,24 @@
+#include <boost/filesystem.hpp>
+#include <boost/thread.hpp>
+
+namespace {
+
+boost::mutex m1;
+boost::recursive_mutex m2;
+
+void threadmain()
+{
+  boost::lock_guard<boost::mutex> lock1(m1);
+  boost::lock_guard<boost::recursive_mutex> lock2(m2);
+
+  boost::filesystem::path p(boost::filesystem::current_path());
+}
+}
+
+int main()
+{
+  boost::thread foo(threadmain);
+  foo.join();
+
+  return 0;
+}