Browse Source

ctest: Populate CTEST_CONFIGURATION_TYPE from the -C command line when set

Julien Jomier 6 years ago
parent
commit
e6f758be6d

+ 5 - 0
Help/release/dev/ctest-configuration-type.rst

@@ -0,0 +1,5 @@
+ctest-configuration-type
+------------------------
+
+* The :variable:`CTEST_CONFIGURATION_TYPE` variable is now set from the command
+  line when :manual:`ctest(1)` is invoked with ``-C <cfg>``.

+ 3 - 0
Help/variable/CTEST_CONFIGURATION_TYPE.rst

@@ -3,3 +3,6 @@ CTEST_CONFIGURATION_TYPE
 
 Specify the CTest ``DefaultCTestConfigurationType`` setting
 in a :manual:`ctest(1)` dashboard client script.
+
+If the configuration type is set via ``-C <cfg>`` from the command line
+then this variable is populated accordingly.

+ 7 - 0
Source/CTest/cmCTestScriptHandler.cxx

@@ -340,6 +340,13 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg)
   this->SetRunCurrentScript(true);
   this->UpdateElapsedTime();
 
+  // set the CTEST_CONFIGURATION_TYPE variable to the current value of the
+  // the -C argument on the command line.
+  if (!this->CTest->GetConfigType().empty()) {
+    this->Makefile->AddDefinition("CTEST_CONFIGURATION_TYPE",
+                                  this->CTest->GetConfigType());
+  }
+
   // add the script arg if defined
   if (!script_arg.empty()) {
     this->Makefile->AddDefinition("CTEST_SCRIPT_ARG", script_arg);

+ 4 - 0
Tests/RunCMake/CTestCommandLine/CMakeLists.txt.in

@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 3.1)
+project(CTestCommandLine@CASE_NAME@ NONE)
+include(CTest)
+add_test(NAME RunCMakeVersion COMMAND "${CMAKE_COMMAND}" --version)

+ 5 - 0
Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake

@@ -1,4 +1,6 @@
 include(RunCMake)
+include(RunCTest)
+
 set(RunCMake_TEST_TIMEOUT 60)
 
 unset(ENV{CTEST_PARALLEL_LEVEL})
@@ -311,3 +313,6 @@ function(run_ShowOnly)
   run_cmake_command(show-only_json-v1 ${CMAKE_CTEST_COMMAND} --show-only=json-v1)
 endfunction()
 run_ShowOnly()
+
+# Check the configuration type variable is passed
+run_ctest(check-configuration-type)

+ 2 - 0
Tests/RunCMake/CTestCommandLine/check-configuration-type-stderr.txt

@@ -0,0 +1,2 @@
+Command line CTEST_CONFIGURATION_TYPE=Debug
+set CTEST_CONFIGURATION_TYPE=Release

+ 19 - 0
Tests/RunCMake/CTestCommandLine/test.cmake.in

@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 3.1)
+
+set(CTEST_SITE                          "test-site")
+set(CTEST_BUILD_NAME                    "test-build-name")
+set(CTEST_SOURCE_DIRECTORY              "@RunCMake_BINARY_DIR@/@CASE_NAME@")
+set(CTEST_BINARY_DIRECTORY              "@RunCMake_BINARY_DIR@/@CASE_NAME@-build")
+set(CTEST_CMAKE_GENERATOR               "@RunCMake_GENERATOR@")
+set(CTEST_CMAKE_GENERATOR_PLATFORM      "@RunCMake_GENERATOR_PLATFORM@")
+set(CTEST_CMAKE_GENERATOR_TOOLSET       "@RunCMake_GENERATOR_TOOLSET@")
+set(CTEST_NIGHTLY_START_TIME            "01:00:00 UTC")
+set(CTEST_COMMAND                       "@CMAKE_CTEST_COMMAND@")
+
+if("@CASE_NAME@" MATCHES "^check-configuration-type")
+  message("Command line CTEST_CONFIGURATION_TYPE=" ${CTEST_CONFIGURATION_TYPE})
+  set(CTEST_CONFIGURATION_TYPE "Release")
+  message("set CTEST_CONFIGURATION_TYPE=" ${CTEST_CONFIGURATION_TYPE})
+
+  ctest_start(Experimental)
+endif()