cmake/Source/cmExtraSublimeTextGenerator.cxx

465 lines
16 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. */
2013-03-16 19:13:01 +02:00
#include "cmExtraSublimeTextGenerator.h"
2016-07-09 11:21:54 +02:00
2020-02-01 23:06:01 +01:00
#include <cstring>
2020-08-30 11:54:41 +02:00
#include <memory>
2017-04-14 19:02:05 +02:00
#include <set>
#include <sstream>
#include <utility>
2020-02-01 23:06:01 +01:00
#include "cmsys/RegularExpression.hxx"
2013-03-16 19:13:01 +02:00
#include "cmGeneratedFileStream.h"
2017-04-14 19:02:05 +02:00
#include "cmGeneratorExpression.h"
2013-03-16 19:13:01 +02:00
#include "cmGeneratorTarget.h"
2016-10-30 18:24:19 +01:00
#include "cmGlobalGenerator.h"
2013-03-16 19:13:01 +02:00
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
2019-11-11 23:01:05 +01:00
#include "cmMessageType.h"
2013-03-16 19:13:01 +02:00
#include "cmSourceFile.h"
2017-04-14 19:02:05 +02:00
#include "cmStateTypes.h"
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
2013-03-16 19:13:01 +02:00
#include "cmSystemTools.h"
2021-11-20 13:41:27 +01:00
#include "cmValue.h"
2017-04-14 19:02:05 +02:00
#include "cmake.h"
2013-03-16 19:13:01 +02:00
/*
Sublime Text 2 Generator
Author: Morné Chamberlain
This generator was initially based off of the CodeBlocks generator.
Some useful URLs:
Homepage:
http://www.sublimetext.com/
File format docs:
http://www.sublimetext.com/docs/2/projects.html
http://sublimetext.info/docs/en/reference/build_systems.html
*/
2016-10-30 18:24:19 +01:00
cmExternalMakefileProjectGeneratorFactory*
cmExtraSublimeTextGenerator::GetFactory()
2013-03-16 19:13:01 +02:00
{
2016-10-30 18:24:19 +01:00
static cmExternalMakefileProjectGeneratorSimpleFactory<
cmExtraSublimeTextGenerator>
factory("Sublime Text 2", "Generates Sublime Text 2 project files.");
if (factory.GetSupportedGlobalGenerators().empty()) {
#if defined(_WIN32)
factory.AddSupportedGlobalGenerator("MinGW Makefiles");
factory.AddSupportedGlobalGenerator("NMake Makefiles");
// disable until somebody actually tests it:
// factory.AddSupportedGlobalGenerator("MSYS Makefiles");
#endif
factory.AddSupportedGlobalGenerator("Ninja");
factory.AddSupportedGlobalGenerator("Unix Makefiles");
}
return &factory;
2013-03-16 19:13:01 +02:00
}
cmExtraSublimeTextGenerator::cmExtraSublimeTextGenerator()
{
2017-04-14 19:02:05 +02:00
this->ExcludeBuildFolder = false;
2013-03-16 19:13:01 +02:00
}
void cmExtraSublimeTextGenerator::Generate()
{
2017-04-14 19:02:05 +02:00
this->ExcludeBuildFolder = this->GlobalGenerator->GlobalSettingIsOn(
"CMAKE_SUBLIME_TEXT_2_EXCLUDE_BUILD_TREE");
this->EnvSettings = this->GlobalGenerator->GetSafeGlobalSetting(
"CMAKE_SUBLIME_TEXT_2_ENV_SETTINGS");
2013-03-16 19:13:01 +02:00
// for each sub project in the project create a sublime text 2 project
2018-01-26 17:06:56 +01:00
for (auto const& it : this->GlobalGenerator->GetProjectMap()) {
2013-03-16 19:13:01 +02:00
// create a project file
2018-01-26 17:06:56 +01:00
this->CreateProjectFile(it.second);
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
}
void cmExtraSublimeTextGenerator::CreateProjectFile(
2016-07-09 11:21:54 +02:00
const std::vector<cmLocalGenerator*>& lgs)
2013-03-16 19:13:01 +02:00
{
2016-07-09 11:21:54 +02:00
std::string outputDir = lgs[0]->GetCurrentBinaryDirectory();
std::string projectName = lgs[0]->GetProjectName();
2013-03-16 19:13:01 +02:00
const std::string filename =
2016-07-09 11:21:54 +02:00
outputDir + "/" + projectName + ".sublime-project";
2013-03-16 19:13:01 +02:00
this->CreateNewProjectFile(lgs, filename);
}
2016-07-09 11:21:54 +02:00
void cmExtraSublimeTextGenerator::CreateNewProjectFile(
const std::vector<cmLocalGenerator*>& lgs, const std::string& filename)
2013-03-16 19:13:01 +02:00
{
2016-07-09 11:21:54 +02:00
const cmMakefile* mf = lgs[0]->GetMakefile();
2017-04-14 19:02:05 +02:00
2018-10-28 12:09:07 +01:00
cmGeneratedFileStream fout(filename);
2016-07-09 11:21:54 +02:00
if (!fout) {
2013-03-16 19:13:01 +02:00
return;
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
2016-07-09 11:21:54 +02:00
const std::string& sourceRootRelativeToOutput = cmSystemTools::RelativePath(
lgs[0]->GetBinaryDirectory(), lgs[0]->GetSourceDirectory());
2013-03-16 19:13:01 +02:00
// Write the folder entries to the project file
fout << "{\n";
fout << "\t\"folders\":\n\t[\n\t";
2016-07-09 11:21:54 +02:00
if (!sourceRootRelativeToOutput.empty()) {
fout << "\t{\n\t\t\t\"path\": \"" << sourceRootRelativeToOutput << "\"";
const std::string& outputRelativeToSourceRoot =
cmSystemTools::RelativePath(lgs[0]->GetSourceDirectory(),
lgs[0]->GetBinaryDirectory());
if ((!outputRelativeToSourceRoot.empty()) &&
2013-03-16 19:13:01 +02:00
((outputRelativeToSourceRoot.length() < 3) ||
2016-07-09 11:21:54 +02:00
(outputRelativeToSourceRoot.substr(0, 3) != "../"))) {
2017-04-14 19:02:05 +02:00
if (this->ExcludeBuildFolder) {
fout << ",\n\t\t\t\"folder_exclude_patterns\": [\""
<< outputRelativeToSourceRoot << "\"]";
}
2013-03-16 19:13:01 +02:00
}
2016-07-09 11:21:54 +02:00
} else {
fout << "\t{\n\t\t\t\"path\": \"./\"";
}
2013-03-16 19:13:01 +02:00
fout << "\n\t\t}";
// End of the folders section
fout << "\n\t]";
// Write the beginning of the build systems section to the project file
fout << ",\n\t\"build_systems\":\n\t[\n\t";
// Set of include directories over all targets (sublime text/sublimeclang
// doesn't currently support these settings per build system, only project
// wide
MapSourceFileFlags sourceFileFlags;
2021-09-14 00:13:48 +02:00
this->AppendAllTargets(lgs, mf, fout, sourceFileFlags);
2013-03-16 19:13:01 +02:00
// End of build_systems
fout << "\n\t]";
2017-04-14 19:02:05 +02:00
std::string systemName = mf->GetSafeDefinition("CMAKE_SYSTEM_NAME");
2020-02-01 23:06:01 +01:00
std::vector<std::string> tokens = cmExpandedList(this->EnvSettings);
2017-04-14 19:02:05 +02:00
if (!this->EnvSettings.empty()) {
fout << ",";
fout << "\n\t\"env\":";
fout << "\n\t{";
fout << "\n\t\t" << systemName << ":";
fout << "\n\t\t{";
2018-01-26 17:06:56 +01:00
for (std::string const& t : tokens) {
size_t const pos = t.find_first_of('=');
2017-04-14 19:02:05 +02:00
if (pos != std::string::npos) {
2018-01-26 17:06:56 +01:00
std::string varName = t.substr(0, pos);
std::string varValue = t.substr(pos + 1);
2017-04-14 19:02:05 +02:00
fout << "\n\t\t\t\"" << varName << "\":\"" << varValue << "\"";
} else {
std::ostringstream e;
e << "Could not parse Env Vars specified in "
"\"CMAKE_SUBLIME_TEXT_2_ENV_SETTINGS\""
2018-01-26 17:06:56 +01:00
<< ", corrupted string " << t;
2019-11-11 23:01:05 +01:00
mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
2017-04-14 19:02:05 +02:00
}
}
fout << "\n\t\t}";
fout << "\n\t}";
}
fout << "\n}";
2013-03-16 19:13:01 +02:00
}
2016-07-09 11:21:54 +02:00
void cmExtraSublimeTextGenerator::AppendAllTargets(
const std::vector<cmLocalGenerator*>& lgs, const cmMakefile* mf,
cmGeneratedFileStream& fout, MapSourceFileFlags& sourceFileFlags)
2013-03-16 19:13:01 +02:00
{
2019-11-11 23:01:05 +01:00
const std::string& make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
2017-04-14 19:02:05 +02:00
std::string compiler;
2016-07-09 11:21:54 +02:00
if (!lgs.empty()) {
2018-01-26 17:06:56 +01:00
this->AppendTarget(fout, "all", lgs[0], nullptr, make.c_str(), mf,
2016-07-09 11:21:54 +02:00
compiler.c_str(), sourceFileFlags, true);
2018-01-26 17:06:56 +01:00
this->AppendTarget(fout, "clean", lgs[0], nullptr, make.c_str(), mf,
2016-07-09 11:21:54 +02:00
compiler.c_str(), sourceFileFlags, false);
}
2013-03-16 19:13:01 +02:00
// add all executable and library targets and some of the GLOBAL
// and UTILITY targets
2018-01-26 17:06:56 +01:00
for (cmLocalGenerator* lg : lgs) {
cmMakefile* makefile = lg->GetMakefile();
2020-08-30 11:54:41 +02:00
const auto& targets = lg->GetGeneratorTargets();
for (const auto& target : targets) {
2018-01-26 17:06:56 +01:00
std::string targetName = target->GetName();
switch (target->GetType()) {
2017-04-14 19:02:05 +02:00
case cmStateEnums::GLOBAL_TARGET: {
2013-03-16 19:13:01 +02:00
// Only add the global targets from CMAKE_BINARY_DIR,
// not from the subdirs
2018-04-23 21:13:27 +02:00
if (lg->GetCurrentBinaryDirectory() == lg->GetBinaryDirectory()) {
2018-01-26 17:06:56 +01:00
this->AppendTarget(fout, targetName, lg, nullptr, make.c_str(),
2016-07-09 11:21:54 +02:00
makefile, compiler.c_str(), sourceFileFlags,
false);
2013-03-16 19:13:01 +02:00
}
2016-07-09 11:21:54 +02:00
} break;
2017-04-14 19:02:05 +02:00
case cmStateEnums::UTILITY:
2013-03-16 19:13:01 +02:00
// Add all utility targets, except the Nightly/Continuous/
// Experimental-"sub"targets as e.g. NightlyStart
2020-08-30 11:54:41 +02:00
if ((cmHasLiteralPrefix(targetName, "Nightly") &&
2016-07-09 11:21:54 +02:00
(targetName != "Nightly")) ||
2020-08-30 11:54:41 +02:00
(cmHasLiteralPrefix(targetName, "Continuous") &&
2016-07-09 11:21:54 +02:00
(targetName != "Continuous")) ||
2020-08-30 11:54:41 +02:00
(cmHasLiteralPrefix(targetName, "Experimental") &&
2016-07-09 11:21:54 +02:00
(targetName != "Experimental"))) {
2013-03-16 19:13:01 +02:00
break;
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
2018-01-26 17:06:56 +01:00
this->AppendTarget(fout, targetName, lg, nullptr, make.c_str(),
2016-10-30 18:24:19 +01:00
makefile, compiler.c_str(), sourceFileFlags,
false);
2013-03-16 19:13:01 +02:00
break;
2017-04-14 19:02:05 +02:00
case cmStateEnums::EXECUTABLE:
case cmStateEnums::STATIC_LIBRARY:
case cmStateEnums::SHARED_LIBRARY:
case cmStateEnums::MODULE_LIBRARY:
case cmStateEnums::OBJECT_LIBRARY: {
2020-08-30 11:54:41 +02:00
this->AppendTarget(fout, targetName, lg, target.get(), make.c_str(),
2016-07-09 11:21:54 +02:00
makefile, compiler.c_str(), sourceFileFlags,
false);
2020-02-01 23:06:01 +01:00
std::string fastTarget = cmStrCat(targetName, "/fast");
2020-08-30 11:54:41 +02:00
this->AppendTarget(fout, fastTarget, lg, target.get(), make.c_str(),
2016-07-09 11:21:54 +02:00
makefile, compiler.c_str(), sourceFileFlags,
false);
} break;
2013-03-16 19:13:01 +02:00
default:
break;
}
}
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
}
2016-07-09 11:21:54 +02:00
void cmExtraSublimeTextGenerator::AppendTarget(
cmGeneratedFileStream& fout, const std::string& targetName,
cmLocalGenerator* lg, cmGeneratorTarget* target, const char* make,
2016-10-30 18:24:19 +01:00
const cmMakefile* makefile, const char* /*compiler*/,
2016-07-09 11:21:54 +02:00
MapSourceFileFlags& sourceFileFlags, bool firstTarget)
2013-03-16 19:13:01 +02:00
{
2018-01-26 17:06:56 +01:00
if (target != nullptr) {
2016-07-09 11:21:54 +02:00
std::vector<cmSourceFile*> sourceFiles;
target->GetSourceFiles(sourceFiles,
makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
2018-01-26 17:06:56 +01:00
for (cmSourceFile* sourceFile : sourceFiles) {
2020-02-01 23:06:01 +01:00
auto sourceFileFlagsIter =
sourceFileFlags.find(sourceFile->ResolveFullPath());
2016-07-09 11:21:54 +02:00
if (sourceFileFlagsIter == sourceFileFlags.end()) {
sourceFileFlagsIter =
sourceFileFlags
2020-02-01 23:06:01 +01:00
.insert(MapSourceFileFlags::value_type(
sourceFile->ResolveFullPath(), std::vector<std::string>()))
2016-07-09 11:21:54 +02:00
.first;
}
std::vector<std::string>& flags = sourceFileFlagsIter->second;
2018-01-26 17:06:56 +01:00
std::string flagsString =
this->ComputeFlagsForObject(sourceFile, lg, target);
std::string definesString = this->ComputeDefines(sourceFile, lg, target);
2018-04-23 21:13:27 +02:00
std::string includesString =
this->ComputeIncludes(sourceFile, lg, target);
2016-07-09 11:21:54 +02:00
flags.clear();
cmsys::RegularExpression flagRegex;
// Regular expression to extract compiler flags from a string
// https://gist.github.com/3944250
const char* regexString =
2019-11-11 23:01:05 +01:00
R"((^|[ ])-[DIOUWfgs][^= ]+(=\"[^"]+\"|=[^"][^ ]+)?)";
2016-07-09 11:21:54 +02:00
flagRegex.compile(regexString);
2018-04-23 21:13:27 +02:00
std::string workString =
2020-02-01 23:06:01 +01:00
cmStrCat(flagsString, " ", definesString, " ", includesString);
2016-07-09 11:21:54 +02:00
while (flagRegex.find(workString)) {
std::string::size_type start = flagRegex.start();
if (workString[start] == ' ') {
start++;
}
flags.push_back(workString.substr(start, flagRegex.end() - start));
if (flagRegex.end() < workString.size()) {
workString = workString.substr(flagRegex.end());
} else {
2018-01-26 17:06:56 +01:00
workString.clear();
2013-03-16 19:13:01 +02:00
}
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
}
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
// Ninja uses ninja.build files (look for a way to get the output file name
// from cmMakefile or something)
std::string makefileName;
2016-07-09 11:21:54 +02:00
if (this->GlobalGenerator->GetName() == "Ninja") {
makefileName = "build.ninja";
} else {
makefileName = "Makefile";
}
if (!firstTarget) {
2013-03-16 19:13:01 +02:00
fout << ",\n\t";
2016-07-09 11:21:54 +02:00
}
fout << "\t{\n\t\t\t\"name\": \"" << lg->GetProjectName() << " - "
<< targetName << "\",\n";
fout << "\t\t\t\"cmd\": ["
2020-08-30 11:54:41 +02:00
<< this->BuildMakeCommand(make, makefileName, targetName) << "],\n";
2013-03-16 19:13:01 +02:00
fout << "\t\t\t\"working_dir\": \"${project_path}\",\n";
2017-04-14 19:02:05 +02:00
fout << "\t\t\t\"file_regex\": \""
"^(..[^:]*)(?::|\\\\()([0-9]+)(?::|\\\\))(?:([0-9]+):)?\\\\s*(.*)"
"\"\n";
2013-03-16 19:13:01 +02:00
fout << "\t\t}";
}
// Create the command line for building the given target using the selected
// make
std::string cmExtraSublimeTextGenerator::BuildMakeCommand(
2020-08-30 11:54:41 +02:00
const std::string& make, const std::string& makefile,
const std::string& target)
2013-03-16 19:13:01 +02:00
{
2020-02-01 23:06:01 +01:00
std::string command = cmStrCat('"', make, '"');
2015-04-27 22:25:09 +02:00
std::string generator = this->GlobalGenerator->GetName();
2016-07-09 11:21:54 +02:00
if (generator == "NMake Makefiles") {
2013-03-16 19:13:01 +02:00
std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
2019-11-11 23:01:05 +01:00
command += R"(, "/NOLOGO", "/f", ")";
2013-03-16 19:13:01 +02:00
command += makefileName + "\"";
2017-04-14 19:02:05 +02:00
command += ", \"" + target + "\"";
2016-07-09 11:21:54 +02:00
} else if (generator == "Ninja") {
2013-03-16 19:13:01 +02:00
std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
2019-11-11 23:01:05 +01:00
command += R"(, "-f", ")";
2013-03-16 19:13:01 +02:00
command += makefileName + "\"";
2017-04-14 19:02:05 +02:00
command += ", \"" + target + "\"";
2016-07-09 11:21:54 +02:00
} else {
2013-03-16 19:13:01 +02:00
std::string makefileName;
2016-07-09 11:21:54 +02:00
if (generator == "MinGW Makefiles") {
// no escaping of spaces in this case, see
2020-08-30 11:54:41 +02:00
// https://gitlab.kitware.com/cmake/cmake/-/issues/10014
2016-07-09 11:21:54 +02:00
makefileName = makefile;
} else {
makefileName = cmSystemTools::ConvertToOutputPath(makefile);
}
2019-11-11 23:01:05 +01:00
command += R"(, "-f", ")";
2013-03-16 19:13:01 +02:00
command += makefileName + "\"";
2017-04-14 19:02:05 +02:00
command += ", \"" + target + "\"";
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
return command;
}
// TODO: Most of the code is picked up from the Ninja generator, refactor it.
2016-07-09 11:21:54 +02:00
std::string cmExtraSublimeTextGenerator::ComputeFlagsForObject(
cmSourceFile* source, cmLocalGenerator* lg, cmGeneratorTarget* gtgt)
2013-03-16 19:13:01 +02:00
{
std::string flags;
2020-02-01 23:06:01 +01:00
std::string language = source->GetOrDetermineLanguage();
2016-07-09 11:21:54 +02:00
if (language.empty()) {
language = "C";
}
2021-09-14 00:13:48 +02:00
// Explicitly add the explicit language flag before any other flag
// so user flags can override it.
gtgt->AddExplicitLanguageFlags(flags, *source);
2016-10-30 18:24:19 +01:00
std::string const& config =
lg->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
2013-03-16 19:13:01 +02:00
2016-10-30 18:24:19 +01:00
lg->GetTargetCompileFlags(gtgt, config, language, flags);
2013-03-16 19:13:01 +02:00
2018-04-23 21:13:27 +02:00
// Add source file specific flags.
2018-10-28 12:09:07 +01:00
cmGeneratorExpressionInterpreter genexInterpreter(lg, config, gtgt,
language);
2018-04-23 21:13:27 +02:00
const std::string COMPILE_FLAGS("COMPILE_FLAGS");
2021-11-20 13:41:27 +01:00
if (cmValue cflags = source->GetProperty(COMPILE_FLAGS)) {
2020-08-30 11:54:41 +02:00
lg->AppendFlags(flags, genexInterpreter.Evaluate(*cflags, COMPILE_FLAGS));
2013-03-16 19:13:01 +02:00
}
2018-04-23 21:13:27 +02:00
const std::string COMPILE_OPTIONS("COMPILE_OPTIONS");
2021-11-20 13:41:27 +01:00
if (cmValue coptions = source->GetProperty(COMPILE_OPTIONS)) {
2018-04-23 21:13:27 +02:00
lg->AppendCompileOptions(
2020-08-30 11:54:41 +02:00
flags, genexInterpreter.Evaluate(*coptions, COMPILE_OPTIONS));
2017-04-14 19:02:05 +02:00
}
2013-03-16 19:13:01 +02:00
return flags;
}
// TODO: Refactor with
// void cmMakefileTargetGenerator::WriteTargetLanguageFlags().
2016-07-09 11:21:54 +02:00
std::string cmExtraSublimeTextGenerator::ComputeDefines(
cmSourceFile* source, cmLocalGenerator* lg, cmGeneratorTarget* target)
2013-03-16 19:13:01 +02:00
{
std::set<std::string> defines;
2016-07-09 11:21:54 +02:00
cmMakefile* makefile = lg->GetMakefile();
2020-02-01 23:06:01 +01:00
const std::string& language = source->GetOrDetermineLanguage();
2015-04-27 22:25:09 +02:00
const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
2018-10-28 12:09:07 +01:00
cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target,
language);
2013-03-16 19:13:01 +02:00
// Add preprocessor definitions for this target and configuration.
2019-11-11 23:01:05 +01:00
lg->GetTargetDefines(target, config, language, defines);
2018-04-23 21:13:27 +02:00
const std::string COMPILE_DEFINITIONS("COMPILE_DEFINITIONS");
2021-11-20 13:41:27 +01:00
if (cmValue compile_defs = source->GetProperty(COMPILE_DEFINITIONS)) {
2018-04-23 21:13:27 +02:00
lg->AppendDefines(
2020-08-30 11:54:41 +02:00
defines, genexInterpreter.Evaluate(*compile_defs, COMPILE_DEFINITIONS));
2018-04-23 21:13:27 +02:00
}
2020-02-01 23:06:01 +01:00
std::string defPropName =
cmStrCat("COMPILE_DEFINITIONS_", cmSystemTools::UpperCase(config));
2021-11-20 13:41:27 +01:00
if (cmValue config_compile_defs = source->GetProperty(defPropName)) {
2018-08-09 18:06:22 +02:00
lg->AppendDefines(
defines,
2020-08-30 11:54:41 +02:00
genexInterpreter.Evaluate(*config_compile_defs, COMPILE_DEFINITIONS));
2013-03-16 19:13:01 +02:00
}
std::string definesString;
lg->JoinDefines(defines, definesString, language);
return definesString;
}
2018-04-23 21:13:27 +02:00
std::string cmExtraSublimeTextGenerator::ComputeIncludes(
cmSourceFile* source, cmLocalGenerator* lg, cmGeneratorTarget* target)
{
std::vector<std::string> includes;
cmMakefile* makefile = lg->GetMakefile();
2020-02-01 23:06:01 +01:00
const std::string& language = source->GetOrDetermineLanguage();
2018-04-23 21:13:27 +02:00
const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
2018-10-28 12:09:07 +01:00
cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target,
language);
2018-04-23 21:13:27 +02:00
// Add include directories for this source file
const std::string INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES");
2021-11-20 13:41:27 +01:00
if (cmValue cincludes = source->GetProperty(INCLUDE_DIRECTORIES)) {
2018-04-23 21:13:27 +02:00
lg->AppendIncludeDirectories(
2020-08-30 11:54:41 +02:00
includes, genexInterpreter.Evaluate(*cincludes, INCLUDE_DIRECTORIES),
2018-04-23 21:13:27 +02:00
*source);
}
// Add include directory flags.
lg->GetIncludeDirectories(includes, target, language, config);
std::string includesString =
2022-03-29 21:10:50 +02:00
lg->GetIncludeFlags(includes, target, language, config, false);
2018-04-23 21:13:27 +02:00
return includesString;
}
bool cmExtraSublimeTextGenerator::Open(const std::string& bindir,
const std::string& projectName,
bool dryRun)
{
2021-11-20 13:41:27 +01:00
cmValue sublExecutable =
2018-04-23 21:13:27 +02:00
this->GlobalGenerator->GetCMakeInstance()->GetCacheDefinition(
"CMAKE_SUBLIMETEXT_EXECUTABLE");
if (!sublExecutable) {
return false;
}
2021-09-14 00:13:48 +02:00
if (cmIsNOTFOUND(*sublExecutable)) {
2018-04-23 21:13:27 +02:00
return false;
}
std::string filename = bindir + "/" + projectName + ".sublime-project";
if (dryRun) {
return cmSystemTools::FileExists(filename, true);
}
return cmSystemTools::RunSingleCommand(
2021-09-14 00:13:48 +02:00
{ *sublExecutable, "--project", filename });
2018-04-23 21:13:27 +02:00
}