cmake_language: Rename command from cmake_command

Also rename the `INVOKE` signature to `CALL`.

Fixes: #20732
This commit is contained in:
Brad King
2020-05-21 13:25:13 -04:00
parent 3c5d52579b
commit 94c1e4fdb3
92 changed files with 127 additions and 128 deletions

View File

@@ -1,5 +1,5 @@
cmake_command
-------------
cmake_language
--------------
Call meta-operations on CMake commands.
@@ -8,8 +8,8 @@ Synopsis
.. parsed-literal::
cmake_command(`INVOKE`_ <command> [<args>...])
cmake_command(`EVAL`_ CODE <code>...)
cmake_language(`CALL`_ <command> [<args>...])
cmake_language(`EVAL`_ CODE <code>...)
Introduction
^^^^^^^^^^^^
@@ -17,24 +17,24 @@ Introduction
This command will call meta-operations on built-in CMake commands or
those created via the :command:`macro` or :command:`function` commands.
``cmake_command`` does not introduce a new variable or policy scope.
``cmake_language`` does not introduce a new variable or policy scope.
Invoking Commands
^^^^^^^^^^^^^^^^^
Calling Commands
^^^^^^^^^^^^^^^^
.. _INVOKE:
.. _CALL:
.. code-block:: cmake
cmake_command(INVOKE <command> [<args>...])
cmake_language(CALL <command> [<args>...])
Invokes the named ``<command>`` with the given arguments (if any).
Calls the named ``<command>`` with the given arguments (if any).
For example, the code:
.. code-block:: cmake
set(message_command "message")
cmake_command(INVOKE ${message_command} STATUS "Hello World!")
cmake_language(CALL ${message_command} STATUS "Hello World!")
is equivalent to
@@ -49,7 +49,7 @@ Evaluating Code
.. code-block:: cmake
cmake_command(EVAL CODE <code>...)
cmake_language(EVAL CODE <code>...)
Evaluates the ``<code>...`` as CMake code.
@@ -62,7 +62,7 @@ For example, the code:
set(C TRUE)
set(condition "(A AND B) OR C")
cmake_command(EVAL CODE "
cmake_language(EVAL CODE "
if (${condition})
message(STATUS TRUE)
else()

View File

@@ -44,14 +44,14 @@ can be invoked through any of
foo()
Foo()
FOO()
cmake_command(INVOKE foo)
cmake_language(CALL foo)
and so on. However, it is strongly recommended to stay with the
case chosen in the function definition. Typically functions use
all-lowercase names.
The :command:`cmake_command(INVOKE ...)` command can also be used to invoke the
function.
The :command:`cmake_language(CALL ...)` command can also be used to
invoke the function.
Arguments
^^^^^^^^^

View File

@@ -42,14 +42,14 @@ can be invoked through any of
foo()
Foo()
FOO()
cmake_command(INVOKE foo)
cmake_language(CALL foo)
and so on. However, it is strongly recommended to stay with the
case chosen in the macro definition. Typically macros use
all-lowercase names.
The :command:`cmake_command(INVOKE ...)` command can also be used to invoke the
macro.
The :command:`cmake_language(CALL ...)` command can also be used to
invoke the macro.
Arguments
^^^^^^^^^

View File

@@ -16,8 +16,8 @@ These commands are always available.
:maxdepth: 1
/command/break
/command/cmake_command
/command/cmake_host_system_information
/command/cmake_language
/command/cmake_minimum_required
/command/cmake_parse_arguments
/command/cmake_policy

View File

@@ -1,6 +0,0 @@
cmake_command
-------------
* The :command:`cmake_command()` command was added for meta-operations on
scripted or built-in commands, starting with a mode to ``INVOKE`` other
commands, and ``EVAL CODE`` to inplace evaluate a CMake script.

View File

@@ -0,0 +1,6 @@
cmake_language-command
----------------------
* The :command:`cmake_language()` command was added for meta-operations on
scripted or built-in commands, starting with a mode to ``CALL`` other
commands, and ``EVAL CODE`` to inplace evaluate a CMake script.

View File

@@ -488,10 +488,10 @@ set(SRCS
cmBuildCommand.h
cmBuildNameCommand.cxx
cmBuildNameCommand.h
cmCMakeCommand.cxx
cmCMakeCommand.h
cmCMakeHostSystemInformationCommand.cxx
cmCMakeHostSystemInformationCommand.h
cmCMakeLanguageCommand.cxx
cmCMakeLanguageCommand.h
cmCMakeMinimumRequired.cxx
cmCMakeMinimumRequired.h
cmCMakePolicyCommand.cxx

View File

@@ -1,6 +1,6 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCMakeCommand.h"
#include "cmCMakeLanguageCommand.h"
#include <algorithm>
#include <cstddef>
@@ -13,8 +13,8 @@
#include "cmRange.h"
#include "cmStringAlgorithms.h"
bool cmCMakeCommand(std::vector<cmListFileArgument> const& args,
cmExecutionStatus& status)
bool cmCMakeLanguageCommand(std::vector<cmListFileArgument> const& args,
cmExecutionStatus& status)
{
if (args.empty()) {
status.SetError("called with incorrect number of arguments");
@@ -36,7 +36,7 @@ bool cmCMakeCommand(std::vector<cmListFileArgument> const& args,
return false;
}
if (dispatchExpandedArgs[0] == "INVOKE") {
if (dispatchExpandedArgs[0] == "CALL") {
if ((args.size() == 1 && dispatchExpandedArgs.size() != 2) ||
dispatchExpandedArgs.size() > 2) {
status.SetError("called with incorrect number of arguments");
@@ -44,7 +44,7 @@ bool cmCMakeCommand(std::vector<cmListFileArgument> const& args,
}
// First argument is the name of the function to call
std::string invokeCommand;
std::string callCommand;
size_t startArg;
if (dispatchExpandedArgs.size() == 1) {
std::vector<std::string> functionExpandedArg;
@@ -57,15 +57,15 @@ bool cmCMakeCommand(std::vector<cmListFileArgument> const& args,
return false;
}
invokeCommand = functionExpandedArg[0];
callCommand = functionExpandedArg[0];
startArg = 2;
} else {
invokeCommand = dispatchExpandedArgs[1];
callCommand = dispatchExpandedArgs[1];
startArg = 1;
}
cmListFileFunction func;
func.Name = invokeCommand;
func.Name = callCommand;
func.Line = context.Line;
// The rest of the arguments are passed to the function call above

View File

@@ -1,7 +1,7 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#ifndef cmCMakeCommand_h
#define cmCMakeCommand_h
#ifndef cmCMakeLanguageCommand_h
#define cmCMakeLanguageCommand_h
#include "cmConfigure.h" // IWYU pragma: keep
@@ -14,7 +14,7 @@ struct cmListFileArgument;
* \brief Calls a scripted or build-in command
*
*/
bool cmCMakeCommand(std::vector<cmListFileArgument> const& args,
cmExecutionStatus& status);
bool cmCMakeLanguageCommand(std::vector<cmListFileArgument> const& args,
cmExecutionStatus& status);
#endif

View File

@@ -91,8 +91,8 @@
# include "cmAddLinkOptionsCommand.h"
# include "cmAuxSourceDirectoryCommand.h"
# include "cmBuildNameCommand.h"
# include "cmCMakeCommand.h"
# include "cmCMakeHostSystemInformationCommand.h"
# include "cmCMakeLanguageCommand.h"
# include "cmExportCommand.h"
# include "cmExportLibraryDependenciesCommand.h"
# include "cmFLTKWrapUICommand.h"
@@ -197,9 +197,9 @@ void GetScriptingCommands(cmState* state)
"match the opening WHILE command.");
#if !defined(CMAKE_BOOTSTRAP)
state->AddBuiltinCommand("cmake_command", cmCMakeCommand);
state->AddBuiltinCommand("cmake_host_system_information",
cmCMakeHostSystemInformationCommand);
state->AddBuiltinCommand("cmake_language", cmCMakeLanguageCommand);
state->AddBuiltinCommand("load_cache", cmLoadCacheCommand);
state->AddBuiltinCommand("remove", cmRemoveCommand);
state->AddBuiltinCommand("variable_watch", cmVariableWatchCommand);

View File

@@ -281,6 +281,7 @@ if(NOT CMake_TEST_EXTERNAL_CMAKE)
endif()
add_RunCMake_test(execute_process)
add_RunCMake_test(export)
add_RunCMake_test(cmake_language)
add_RunCMake_test(cmake_minimum_required)
add_RunCMake_test(cmake_parse_arguments)
add_RunCMake_test(continue)
@@ -676,5 +677,3 @@ add_RunCMake_test("CTestCommandExpandLists")
add_RunCMake_test(PrecompileHeaders -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID})
add_RunCMake_test("UnityBuild")
add_RunCMake_test(cmake_command)

View File

@@ -1,23 +0,0 @@
include(RunCMake)
run_cmake(cmake_command_no_parameters)
run_cmake(cmake_command_unknown_meta_operation)
run_cmake(cmake_command_invoke_double_evaluation)
run_cmake(cmake_command_invoke_expanded_command)
run_cmake(cmake_command_invoke_expanded_command_and_arguments)
run_cmake(cmake_command_invoke_expanded_command_with_explicit_argument)
run_cmake(cmake_command_invoke_expand_command_name)
run_cmake(cmake_command_invoke_expand_function_name)
run_cmake(cmake_command_invoke_message)
run_cmake(cmake_command_invoke_message_fatal_error)
run_cmake(cmake_command_invoke_no_parameters)
run_cmake(cmake_command_invoke_preserve_arguments)
run_cmake(cmake_command_invoke_unknown_function)
run_cmake(cmake_command_eval_expand_command_name)
run_cmake(cmake_command_eval_expanded_command_and_arguments)
run_cmake(cmake_command_eval_extra_parameters_between_eval_and_code)
run_cmake(cmake_command_eval_message)
run_cmake(cmake_command_eval_message_fatal_error)
run_cmake(cmake_command_eval_no_code)
run_cmake(cmake_command_eval_no_parameters)
run_cmake(cmake_command_eval_variable_outside_message)

View File

@@ -1,2 +0,0 @@
set (my_eval "EVAL")
cmake_command (${my_eval} CODE message("OK!"))

View File

@@ -1,5 +0,0 @@
CMake Error at cmake_command_eval_extra_parameters_between_eval_and_code.cmake:1 \(cmake_command\):
cmake_command called with unsupported arguments between EVAL and CODE
arguments
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@@ -1 +0,0 @@
cmake_command(EVAL BAD CODE "message(BAD CODE)")

View File

@@ -1 +0,0 @@
cmake_command(EVAL CODE message(WORKS!))

View File

@@ -1,5 +0,0 @@
CMake Error at cmake_command_eval_message_fatal_error.cmake:1:EVAL:2 \(message\):
error!
Call Stack \(most recent call first\):
cmake_command_eval_message_fatal_error.cmake:1 \(cmake_command\)
CMakeLists.txt:3 \(include\)

View File

@@ -1,2 +0,0 @@
CMake Error at cmake_command_eval_no_code.cmake:1 \(cmake_command\):
cmake_command called without CODE argument

View File

@@ -1 +0,0 @@
cmake_command(EVAL message "too many parameters")

View File

@@ -1,2 +0,0 @@
CMake Error at cmake_command_eval_no_parameters.cmake:1 \(cmake_command\):
cmake_command called with incorrect number of arguments

View File

@@ -1 +0,0 @@
cmake_command(EVAL)

View File

@@ -1,2 +0,0 @@
cmake_command(EVAL CODE "set(phrase \"WORKS!\")")
message(${phrase})

View File

@@ -1,2 +0,0 @@
set(var [[${foo}]])
cmake_command(INVOKE cmake_command INVOKE message "var='${var}'")

View File

@@ -1,2 +0,0 @@
set (my_invoke "INVOKE")
cmake_command (${my_invoke} message "OK!")

View File

@@ -1,4 +0,0 @@
CMake Error at cmake_command_invoke_expanded_command_and_arguments.cmake:2 \(cmake_command\):
cmake_command called with incorrect number of arguments
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@@ -1,2 +0,0 @@
set(invoke_message INVOKE message a b)
cmake_command(${invoke_message})

View File

@@ -1,2 +0,0 @@
set (cmd INVOKE message)
cmake_command (${cmd} "OK!")

View File

@@ -1 +0,0 @@
cmake_command(INVOKE message WORKS!)

View File

@@ -1,5 +0,0 @@
CMake Error at cmake_command_invoke_message_fatal_error.cmake:1 \(message\):
error!
Call Stack \(most recent call first\):
cmake_command_invoke_message_fatal_error.cmake:1 \(cmake_command\)
CMakeLists.txt:3 \(include\)

View File

@@ -1 +0,0 @@
cmake_command(INVOKE message FATAL_ERROR error!)

View File

@@ -1,2 +0,0 @@
CMake Error at cmake_command_invoke_no_parameters.cmake:1 \(cmake_command\):
cmake_command called with incorrect number of arguments

View File

@@ -1 +0,0 @@
cmake_command(INVOKE)

View File

@@ -1,2 +0,0 @@
CMake Error at cmake_command_invoke_unknown_function.cmake:1 \(unknown\):
Unknown CMake command "unknown".

View File

@@ -1 +0,0 @@
cmake_command(INVOKE unknown)

View File

@@ -1,2 +0,0 @@
CMake Error at cmake_command_no_parameters.cmake:1 \(cmake_command\):
cmake_command called with incorrect number of arguments

View File

@@ -1 +0,0 @@
cmake_command(INVOKE)

View File

@@ -1,2 +0,0 @@
CMake Error at cmake_command_unknown_meta_operation.cmake:1 \(cmake_command\):
cmake_command called with unknown meta-operation

View File

@@ -1 +0,0 @@
cmake_command(UNKNOWN)

View File

@@ -0,0 +1,23 @@
include(RunCMake)
run_cmake(no_parameters)
run_cmake(unknown_meta_operation)
run_cmake(call_double_evaluation)
run_cmake(call_expanded_command)
run_cmake(call_expanded_command_and_arguments)
run_cmake(call_expanded_command_with_explicit_argument)
run_cmake(call_expand_command_name)
run_cmake(call_expand_function_name)
run_cmake(call_message)
run_cmake(call_message_fatal_error)
run_cmake(call_no_parameters)
run_cmake(call_preserve_arguments)
run_cmake(call_unknown_function)
run_cmake(eval_expand_command_name)
run_cmake(eval_expanded_command_and_arguments)
run_cmake(eval_extra_parameters_between_eval_and_code)
run_cmake(eval_message)
run_cmake(eval_message_fatal_error)
run_cmake(eval_no_code)
run_cmake(eval_no_parameters)
run_cmake(eval_variable_outside_message)

View File

@@ -0,0 +1,2 @@
set(var [[${foo}]])
cmake_language(CALL cmake_language CALL message "var='${var}'")

View File

@@ -0,0 +1,2 @@
set (my_call "CALL")
cmake_language (${my_call} message "OK!")

View File

@@ -8,4 +8,4 @@ endfunction()
set(function_version 1)
cmake_command(INVOKE some_function_${function_version})
cmake_language(CALL some_function_${function_version})

View File

@@ -2,5 +2,5 @@ function (itsok)
message(OK!)
endfunction()
set (cmd INVOKE itsok)
cmake_command (${cmd})
set (cmd CALL itsok)
cmake_language (${cmd})

View File

@@ -0,0 +1,4 @@
CMake Error at call_expanded_command_and_arguments.cmake:2 \(cmake_language\):
cmake_language called with incorrect number of arguments
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@@ -0,0 +1,2 @@
set(call_message CALL message a b)
cmake_language(${call_message})

View File

@@ -0,0 +1,2 @@
set (cmd CALL message)
cmake_language (${cmd} "OK!")

View File

@@ -0,0 +1 @@
cmake_language(CALL message WORKS!)

View File

@@ -0,0 +1,5 @@
CMake Error at call_message_fatal_error.cmake:1 \(message\):
error!
Call Stack \(most recent call first\):
call_message_fatal_error.cmake:1 \(cmake_language\)
CMakeLists.txt:3 \(include\)

View File

@@ -0,0 +1 @@
cmake_language(CALL message FATAL_ERROR error!)

View File

@@ -0,0 +1,2 @@
CMake Error at call_no_parameters.cmake:1 \(cmake_language\):
cmake_language called with incorrect number of arguments

View File

@@ -0,0 +1 @@
cmake_language(CALL)

View File

@@ -1,6 +1,6 @@
foo\(...\)
\[a;b\]
\[c;d\]
cmake_command\(INVOKE foo ...\)
cmake_language\(CALL foo ...\)
\[a;b\]
\[c;d\]

View File

@@ -8,5 +8,5 @@ endfunction()
message("foo(...)")
foo("a;b" "c;d")
message("cmake_command(INVOKE foo ...)")
cmake_command(INVOKE foo "a;b" "c;d")
message("cmake_language(CALL foo ...)")
cmake_language(CALL foo "a;b" "c;d")

View File

@@ -0,0 +1,2 @@
CMake Error at call_unknown_function.cmake:1 \(unknown\):
Unknown CMake command "unknown".

View File

@@ -0,0 +1 @@
cmake_language(CALL unknown)

View File

@@ -0,0 +1,2 @@
set (my_eval "EVAL")
cmake_language (${my_eval} CODE message("OK!"))

View File

@@ -1,2 +1,2 @@
set(cmd EVAL CODE [[message("OK!")]])
cmake_command(${cmd})
cmake_language(${cmd})

View File

@@ -0,0 +1,5 @@
CMake Error at eval_extra_parameters_between_eval_and_code.cmake:1 \(cmake_language\):
cmake_language called with unsupported arguments between EVAL and CODE
arguments
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@@ -0,0 +1 @@
cmake_language(EVAL BAD CODE "message(BAD CODE)")

View File

@@ -0,0 +1 @@
cmake_language(EVAL CODE message(WORKS!))

View File

@@ -0,0 +1,5 @@
CMake Error at eval_message_fatal_error.cmake:1:EVAL:2 \(message\):
error!
Call Stack \(most recent call first\):
eval_message_fatal_error.cmake:1 \(cmake_language\)
CMakeLists.txt:3 \(include\)

View File

@@ -1,4 +1,4 @@
cmake_command(EVAL CODE
cmake_language(EVAL CODE
"
message(FATAL_ERROR error!)
"

View File

@@ -0,0 +1,2 @@
CMake Error at eval_no_code.cmake:1 \(cmake_language\):
cmake_language called without CODE argument

View File

@@ -0,0 +1 @@
cmake_language(EVAL message "too many parameters")

View File

@@ -0,0 +1,2 @@
CMake Error at eval_no_parameters.cmake:1 \(cmake_language\):
cmake_language called with incorrect number of arguments

View File

@@ -0,0 +1 @@
cmake_language(EVAL)

View File

@@ -0,0 +1,2 @@
cmake_language(EVAL CODE "set(phrase \"WORKS!\")")
message(${phrase})

View File

@@ -0,0 +1,2 @@
CMake Error at no_parameters.cmake:1 \(cmake_language\):
cmake_language called with incorrect number of arguments

View File

@@ -0,0 +1 @@
cmake_language(CALL)

View File

@@ -0,0 +1,2 @@
CMake Error at unknown_meta_operation.cmake:1 \(cmake_language\):
cmake_language called with unknown meta-operation

View File

@@ -0,0 +1 @@
cmake_language(UNKNOWN)