diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1c7b03e..368ce75 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,12 +1,11 @@ cmake_minimum_required(VERSION 3.0.2) project(GSLTests CXX) +enable_testing() # again, for support standalone testing include(FindPkgConfig) include(ExternalProject) -find_package(Git REQUIRED QUIET) - # will make visual studio generated project group files set_property(GLOBAL PROPERTY USE_FOLDERS ON) @@ -16,6 +15,9 @@ endif() pkg_search_module(GTestMain gtest_main) if (NOT GTestMain_FOUND) + # No pre-installed GTest is available, try to download it using Git. + find_package(Git REQUIRED QUIET) + configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) execute_process( COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . @@ -45,6 +47,13 @@ if (NOT GTestMain_FOUND) ) endif() +if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + # CMake has been started independently in this directory with tests. Do + # import the globally installed Guidelines Support Library and test it + # instead of the current version from the include/ folder. + find_package(Microsoft.GSL REQUIRED) +endif() + if (MSVC AND (GSL_CXX_STANDARD EQUAL 17)) set(GSL_CPLUSPLUS_OPT -Zc:__cplusplus -permissive-) endif() @@ -160,7 +169,7 @@ set_property(TARGET PROPERTY FOLDER "GSL_tests") function(add_gsl_test name) add_executable(${name} ${name}.cpp) target_link_libraries(${name} - GSL + Microsoft.GSL::GSL gsl_tests_config ${GTestMain_LIBRARIES} ) @@ -262,7 +271,7 @@ endif(MSVC) function(add_gsl_test_noexcept name) add_executable(${name} ${name}.cpp) target_link_libraries(${name} - GSL + Microsoft.GSL::GSL gsl_tests_config_noexcept ${GTestMain_LIBRARIES} )