cmake/Source/cmSubdirCommand.cxx

52 lines
1.7 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmSubdirCommand.h"
2020-02-01 23:06:01 +01:00
#include "cmExecutionStatus.h"
2017-04-14 19:02:05 +02:00
#include "cmMakefile.h"
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
2017-04-14 19:02:05 +02:00
#include "cmSystemTools.h"
2020-02-01 23:06:01 +01:00
bool cmSubdirCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
2016-10-30 18:24:19 +01:00
if (args.empty()) {
2020-02-01 23:06:01 +01:00
status.SetError("called with incorrect number of arguments");
return false;
2016-07-09 11:21:54 +02:00
}
bool res = true;
bool excludeFromAll = false;
2020-02-01 23:06:01 +01:00
cmMakefile& mf = status.GetMakefile();
2018-01-26 17:06:56 +01:00
for (std::string const& i : args) {
if (i == "EXCLUDE_FROM_ALL") {
excludeFromAll = true;
continue;
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
if (i == "PREORDER") {
2015-08-17 11:37:30 +02:00
// Ignored
continue;
2016-07-09 11:21:54 +02:00
}
// if they specified a relative path then compute the full
2020-02-01 23:06:01 +01:00
std::string srcPath = mf.GetCurrentSourceDirectory() + "/" + i;
2016-07-09 11:21:54 +02:00
if (cmSystemTools::FileIsDirectory(srcPath)) {
2020-02-01 23:06:01 +01:00
std::string binPath = mf.GetCurrentBinaryDirectory() + "/" + i;
mf.AddSubDirectory(srcPath, binPath, excludeFromAll, false);
2016-07-09 11:21:54 +02:00
}
// otherwise it is a full path
2018-01-26 17:06:56 +01:00
else if (cmSystemTools::FileIsDirectory(i)) {
// we must compute the binPath from the srcPath, we just take the last
// element from the source path and use that
2020-02-01 23:06:01 +01:00
std::string binPath = mf.GetCurrentBinaryDirectory() + "/" +
2018-01-26 17:06:56 +01:00
cmSystemTools::GetFilenameName(i);
2020-02-01 23:06:01 +01:00
mf.AddSubDirectory(i, binPath, excludeFromAll, false);
2016-07-09 11:21:54 +02:00
} else {
2020-02-01 23:06:01 +01:00
status.SetError(cmStrCat("Incorrect SUBDIRS command. Directory: ", i,
" does not exist."));
res = false;
}
2016-07-09 11:21:54 +02:00
}
return res;
}