Tests: Add FindBoost testcase for imported targets

Enable by setting CMake_TEST_FindBoost to TRUE.
This commit is contained in:
Roger Leigh 2015-12-01 22:05:35 +00:00 committed by Brad King
parent 3f9b081f6e
commit 9fd9875076
4 changed files with 58 additions and 0 deletions

View File

@ -1356,6 +1356,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
endif()
endif()
if(CMake_TEST_FindBoost)
add_subdirectory(FindBoost)
endif()
if(CMake_TEST_FindGSL)
add_subdirectory(FindGSL)
endif()

View File

@ -0,0 +1,10 @@
add_test(NAME FindBoost.Test COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
"${CMake_SOURCE_DIR}/Tests/FindBoost/Test"
"${CMake_BINARY_DIR}/Tests/FindBoost/Test"
${build_generator_args}
--build-project TestFindBoost
--build-options ${build_options}
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)

View File

@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.1)
project(TestFindBoost CXX)
include(CTest)
find_package(Boost REQUIRED COMPONENTS 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)

View File

@ -0,0 +1,26 @@
#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;
}