diff options
author | Eicke Herbertz <wolletd@posteo.de> | 2019-05-04 21:54:58 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-05-22 11:40:51 (GMT) |
commit | d0f0ba0f7a39e70fbed197e717292b74150cf84f (patch) | |
tree | c257620240b55fb1e13ea5c378fb3e84037165b4 | |
parent | a48ce8f4bf0677e9e8d054892836e8a980ffa435 (diff) | |
download | CMake-d0f0ba0f7a39e70fbed197e717292b74150cf84f.zip CMake-d0f0ba0f7a39e70fbed197e717292b74150cf84f.tar.gz CMake-d0f0ba0f7a39e70fbed197e717292b74150cf84f.tar.bz2 |
Tests: Add environment generator tests
24 files changed, 128 insertions, 0 deletions
diff --git a/Tests/EnforceConfig.cmake.in b/Tests/EnforceConfig.cmake.in index 8c0817c..f84d180 100644 --- a/Tests/EnforceConfig.cmake.in +++ b/Tests/EnforceConfig.cmake.in @@ -23,4 +23,10 @@ if(NOT CTEST_CONFIGURATION_TYPE) message("Guessing configuration ${CTEST_CONFIGURATION_TYPE}") endif() +# Isolate tests from user configuration in the environment. +unset(ENV{CMAKE_GENERATOR}) +unset(ENV{CMAKE_GENERATOR_INSTANCE}) +unset(ENV{CMAKE_GENERATOR_PLATFORM}) +unset(ENV{CMAKE_GENERATOR_TOOLSET}) + @TEST_HOME_ENV_CODE@ diff --git a/Tests/RunCMake/CommandLine/EnvGenerator/CMakeLists.txt b/Tests/RunCMake/CommandLine/EnvGenerator/CMakeLists.txt new file mode 100644 index 0000000..2b8c65c --- /dev/null +++ b/Tests/RunCMake/CommandLine/EnvGenerator/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.14) +project(EnvGenerator C) +if(CMAKE_GENERATOR MATCHES "Visual Studio") + message(STATUS "CMAKE_VS_PLATFORM_NAME='${CMAKE_VS_PLATFORM_NAME}'") +endif() +add_custom_command( + OUTPUT output.txt + COMMAND ${CMAKE_COMMAND} -E echo CustomCommand > output.txt + ) +add_custom_target(CustomTarget ALL DEPENDS output.txt) diff --git a/Tests/RunCMake/CommandLine/Envgen-A-platform-result.txt b/Tests/RunCMake/CommandLine/Envgen-A-platform-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/Envgen-A-platform-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/Envgen-A-platform-stderr-vs9.txt b/Tests/RunCMake/CommandLine/Envgen-A-platform-stderr-vs9.txt new file mode 100644 index 0000000..4eae6aa --- /dev/null +++ b/Tests/RunCMake/CommandLine/Envgen-A-platform-stderr-vs9.txt @@ -0,0 +1,2 @@ +^CMake Error at CMakeLists.+ + No CMAKE_C_COMPILER could be found. diff --git a/Tests/RunCMake/CommandLine/Envgen-A-platform-stderr.txt b/Tests/RunCMake/CommandLine/Envgen-A-platform-stderr.txt new file mode 100644 index 0000000..09c2d2b --- /dev/null +++ b/Tests/RunCMake/CommandLine/Envgen-A-platform-stderr.txt @@ -0,0 +1,2 @@ +^CMake Error at CMakeLists.+ +.+Platform='fromcli'.+ diff --git a/Tests/RunCMake/CommandLine/Envgen-G-implicit-platform-stdout.txt b/Tests/RunCMake/CommandLine/Envgen-G-implicit-platform-stdout.txt new file mode 100644 index 0000000..4dd6be1 --- /dev/null +++ b/Tests/RunCMake/CommandLine/Envgen-G-implicit-platform-stdout.txt @@ -0,0 +1 @@ +-- CMAKE_VS_PLATFORM_NAME='(x64|Win32)' diff --git a/Tests/RunCMake/CommandLine/Envgen-T-toolset-result.txt b/Tests/RunCMake/CommandLine/Envgen-T-toolset-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/Envgen-T-toolset-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/Envgen-T-toolset-stderr.txt b/Tests/RunCMake/CommandLine/Envgen-T-toolset-stderr.txt new file mode 100644 index 0000000..b432c19 --- /dev/null +++ b/Tests/RunCMake/CommandLine/Envgen-T-toolset-stderr.txt @@ -0,0 +1,2 @@ +^CMake Error at CMakeLists.+ +.+(Platform Toolset = 'fromcli'|Specified platform toolset \(fromcli\) is not installed or invalid).+ diff --git a/Tests/RunCMake/CommandLine/Envgen-bad-result.txt b/Tests/RunCMake/CommandLine/Envgen-bad-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/Envgen-bad-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/Envgen-bad-stderr.txt b/Tests/RunCMake/CommandLine/Envgen-bad-stderr.txt new file mode 100644 index 0000000..4a1215e --- /dev/null +++ b/Tests/RunCMake/CommandLine/Envgen-bad-stderr.txt @@ -0,0 +1,5 @@ +^CMake Error: No generator specified for -G +CMake Error: CMAKE_GENERATOR was set but the specified generator doesn't exist. Using CMake default. + +Generators.* +\* (Unix Makefiles|Visual Studio).* diff --git a/Tests/RunCMake/CommandLine/Envgen-instance-invalid-result.txt b/Tests/RunCMake/CommandLine/Envgen-instance-invalid-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/Envgen-instance-invalid-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/Envgen-instance-invalid-stderr.txt b/Tests/RunCMake/CommandLine/Envgen-instance-invalid-stderr.txt new file mode 100644 index 0000000..d53daa5 --- /dev/null +++ b/Tests/RunCMake/CommandLine/Envgen-instance-invalid-stderr.txt @@ -0,0 +1,2 @@ +^CMake Error at CMakeLists.+ + could not find specified instance of Visual Studio.+ diff --git a/Tests/RunCMake/CommandLine/Envgen-ninja-result.txt b/Tests/RunCMake/CommandLine/Envgen-ninja-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/Envgen-ninja-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/Envgen-ninja-stderr.txt b/Tests/RunCMake/CommandLine/Envgen-ninja-stderr.txt new file mode 100644 index 0000000..0d455db --- /dev/null +++ b/Tests/RunCMake/CommandLine/Envgen-ninja-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error: No generator specified for -G + +Generators.* +\* Ninja.* diff --git a/Tests/RunCMake/CommandLine/Envgen-platform-invalid-result.txt b/Tests/RunCMake/CommandLine/Envgen-platform-invalid-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/Envgen-platform-invalid-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/Envgen-platform-invalid-stderr-vs9.txt b/Tests/RunCMake/CommandLine/Envgen-platform-invalid-stderr-vs9.txt new file mode 100644 index 0000000..4eae6aa --- /dev/null +++ b/Tests/RunCMake/CommandLine/Envgen-platform-invalid-stderr-vs9.txt @@ -0,0 +1,2 @@ +^CMake Error at CMakeLists.+ + No CMAKE_C_COMPILER could be found. diff --git a/Tests/RunCMake/CommandLine/Envgen-platform-invalid-stderr.txt b/Tests/RunCMake/CommandLine/Envgen-platform-invalid-stderr.txt new file mode 100644 index 0000000..76a8f1c --- /dev/null +++ b/Tests/RunCMake/CommandLine/Envgen-platform-invalid-stderr.txt @@ -0,0 +1,2 @@ +^CMake Error at CMakeLists.+ +.+Platform='invalid'.+ diff --git a/Tests/RunCMake/CommandLine/Envgen-toolset-invalid-result.txt b/Tests/RunCMake/CommandLine/Envgen-toolset-invalid-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/Envgen-toolset-invalid-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/Envgen-toolset-invalid-stderr.txt b/Tests/RunCMake/CommandLine/Envgen-toolset-invalid-stderr.txt new file mode 100644 index 0000000..51fce60 --- /dev/null +++ b/Tests/RunCMake/CommandLine/Envgen-toolset-invalid-stderr.txt @@ -0,0 +1,2 @@ +^CMake Error at CMakeLists.+ +.+(Platform Toolset = 'invalid'|Specified platform toolset \(invalid\) is not installed or invalid).+ diff --git a/Tests/RunCMake/CommandLine/Envgen-unset-result.txt b/Tests/RunCMake/CommandLine/Envgen-unset-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/Envgen-unset-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/Envgen-unset-stderr.txt b/Tests/RunCMake/CommandLine/Envgen-unset-stderr.txt new file mode 100644 index 0000000..ec6ec92 --- /dev/null +++ b/Tests/RunCMake/CommandLine/Envgen-unset-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error: No generator specified for -G + +Generators.* +\* (Unix Makefiles|Visual Studio).* diff --git a/Tests/RunCMake/CommandLine/Envgen-warnings-result.txt b/Tests/RunCMake/CommandLine/Envgen-warnings-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/Envgen-warnings-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/Envgen-warnings-stderr.txt b/Tests/RunCMake/CommandLine/Envgen-warnings-stderr.txt new file mode 100644 index 0000000..47f9c9e --- /dev/null +++ b/Tests/RunCMake/CommandLine/Envgen-warnings-stderr.txt @@ -0,0 +1,7 @@ +^Warning: Environment variable CMAKE_GENERATOR_INSTANCE will be ignored, because CMAKE_GENERATOR is not set. +Warning: Environment variable CMAKE_GENERATOR_PLATFORM will be ignored, because CMAKE_GENERATOR is not set. +Warning: Environment variable CMAKE_GENERATOR_TOOLSET will be ignored, because CMAKE_GENERATOR is not set. +CMake Error: No generator specified for -G + +Generators.* +\* (Unix Makefiles|Visual Studio).* diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index ea749ea..dd1180b 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -164,6 +164,74 @@ function(run_BuildDir) endfunction() run_BuildDir() +function(run_EnvironmentGenerator) + set(source_dir ${RunCMake_SOURCE_DIR}/EnvGenerator) + + set(ENV{CMAKE_GENERATOR_INSTANCE} "instance") + set(ENV{CMAKE_GENERATOR_PLATFORM} "platform") + set(ENV{CMAKE_GENERATOR_TOOLSET} "toolset") + run_cmake_command(Envgen-warnings ${CMAKE_COMMAND} -G) + unset(ENV{CMAKE_GENERATOR_INSTANCE}) + unset(ENV{CMAKE_GENERATOR_PLATFORM}) + unset(ENV{CMAKE_GENERATOR_TOOLSET}) + + # Test CMAKE_GENERATOR without actual configuring + run_cmake_command(Envgen-unset ${CMAKE_COMMAND} -G) + set(ENV{CMAKE_GENERATOR} "Ninja") + run_cmake_command(Envgen-ninja ${CMAKE_COMMAND} -G) + set(ENV{CMAKE_GENERATOR} "NoSuchGenerator") + run_cmake_command(Envgen-bad ${CMAKE_COMMAND} -G) + unset(ENV{CMAKE_GENERATOR}) + + if(RunCMake_GENERATOR MATCHES "Visual Studio.*") + set(ENV{CMAKE_GENERATOR} "${RunCMake_GENERATOR}") + run_cmake_command(Envgen ${CMAKE_COMMAND} ${source_dir}) + # Toolset is available since VS 2010. + if(RunCMake_GENERATOR MATCHES "Visual Studio [1-9][0-9]") + set(ENV{CMAKE_GENERATOR_TOOLSET} "invalid") + # Envvar shouldn't affect existing build tree + run_cmake_command(Envgen-toolset-existing ${CMAKE_COMMAND} -E chdir .. + ${CMAKE_COMMAND} --build Envgen-build) + run_cmake_command(Envgen-toolset-invalid ${CMAKE_COMMAND} ${source_dir}) + # Command line -G implies -T"" + run_cmake_command(Envgen-G-implicit-toolset ${CMAKE_COMMAND} -G "${RunCMake_GENERATOR}" ${source_dir}) + run_cmake_command(Envgen-T-toolset ${CMAKE_COMMAND} -T "fromcli" ${source_dir}) + unset(ENV{CMAKE_GENERATOR_TOOLSET}) + endif() + # Platform can be set only if not in generator name. + if(RunCMake_GENERATOR MATCHES "^Visual Studio [0-9]+ [0-9]+$") + set(ENV{CMAKE_GENERATOR_PLATFORM} "invalid") + # Envvar shouldn't affect existing build tree + run_cmake_command(Envgen-platform-existing ${CMAKE_COMMAND} -E chdir .. + ${CMAKE_COMMAND} --build Envgen-build) + if(RunCMake_GENERATOR MATCHES "^Visual Studio 9 ") + set(RunCMake-stderr-file "Envgen-platform-invalid-stderr-vs9.txt") + endif() + run_cmake_command(Envgen-platform-invalid ${CMAKE_COMMAND} ${source_dir}) + unset(RunCMake-stderr-file) + # Command line -G implies -A"" + run_cmake_command(Envgen-G-implicit-platform ${CMAKE_COMMAND} -G "${RunCMake_GENERATOR}" ${source_dir}) + if(RunCMake_GENERATOR MATCHES "^Visual Studio 9 ") + set(RunCMake-stderr-file "Envgen-A-platform-stderr-vs9.txt") + endif() + run_cmake_command(Envgen-A-platform ${CMAKE_COMMAND} -A "fromcli" ${source_dir}) + unset(RunCMake-stderr-file) + unset(ENV{CMAKE_GENERATOR_PLATFORM}) + endif() + # Instance is available since VS 2017. + if(RunCMake_GENERATOR MATCHES "Visual Studio (15|16).*") + set(ENV{CMAKE_GENERATOR_INSTANCE} "invalid") + # Envvar shouldn't affect existing build tree + run_cmake_command(Envgen-instance-existing ${CMAKE_COMMAND} -E chdir .. + ${CMAKE_COMMAND} --build Envgen-build) + run_cmake_command(Envgen-instance-invalid ${CMAKE_COMMAND} ${source_dir}) + unset(ENV{CMAKE_GENERATOR_INSTANCE}) + endif() + unset(ENV{CMAKE_GENERATOR}) + endif() +endfunction() +run_EnvironmentGenerator() + if(RunCMake_GENERATOR STREQUAL "Ninja") # Use a single build tree for a few tests without cleaning. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Build-build) |