cmake/Source/cmAuxSourceDirectoryCommand.cxx

79 lines
2.4 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 "cmAuxSourceDirectoryCommand.h"
2016-07-09 11:21:54 +02:00
2017-07-20 19:35:53 +02:00
#include "cmsys/Directory.hxx"
2017-04-14 19:02:05 +02:00
#include <algorithm>
#include <stddef.h>
#include "cmAlgorithms.h"
#include "cmMakefile.h"
#include "cmSourceFile.h"
2017-04-14 19:02:05 +02:00
#include "cmSystemTools.h"
#include "cmake.h"
2017-04-14 19:02:05 +02:00
class cmExecutionStatus;
// cmAuxSourceDirectoryCommand
2016-07-09 11:21:54 +02:00
bool cmAuxSourceDirectoryCommand::InitialPass(
std::vector<std::string> const& args, cmExecutionStatus&)
{
2017-07-20 19:35:53 +02:00
if (args.size() != 2) {
this->SetError("called with incorrect number of arguments");
return false;
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
std::string sourceListValue;
2017-07-20 19:35:53 +02:00
std::string const& templateDirectory = args[0];
std::string tdir;
2018-04-23 21:13:27 +02:00
if (!cmSystemTools::FileIsFullPath(templateDirectory)) {
2015-08-17 11:37:30 +02:00
tdir = this->Makefile->GetCurrentSourceDirectory();
tdir += "/";
tdir += templateDirectory;
2016-07-09 11:21:54 +02:00
} else {
tdir = templateDirectory;
2016-07-09 11:21:54 +02:00
}
// was the list already populated
2016-07-09 11:21:54 +02:00
const char* def = this->Makefile->GetDefinition(args[1]);
if (def) {
sourceListValue = def;
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
2016-10-30 18:24:19 +01:00
std::vector<std::string> files;
// Load all the files in the directory
cmsys::Directory dir;
2017-04-14 19:02:05 +02:00
if (dir.Load(tdir)) {
size_t numfiles = dir.GetNumberOfFiles();
2016-07-09 11:21:54 +02:00
for (size_t i = 0; i < numfiles; ++i) {
std::string file = dir.GetFile(static_cast<unsigned long>(i));
// Split the filename into base and extension
2017-04-14 19:02:05 +02:00
std::string::size_type dotpos = file.rfind('.');
2016-07-09 11:21:54 +02:00
if (dotpos != std::string::npos) {
std::string ext = file.substr(dotpos + 1);
std::string base = file.substr(0, dotpos);
// Process only source files
2018-04-23 21:13:27 +02:00
auto cm = this->Makefile->GetCMakeInstance();
if (!base.empty() && cm->IsSourceExtension(ext)) {
std::string fullname = templateDirectory;
fullname += "/";
fullname += file;
2013-03-16 19:13:01 +02:00
// add the file as a class file so
// depends can be done
2016-07-09 11:21:54 +02:00
cmSourceFile* sf = this->Makefile->GetOrCreateSource(fullname);
sf->SetProperty("ABSTRACT", "0");
2018-04-23 21:13:27 +02:00
files.push_back(std::move(fullname));
}
}
}
2016-07-09 11:21:54 +02:00
}
2016-10-30 18:24:19 +01:00
std::sort(files.begin(), files.end());
if (!sourceListValue.empty()) {
sourceListValue += ";";
}
sourceListValue += cmJoin(files, ";");
2015-04-27 22:25:09 +02:00
this->Makefile->AddDefinition(args[1], sourceListValue.c_str());
return true;
}