summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Help/release/dev/load_cache-script-mode.rst5
-rw-r--r--Source/cmCommands.cxx3
-rw-r--r--Source/cmLoadCacheCommand.cxx8
-rw-r--r--Tests/RunCMake/CMakeLists.txt1
-rw-r--r--Tests/RunCMake/load_cache/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/load_cache/NewForm_Project.cmake16
-rw-r--r--Tests/RunCMake/load_cache/NewForm_Script.cmake16
-rw-r--r--Tests/RunCMake/load_cache/OldForm_Script-result.txt1
-rw-r--r--Tests/RunCMake/load_cache/OldForm_Script-stderr.txt2
-rw-r--r--Tests/RunCMake/load_cache/OldForm_Script.cmake13
-rw-r--r--Tests/RunCMake/load_cache/RunCMakeTest.cmake13
11 files changed, 79 insertions, 2 deletions
diff --git a/Help/release/dev/load_cache-script-mode.rst b/Help/release/dev/load_cache-script-mode.rst
new file mode 100644
index 0000000..d84b08a
--- /dev/null
+++ b/Help/release/dev/load_cache-script-mode.rst
@@ -0,0 +1,5 @@
+load_cache-script-mode
+----------------------
+
+* The :command:`load_cache(READ_WITH_PREFIX)` command mode is now allowed
+ when using ``cmake -P`` to :ref:`Run a Script <Script Processing Mode>`.
diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx
index ff73b27..563e0f1 100644
--- a/Source/cmCommands.cxx
+++ b/Source/cmCommands.cxx
@@ -198,6 +198,7 @@ void GetScriptingCommands(cmState* state)
#if !defined(CMAKE_BOOTSTRAP)
state->AddBuiltinCommand("cmake_host_system_information",
cmCMakeHostSystemInformationCommand);
+ state->AddBuiltinCommand("load_cache", cmLoadCacheCommand);
state->AddBuiltinCommand("remove", cmRemoveCommand);
state->AddBuiltinCommand("variable_watch", cmVariableWatchCommand);
state->AddBuiltinCommand("write_file", cmWriteFileCommand);
@@ -279,7 +280,6 @@ void GetProjectCommands(cmState* state)
state->AddBuiltinCommand("target_link_options", cmTargetLinkOptionsCommand);
state->AddBuiltinCommand("target_link_directories",
cmTargetLinkDirectoriesCommand);
- state->AddBuiltinCommand("load_cache", cmLoadCacheCommand);
state->AddBuiltinCommand("qt_wrap_cpp", cmQTWrapCPPCommand);
state->AddBuiltinCommand("qt_wrap_ui", cmQTWrapUICommand);
state->AddBuiltinCommand("remove_definitions", cmRemoveDefinitionsCommand);
@@ -339,7 +339,6 @@ void GetProjectCommandsInScriptMode(cmState* state)
CM_UNEXPECTED_PROJECT_COMMAND("install");
CM_UNEXPECTED_PROJECT_COMMAND("link_directories");
CM_UNEXPECTED_PROJECT_COMMAND("link_libraries");
- CM_UNEXPECTED_PROJECT_COMMAND("load_cache");
CM_UNEXPECTED_PROJECT_COMMAND("project");
CM_UNEXPECTED_PROJECT_COMMAND("qt_wrap_cpp");
CM_UNEXPECTED_PROJECT_COMMAND("qt_wrap_ui");
diff --git a/Source/cmLoadCacheCommand.cxx b/Source/cmLoadCacheCommand.cxx
index 1184bcb..d49e711 100644
--- a/Source/cmLoadCacheCommand.cxx
+++ b/Source/cmLoadCacheCommand.cxx
@@ -24,12 +24,20 @@ bool cmLoadCacheCommand(std::vector<std::string> const& args,
{
if (args.empty()) {
status.SetError("called with wrong number of arguments.");
+ return false;
}
if (args.size() >= 2 && args[1] == "READ_WITH_PREFIX") {
return ReadWithPrefix(args, status);
}
+ if (status.GetMakefile().GetCMakeInstance()->GetWorkingMode() ==
+ cmake::SCRIPT_MODE) {
+ status.SetError(
+ "Only load_cache(READ_WITH_PREFIX) may be used in script mode");
+ return false;
+ }
+
// Cache entries to be excluded from the import list.
// If this set is empty, all cache entries are brought in
// and they can not be overridden.
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index 1371295..51a3db5 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -279,6 +279,7 @@ add_RunCMake_test(include)
add_RunCMake_test(include_directories)
add_RunCMake_test(include_guard)
add_RunCMake_test(list)
+add_RunCMake_test(load_cache)
add_RunCMake_test(math)
add_RunCMake_test(message)
add_RunCMake_test(option)
diff --git a/Tests/RunCMake/load_cache/CMakeLists.txt b/Tests/RunCMake/load_cache/CMakeLists.txt
new file mode 100644
index 0000000..2632ffa
--- /dev/null
+++ b/Tests/RunCMake/load_cache/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.16)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/load_cache/NewForm_Project.cmake b/Tests/RunCMake/load_cache/NewForm_Project.cmake
new file mode 100644
index 0000000..13a450b
--- /dev/null
+++ b/Tests/RunCMake/load_cache/NewForm_Project.cmake
@@ -0,0 +1,16 @@
+load_cache(${CMAKE_CURRENT_BINARY_DIR}/../test_project READ_WITH_PREFIX LOAD_CACHE_TEST_
+ CACHE_STRING
+ CACHE_BOOL
+ CACHE_INTERNAL)
+
+if(NOT LOAD_CACHE_TEST_CACHE_STRING STREQUAL "cache string")
+ message(FATAL_ERROR "CACHE_STRING: was ${CACHE_STRING}, expected \"cache string\"")
+endif()
+
+if(NOT LOAD_CACHE_TEST_CACHE_BOOL)
+ message(FATAL_ERROR "CACHE_BOOL: was falsey, expected ON")
+endif()
+
+if(NOT LOAD_CACHE_TEST_CACHE_INTERNAL STREQUAL "cache internal")
+ message(FATAL_ERROR "CACHE_INTERNAL: was ${CACHE_INTENRAL}, expected \"cache internal\"")
+endif()
diff --git a/Tests/RunCMake/load_cache/NewForm_Script.cmake b/Tests/RunCMake/load_cache/NewForm_Script.cmake
new file mode 100644
index 0000000..f3cee92
--- /dev/null
+++ b/Tests/RunCMake/load_cache/NewForm_Script.cmake
@@ -0,0 +1,16 @@
+load_cache(${RunCMake_BINARY_DIR}/test_project READ_WITH_PREFIX LOAD_CACHE_TEST_
+ CACHE_STRING
+ CACHE_BOOL
+ CACHE_INTERNAL)
+
+if(NOT LOAD_CACHE_TEST_CACHE_STRING STREQUAL "cache string")
+ message(FATAL_ERROR "CACHE_STRING: was ${CACHE_STRING}, expected \"cache string\"")
+endif()
+
+if(NOT LOAD_CACHE_TEST_CACHE_BOOL)
+ message(FATAL_ERROR "CACHE_BOOL: was falsey, expected ON")
+endif()
+
+if(NOT LOAD_CACHE_TEST_CACHE_INTERNAL STREQUAL "cache internal")
+ message(FATAL_ERROR "CACHE_INTERNAL: was ${CACHE_INTENRAL}, expected \"cache internal\"")
+endif()
diff --git a/Tests/RunCMake/load_cache/OldForm_Script-result.txt b/Tests/RunCMake/load_cache/OldForm_Script-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/load_cache/OldForm_Script-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/load_cache/OldForm_Script-stderr.txt b/Tests/RunCMake/load_cache/OldForm_Script-stderr.txt
new file mode 100644
index 0000000..9ad5c80
--- /dev/null
+++ b/Tests/RunCMake/load_cache/OldForm_Script-stderr.txt
@@ -0,0 +1,2 @@
+^CMake Error at.*/Tests/RunCMake/load_cache/OldForm_Script.cmake:1 \(load_cache\):
+ load_cache Only load_cache\(READ_WITH_PREFIX\) may be used in script mode$
diff --git a/Tests/RunCMake/load_cache/OldForm_Script.cmake b/Tests/RunCMake/load_cache/OldForm_Script.cmake
new file mode 100644
index 0000000..9560f61
--- /dev/null
+++ b/Tests/RunCMake/load_cache/OldForm_Script.cmake
@@ -0,0 +1,13 @@
+load_cache(${RunCMake_BINARY_DIR}/test_project INCLUDE_INTERNALS CACHE_INTERNAL)
+
+if(NOT CACHE_STRING STREQUAL "cache string")
+ message(FATAL_ERROR "CACHE_STRING: was ${CACHE_STRING}, expected \"cache string\"")
+endif()
+
+if(NOT CACHE_BOOL)
+ message(FATAL_ERROR "CACHE_BOOL: was falsey, expected ON")
+endif()
+
+if(NOT CACHE_INTERNAL STREQUAL "cache internal")
+ message(FATAL_ERROR "CACHE_INTERNAL: was ${CACHE_INTENRAL}, expected \"cache internal\"")
+endif()
diff --git a/Tests/RunCMake/load_cache/RunCMakeTest.cmake b/Tests/RunCMake/load_cache/RunCMakeTest.cmake
new file mode 100644
index 0000000..a0d54ea
--- /dev/null
+++ b/Tests/RunCMake/load_cache/RunCMakeTest.cmake
@@ -0,0 +1,13 @@
+include(RunCMake)
+
+file(WRITE ${RunCMake_BINARY_DIR}/test_project/CMakeCache.txt [[
+CACHE_STRING:STRING=cache string
+CACHE_BOOL:BOOL=ON
+CACHE_INTERNAL:INTERNAL=cache internal
+]])
+
+run_cmake(NewForm_Project)
+run_cmake_command(NewForm_Script ${CMAKE_COMMAND} -DRunCMake_BINARY_DIR=${RunCMake_BINARY_DIR}
+ -P "${RunCMake_SOURCE_DIR}/NewForm_Script.cmake")
+run_cmake_command(OldForm_Script ${CMAKE_COMMAND} -DRunCMake_BINARY_DIR=${RunCMake_BINARY_DIR}
+ -P "${RunCMake_SOURCE_DIR}/OldForm_Script.cmake")