mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 05:26:58 +08:00
@@ -8,23 +8,29 @@ This is mainly intended for internal use by the :module:`CTest` module.
|
|||||||
|
|
||||||
build_command(<variable>
|
build_command(<variable>
|
||||||
[CONFIGURATION <config>]
|
[CONFIGURATION <config>]
|
||||||
|
[PARALLEL_LEVEL <parallel>]
|
||||||
[TARGET <target>]
|
[TARGET <target>]
|
||||||
[PROJECT_NAME <projname>] # legacy, causes warning
|
[PROJECT_NAME <projname>] # legacy, causes warning
|
||||||
)
|
)
|
||||||
|
|
||||||
Sets the given ``<variable>`` to a command-line string of the form::
|
Sets the given ``<variable>`` to a command-line string of the form::
|
||||||
|
|
||||||
<cmake> --build . [--config <config>] [--target <target>...] [-- -i]
|
<cmake> --build . [--config <config>] [--parallel <parallel>] [--target <target>...] [-- -i]
|
||||||
|
|
||||||
where ``<cmake>`` is the location of the :manual:`cmake(1)` command-line
|
where ``<cmake>`` is the location of the :manual:`cmake(1)` command-line
|
||||||
tool, and ``<config>`` and ``<target>`` are the values provided to the
|
tool, and ``<config>``, ``<parallel>`` and ``<target>`` are the values
|
||||||
``CONFIGURATION`` and ``TARGET`` options, if any. The trailing ``-- -i``
|
provided to the ``CONFIGURATION``, ``PARALLEL_LEVEL`` and ``TARGET``
|
||||||
option is added for :ref:`Makefile Generators` if policy :policy:`CMP0061`
|
options, if any. The trailing ``-- -i`` option is added for
|
||||||
is not set to ``NEW``.
|
:ref:`Makefile Generators` if policy :policy:`CMP0061` is not set to
|
||||||
|
``NEW``.
|
||||||
|
|
||||||
When invoked, this ``cmake --build`` command line will launch the
|
When invoked, this ``cmake --build`` command line will launch the
|
||||||
underlying build system tool.
|
underlying build system tool.
|
||||||
|
|
||||||
|
.. versionadded:: 3.21
|
||||||
|
The ``PARALLEL_LEVEL`` argument can be used to set the ``--parallel``
|
||||||
|
flag.
|
||||||
|
|
||||||
.. code-block:: cmake
|
.. code-block:: cmake
|
||||||
|
|
||||||
build_command(<cachevariable> <makecommand>)
|
build_command(<cachevariable> <makecommand>)
|
||||||
|
@@ -0,0 +1,4 @@
|
|||||||
|
generate-cmake-build-command-parallel
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
* The :command:`build_command` command gained a ``PARALLEL_LEVEL`` option.
|
@@ -28,12 +28,14 @@ bool MainSignature(std::vector<std::string> const& args,
|
|||||||
std::string configuration;
|
std::string configuration;
|
||||||
std::string project_name;
|
std::string project_name;
|
||||||
std::string target;
|
std::string target;
|
||||||
|
std::string parallel;
|
||||||
enum Doing
|
enum Doing
|
||||||
{
|
{
|
||||||
DoingNone,
|
DoingNone,
|
||||||
DoingConfiguration,
|
DoingConfiguration,
|
||||||
DoingProjectName,
|
DoingProjectName,
|
||||||
DoingTarget
|
DoingTarget,
|
||||||
|
DoingParallel
|
||||||
};
|
};
|
||||||
Doing doing = DoingNone;
|
Doing doing = DoingNone;
|
||||||
for (unsigned int i = 1; i < args.size(); ++i) {
|
for (unsigned int i = 1; i < args.size(); ++i) {
|
||||||
@@ -43,6 +45,8 @@ bool MainSignature(std::vector<std::string> const& args,
|
|||||||
doing = DoingProjectName;
|
doing = DoingProjectName;
|
||||||
} else if (args[i] == "TARGET") {
|
} else if (args[i] == "TARGET") {
|
||||||
doing = DoingTarget;
|
doing = DoingTarget;
|
||||||
|
} else if (args[i] == "PARALLEL_LEVEL") {
|
||||||
|
doing = DoingParallel;
|
||||||
} else if (doing == DoingConfiguration) {
|
} else if (doing == DoingConfiguration) {
|
||||||
doing = DoingNone;
|
doing = DoingNone;
|
||||||
configuration = args[i];
|
configuration = args[i];
|
||||||
@@ -52,6 +56,9 @@ bool MainSignature(std::vector<std::string> const& args,
|
|||||||
} else if (doing == DoingTarget) {
|
} else if (doing == DoingTarget) {
|
||||||
doing = DoingNone;
|
doing = DoingNone;
|
||||||
target = args[i];
|
target = args[i];
|
||||||
|
} else if (doing == DoingParallel) {
|
||||||
|
doing = DoingNone;
|
||||||
|
parallel = args[i];
|
||||||
} else {
|
} else {
|
||||||
status.SetError(cmStrCat("unknown argument \"", args[i], "\""));
|
status.SetError(cmStrCat("unknown argument \"", args[i], "\""));
|
||||||
return false;
|
return false;
|
||||||
@@ -77,7 +84,7 @@ bool MainSignature(std::vector<std::string> const& args,
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string makecommand = mf.GetGlobalGenerator()->GenerateCMakeBuildCommand(
|
std::string makecommand = mf.GetGlobalGenerator()->GenerateCMakeBuildCommand(
|
||||||
target, configuration, "", "", mf.IgnoreErrorsCMP0061());
|
target, configuration, parallel, "", mf.IgnoreErrorsCMP0061());
|
||||||
|
|
||||||
mf.AddDefinition(variable, makecommand);
|
mf.AddDefinition(variable, makecommand);
|
||||||
|
|
||||||
|
5
Tests/RunCMake/build_command/ParallelLevel.cmake
Normal file
5
Tests/RunCMake/build_command/ParallelLevel.cmake
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
cmake_policy(SET CMP0061 NEW)
|
||||||
|
build_command(cmd PARALLEL_LEVEL 1)
|
||||||
|
if(NOT cmd MATCHES [[ --parallel "1"]])
|
||||||
|
message(FATAL_ERROR "Cannot find the --parallel flag")
|
||||||
|
endif()
|
@@ -14,3 +14,5 @@ if(RunCMake_GENERATOR MATCHES "Make")
|
|||||||
else()
|
else()
|
||||||
run_cmake(CMP0061-OLD-other)
|
run_cmake(CMP0061-OLD-other)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
run_cmake(ParallelLevel)
|
||||||
|
Reference in New Issue
Block a user