CMake Nightly Date Stamp
[kiteware-cmake.git] / Source / cmBuildNameCommand.cxx
blob20d6089b9fc618b0b54c6fbb540461d1f15bf222
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"
5 #include <algorithm>
7 #include "cmsys/RegularExpression.hxx"
9 #include "cmExecutionStatus.h"
10 #include "cmMakefile.h"
11 #include "cmStateTypes.h"
12 #include "cmSystemTools.h"
13 #include "cmValue.h"
15 bool cmBuildNameCommand(std::vector<std::string> const& args,
16 cmExecutionStatus& status)
18 if (args.empty()) {
19 status.SetError("called with incorrect number of arguments");
20 return false;
22 cmMakefile& mf = status.GetMakefile();
23 cmValue cacheValue = mf.GetDefinition(args[0]);
24 if (cacheValue) {
25 // do we need to correct the value?
26 cmsys::RegularExpression reg("[()/]");
27 std::string cv = *cacheValue;
28 if (reg.find(cv)) {
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);
35 return true;
38 std::string buildname = "WinNT";
39 if (mf.GetDefinition("UNIX")) {
40 buildname.clear();
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);
52 buildname += "-";
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);
60 return true;