CMake Nightly Date Stamp
[kiteware-cmake.git] / Source / cmSubdirCommand.cxx
blob47082f1fde5e34d37fe37fd13561fff1fb7ca407
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 "cmSubdirCommand.h"
5 #include "cmExecutionStatus.h"
6 #include "cmMakefile.h"
7 #include "cmStringAlgorithms.h"
8 #include "cmSystemTools.h"
10 bool cmSubdirCommand(std::vector<std::string> const& args,
11 cmExecutionStatus& status)
13 if (args.empty()) {
14 status.SetError("called with incorrect number of arguments");
15 return false;
17 bool res = true;
18 bool excludeFromAll = false;
19 cmMakefile& mf = status.GetMakefile();
21 for (std::string const& i : args) {
22 if (i == "EXCLUDE_FROM_ALL") {
23 excludeFromAll = true;
24 continue;
26 if (i == "PREORDER") {
27 // Ignored
28 continue;
31 // if they specified a relative path then compute the full
32 std::string srcPath = mf.GetCurrentSourceDirectory() + "/" + i;
33 if (cmSystemTools::FileIsDirectory(srcPath)) {
34 std::string binPath = mf.GetCurrentBinaryDirectory() + "/" + i;
35 mf.AddSubDirectory(srcPath, binPath, excludeFromAll, false, false);
37 // otherwise it is a full path
38 else if (cmSystemTools::FileIsDirectory(i)) {
39 // we must compute the binPath from the srcPath, we just take the last
40 // element from the source path and use that
41 std::string binPath = mf.GetCurrentBinaryDirectory() + "/" +
42 cmSystemTools::GetFilenameName(i);
43 mf.AddSubDirectory(i, binPath, excludeFromAll, false, false);
44 } else {
45 status.SetError(cmStrCat("Incorrect SUBDIRS command. Directory: ", i,
46 " does not exist."));
47 res = false;
50 return res;