1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmBuildCommand.h"
5 #include "cmExecutionStatus.h"
6 #include "cmGlobalGenerator.h"
7 #include "cmMakefile.h"
8 #include "cmMessageType.h"
9 #include "cmStateTypes.h"
10 #include "cmStringAlgorithms.h"
11 #include "cmSystemTools.h"
16 bool MainSignature(std::vector<std::string> const& args,
17 cmExecutionStatus& status)
20 status.SetError("requires at least one argument naming a CMake variable");
24 // The cmake variable in which to store the result.
25 std::string const& variable = args[0];
27 // Parse remaining arguments.
28 std::string configuration;
29 std::string project_name;
40 Doing doing = DoingNone;
41 for (unsigned int i = 1; i < args.size(); ++i) {
42 if (args[i] == "CONFIGURATION") {
43 doing = DoingConfiguration;
44 } else if (args[i] == "PROJECT_NAME") {
45 doing = DoingProjectName;
46 } else if (args[i] == "TARGET") {
48 } else if (args[i] == "PARALLEL_LEVEL") {
49 doing = DoingParallel;
50 } else if (doing == DoingConfiguration) {
52 configuration = args[i];
53 } else if (doing == DoingProjectName) {
55 project_name = args[i];
56 } else if (doing == DoingTarget) {
59 } else if (doing == DoingParallel) {
63 status.SetError(cmStrCat("unknown argument \"", args[i], "\""));
68 // If null/empty CONFIGURATION argument, cmake --build uses 'Debug'
69 // in the currently implemented multi-configuration global generators...
70 // so we put this code here to end up with the same default configuration
71 // as the original 2-arg build_command signature:
73 if (configuration.empty()) {
74 cmSystemTools::GetEnv("CMAKE_CONFIG_TYPE", configuration);
76 if (configuration.empty()) {
77 configuration = "Release";
80 cmMakefile& mf = status.GetMakefile();
81 if (!project_name.empty()) {
82 mf.IssueMessage(MessageType::AUTHOR_WARNING,
83 "Ignoring PROJECT_NAME option because it has no effect.");
86 std::string makecommand = mf.GetGlobalGenerator()->GenerateCMakeBuildCommand(
87 target, configuration, parallel, "", mf.IgnoreErrorsCMP0061());
89 mf.AddDefinition(variable, makecommand);
94 bool TwoArgsSignature(std::vector<std::string> const& args,
95 cmExecutionStatus& status)
97 if (args.size() < 2) {
98 status.SetError("called with less than two arguments");
102 cmMakefile& mf = status.GetMakefile();
104 std::string const& define = args[0];
105 cmValue cacheValue = mf.GetDefinition(define);
107 std::string configType;
108 if (!cmSystemTools::GetEnv("CMAKE_CONFIG_TYPE", configType) ||
109 configType.empty()) {
110 configType = "Release";
113 std::string makecommand = mf.GetGlobalGenerator()->GenerateCMakeBuildCommand(
114 "", configType, "", "", mf.IgnoreErrorsCMP0061());
119 mf.AddCacheDefinition(define, makecommand,
120 "Command used to build entire project "
121 "from the command line.",
122 cmStateEnums::STRING);
128 bool cmBuildCommand(std::vector<std::string> const& args,
129 cmExecutionStatus& status)
131 // Support the legacy signature of the command:
132 if (args.size() == 2) {
133 return TwoArgsSignature(args, status);
136 return MainSignature(args, status);