Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Tests/CTestConfig/CMakeLists.txt
3148 views
1
cmake_minimum_required(VERSION 3.10)
2
project(CTestConfig)
3
4
include(CTest)
5
6
7
# We expect this configure to occur through a 'ctest -D Experimental' or a
8
# 'ctest -S script.cmake' call.
9
#
10
# In either case, we expect CMAKE_BUILD_TYPE to be defined for single-configuration
11
# build trees and not defined for multi-configuration build trees. The value of
12
# CMAKE_CONFIGURATION_TYPES should not be relied upon to determine whether we
13
# are using a multi-config generator or not, the GENERATOR_IS_MULTI_CONFIG
14
# global property is the canonical way to do that as of CMake 3.9.
15
#
16
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
17
if(_isMultiConfig)
18
if(NOT DEFINED CMAKE_CONFIGURATION_TYPES OR CMAKE_CONFIGURATION_TYPES STREQUAL "")
19
message(FATAL_ERROR "CMAKE_CONFIGURATION_TYPES is not defined or is empty "
20
"(but must be defined and non-empty for a multi-configuration generator)")
21
endif()
22
if(DEFINED CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE STREQUAL "")
23
message(FATAL_ERROR "CMAKE_BUILD_TYPE='${CMAKE_BUILD_TYPE}' is defined and non-empty "
24
"(but should not be for a multi-configuration generator)")
25
endif()
26
set(_configs ${CMAKE_CONFIGURATION_TYPES})
27
else()
28
# Populating CMAKE_CONFIGURATION_TYPES even for single config generators is
29
# common enough for user projects that we don't want to consider it an error.
30
# We just need CMAKE_BUILD_TYPE to be set and ignore CMAKE_CONFIGURATION_TYPES.
31
if(NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
32
message(FATAL_ERROR "CMAKE_BUILD_TYPE is not defined or is empty "
33
"(but should be defined and non-empty for a single-configuration generator)")
34
endif()
35
add_definitions(-DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}")
36
set(_configs ${CMAKE_BUILD_TYPE})
37
endif()
38
39
add_executable(ctc CTestConfig.cxx)
40
41
42
foreach(cfg ${_configs})
43
add_test(NAME ctc-${cfg} CONFIGURATIONS ${cfg} COMMAND ctc --config $<CONFIGURATION>)
44
45
if(_isMultiConfig)
46
set_property(TEST ctc-${cfg}
47
PROPERTY PASS_REGULAR_EXPRESSION "CMAKE_INTDIR is ${cfg}")
48
set_property(TEST ctc-${cfg}
49
PROPERTY FAIL_REGULAR_EXPRESSION "CMAKE_BUILD_TYPE is")
50
else()
51
set_property(TEST ctc-${cfg}
52
PROPERTY PASS_REGULAR_EXPRESSION "CMAKE_BUILD_TYPE is ${cfg}")
53
set_property(TEST ctc-${cfg}
54
PROPERTY FAIL_REGULAR_EXPRESSION "CMAKE_INTDIR is")
55
endif()
56
endforeach()
57
58