Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/microsoft/GSL.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Guriev <guriev-ns@ya.ru>2021-01-08 21:55:59 +0300
committerGitHub <noreply@github.com>2021-01-08 21:55:59 +0300
commitd9fa328f89b4089f3b700eeaddb27eb4782f99fa (patch)
treec45622bbf55e9d1d97ee1d7a19239e510addf968
parentd0052f6320553769110a1d6b260b74afb82ffb92 (diff)
Improve build script for standalone tests (#963)
* Require Git for build tests only if installed GTest is not found Cloning via Git is not the only path to obtain Google Test framework. In Linux, using a system package manager is the preferred way, and gtest can be installed through APK, APT, DNF, pacman, or many other. Now we make Git mandatory after checking GTest existence. See also: https://github.com/microsoft/GSL/pull/961#discussion_r548959056 * Support standalone tests The patch makes possible to run auto-tests against globally installed GSL, ignoring local headers. To do this, run CMake in the tests/ folder. cmake -B build -S tests -DGSL_CXX_STANDARD=14 This feature should not break existing build recipes. Co-authored-by: Nicholas Guriev <nicholas@guriev.su>
-rw-r--r--tests/CMakeLists.txt17
1 files changed, 13 insertions, 4 deletions
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}
)