summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2018-10-29 11:15:10 -0400
committerBrad King <brad.king@kitware.com>2018-10-29 11:37:32 -0400
commit50572d638b3903f2c2af636dcfe9d3765fd87a7c (patch)
treec49c51130aae4e2a207995783bea9106c7fd2a44
parente4a0d8f39987a4574336892106b39781fd2d4e50 (diff)
downloadcmake-50572d638b3903f2c2af636dcfe9d3765fd87a7c.tar.gz
set_directory_properties: Restore in script mode
Since commit v3.10.0-rc1~391^2~3 (Add directory property 'LABELS' and CMAKE_DIRECTORY_LABELS variable, 2017-06-23) this command was accidentally not allowed in script mode. It was dropped because `ctest -S` mode needs to start with CMake's normal script mode and then replace the `set_directory_properties` implementation. Restore the normal `set_directory_properties` in script mode and then add special logic to replace it in ctest. Also add a test case. Fixes: #18523
-rw-r--r--Source/CTest/cmCTestTestHandler.cxx1
-rw-r--r--Source/cmCommands.cxx4
-rw-r--r--Source/cmState.cxx10
-rw-r--r--Source/cmState.h1
-rw-r--r--Tests/RunCMake/CMakeLists.txt1
-rw-r--r--Tests/RunCMake/ScriptMode/RunCMakeTest.cmake3
-rw-r--r--Tests/RunCMake/ScriptMode/set_directory_properties.cmake1
7 files changed, 19 insertions, 2 deletions
diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx
index c7ed92725d..d24410d08a 100644
--- a/Source/CTest/cmCTestTestHandler.cxx
+++ b/Source/CTest/cmCTestTestHandler.cxx
@@ -1662,6 +1662,7 @@ void cmCTestTestHandler::GetListOfTests()
cm.GetState()->AddBuiltinCommand("set_tests_properties", newCom4);
// Add handler for SET_DIRECTORY_PROPERTIES
+ cm.GetState()->RemoveBuiltinCommand("set_directory_properties");
cmCTestSetDirectoryPropertiesCommand* newCom5 =
new cmCTestSetDirectoryPropertiesCommand;
newCom5->TestHandler = this;
diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx
index 8a7d9bde78..ab0378b8d6 100644
--- a/Source/cmCommands.cxx
+++ b/Source/cmCommands.cxx
@@ -147,6 +147,8 @@ void GetScriptingCommands(cmState* state)
state->AddBuiltinCommand("separate_arguments",
new cmSeparateArgumentsCommand);
state->AddBuiltinCommand("set", new cmSetCommand);
+ state->AddBuiltinCommand("set_directory_properties",
+ new cmSetDirectoryPropertiesCommand);
state->AddBuiltinCommand("set_property", new cmSetPropertyCommand);
state->AddBuiltinCommand("site_name", new cmSiteNameCommand);
state->AddBuiltinCommand("string", new cmStringCommand);
@@ -229,8 +231,6 @@ void GetProjectCommands(cmState* state)
state->AddBuiltinCommand("install_targets", new cmInstallTargetsCommand);
state->AddBuiltinCommand("link_directories", new cmLinkDirectoriesCommand);
state->AddBuiltinCommand("project", new cmProjectCommand);
- state->AddBuiltinCommand("set_directory_properties",
- new cmSetDirectoryPropertiesCommand);
state->AddBuiltinCommand("set_source_files_properties",
new cmSetSourceFilesPropertiesCommand);
state->AddBuiltinCommand("set_target_properties",
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index 5957b5bb29..ae29160c18 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -456,6 +456,16 @@ std::vector<std::string> cmState::GetCommandNames() const
return commandNames;
}
+void cmState::RemoveBuiltinCommand(std::string const& name)
+{
+ assert(name == cmSystemTools::LowerCase(name));
+ std::map<std::string, cmCommand*>::iterator i =
+ this->BuiltinCommands.find(name);
+ assert(i != this->BuiltinCommands.end());
+ delete i->second;
+ this->BuiltinCommands.erase(i);
+}
+
void cmState::RemoveUserDefinedCommands()
{
cmDeleteAll(this->ScriptedCommands);
diff --git a/Source/cmState.h b/Source/cmState.h
index e03ad8981d..a6db7b1a72 100644
--- a/Source/cmState.h
+++ b/Source/cmState.h
@@ -128,6 +128,7 @@ public:
cmPolicies::PolicyID policy, const char* message);
void AddUnexpectedCommand(std::string const& name, const char* error);
void AddScriptedCommand(std::string const& name, cmCommand* command);
+ void RemoveBuiltinCommand(std::string const& name);
void RemoveUserDefinedCommands();
std::vector<std::string> GetCommandNames() const;
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index 29325ff0ac..f4e32ae581 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -158,6 +158,7 @@ add_RunCMake_test(ObjectLibrary)
if(UNIX AND CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG AND CMAKE_EXECUTABLE_FORMAT STREQUAL "ELF")
add_RunCMake_test(RuntimePath)
endif()
+add_RunCMake_test(ScriptMode)
add_RunCMake_test(Swift)
add_RunCMake_test(TargetObjects)
add_RunCMake_test(TargetSources)
diff --git a/Tests/RunCMake/ScriptMode/RunCMakeTest.cmake b/Tests/RunCMake/ScriptMode/RunCMakeTest.cmake
new file mode 100644
index 0000000000..4c44ffb099
--- /dev/null
+++ b/Tests/RunCMake/ScriptMode/RunCMakeTest.cmake
@@ -0,0 +1,3 @@
+include(RunCMake)
+
+run_cmake_command(set_directory_properties ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/set_directory_properties.cmake)
diff --git a/Tests/RunCMake/ScriptMode/set_directory_properties.cmake b/Tests/RunCMake/ScriptMode/set_directory_properties.cmake
new file mode 100644
index 0000000000..bf793172f6
--- /dev/null
+++ b/Tests/RunCMake/ScriptMode/set_directory_properties.cmake
@@ -0,0 +1 @@
+set_directory_properties(PROPERTIES SOME_PROPERTY FALSE)