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 "cmBuildNameCommand.h"
7 #include "cmsys/RegularExpression.hxx"
9 #include "cmExecutionStatus.h"
10 #include "cmMakefile.h"
11 #include "cmStateTypes.h"
12 #include "cmSystemTools.h"
15 bool cmBuildNameCommand(std::vector
<std::string
> const& args
,
16 cmExecutionStatus
& status
)
19 status
.SetError("called with incorrect number of arguments");
22 cmMakefile
& mf
= status
.GetMakefile();
23 cmValue cacheValue
= mf
.GetDefinition(args
[0]);
25 // do we need to correct the value?
26 cmsys::RegularExpression
reg("[()/]");
27 std::string cv
= *cacheValue
;
29 std::replace(cv
.begin(), cv
.end(), '/', '_');
30 std::replace(cv
.begin(), cv
.end(), '(', '_');
31 std::replace(cv
.begin(), cv
.end(), ')', '_');
32 mf
.AddCacheDefinition(args
[0], cv
, "Name of build.",
33 cmStateEnums::STRING
);
38 std::string buildname
= "WinNT";
39 if (mf
.GetDefinition("UNIX")) {
41 cmSystemTools::RunSingleCommand("uname -a", &buildname
, &buildname
);
42 if (!buildname
.empty()) {
43 std::string RegExp
= "([^ ]*) [^ ]* ([^ ]*) ";
44 cmsys::RegularExpression
reg(RegExp
);
45 if (reg
.find(buildname
)) {
46 buildname
= reg
.match(1) + "-" + reg
.match(2);
50 std::string compiler
= "${CMAKE_CXX_COMPILER}";
51 mf
.ExpandVariablesInString(compiler
);
53 buildname
+= cmSystemTools::GetFilenameName(compiler
);
54 std::replace(buildname
.begin(), buildname
.end(), '/', '_');
55 std::replace(buildname
.begin(), buildname
.end(), '(', '_');
56 std::replace(buildname
.begin(), buildname
.end(), ')', '_');
58 mf
.AddCacheDefinition(args
[0], buildname
, "Name of build.",
59 cmStateEnums::STRING
);