Commit ae7d99fb authored by Brad King's avatar Brad King Committed by Kitware Robot

Merge topic 'load_cache_in_script'

5e9ecaae load_cache: Allow READ_WITH_PREFIX mode in cmake scripts
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !4042
parents d9cf0ec4 5e9ecaae
Pipeline #152085 passed with stage
in 0 seconds
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>`.
......@@ -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");
......
......@@ -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.
......
......@@ -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)
......
cmake_minimum_required(VERSION 3.16)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)
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()
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()
^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$
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()
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")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment