resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmBuildNameCommand.cxx
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"
4
5 #include <algorithm>
6
7 #include "cmsys/RegularExpression.hxx"
8
9 #include "cmExecutionStatus.h"
10 #include "cmMakefile.h"
11 #include "cmStateTypes.h"
12 #include "cmSystemTools.h"
13 #include "cmValue.h"
14
15 bool cmBuildNameCommand(std::vector<std::string> const& args,
16                         cmExecutionStatus& status)
17 {
18   if (args.empty()) {
19     status.SetError("called with incorrect number of arguments");
20     return false;
21   }
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);
34     }
35     return true;
36   }
37
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);
47       }
48     }
49   }
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(), ')', '_');
57
58   mf.AddCacheDefinition(args[0], buildname, "Name of build.",
59                         cmStateEnums::STRING);
60   return true;
61 }