diff options
Diffstat (limited to 'Source/cmLocalGenerator.cxx')
-rw-r--r-- | Source/cmLocalGenerator.cxx | 174 |
1 files changed, 138 insertions, 36 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index e91eb46..2f29791 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -45,6 +45,7 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile) : cmOutputConverter(makefile->GetStateSnapshot()) , StateSnapshot(makefile->GetStateSnapshot()) + , DirectoryBacktrace(makefile->GetBacktrace()) { this->GlobalGenerator = gg; @@ -68,7 +69,7 @@ cmLocalGenerator::~cmLocalGenerator() void cmLocalGenerator::IssueMessage(cmake::MessageType t, std::string const& text) const { - this->Makefile->IssueMessage(t, text); + this->GetCMakeInstance()->IssueMessage(t, text, this->DirectoryBacktrace); } void cmLocalGenerator::ComputeObjectMaxPath() @@ -271,7 +272,7 @@ void cmLocalGenerator::GenerateInstallRules() // Choose a default install configuration. std::string default_config = config; const char* default_order[] = { "RELEASE", "MINSIZEREL", "RELWITHDEBINFO", - "DEBUG", 0 }; + "DEBUG", CM_NULLPTR }; for (const char** c = default_order; *c && default_config.empty(); ++c) { for (std::vector<std::string>::iterator i = configurationTypes.begin(); i != configurationTypes.end(); ++i) { @@ -444,7 +445,7 @@ cmGeneratorTarget* cmLocalGenerator::FindLocalNonAliasGeneratorTarget( if (ti != this->GeneratorTargets.end()) { return *ti; } - return 0; + return CM_NULLPTR; } void cmLocalGenerator::ComputeTargetManifest() @@ -507,7 +508,7 @@ static const char* ruleReplaceVars[] = { "CMAKE_RANLIB", "CMAKE_LINKER", "CMAKE_CL_SHOWINCLUDES_PREFIX", - 0 + CM_NULLPTR }; std::string cmLocalGenerator::ExpandRuleVariable( @@ -703,13 +704,13 @@ std::string cmLocalGenerator::ExpandRuleVariable( std::string actualReplace = ruleReplaceVars[pos]; // If this is the compiler then look for the extra variable // _COMPILER_ARG1 which must be the first argument to the compiler - const char* compilerArg1 = 0; - const char* compilerTarget = 0; - const char* compilerOptionTarget = 0; - const char* compilerExternalToolchain = 0; - const char* compilerOptionExternalToolchain = 0; - const char* compilerSysroot = 0; - const char* compilerOptionSysroot = 0; + const char* compilerArg1 = CM_NULLPTR; + const char* compilerTarget = CM_NULLPTR; + const char* compilerOptionTarget = CM_NULLPTR; + const char* compilerExternalToolchain = CM_NULLPTR; + const char* compilerOptionExternalToolchain = CM_NULLPTR; + const char* compilerSysroot = CM_NULLPTR; + const char* compilerOptionSysroot = CM_NULLPTR; if (actualReplace == "CMAKE_${LANG}_COMPILER") { std::string arg1 = actualReplace + "_ARG1"; cmSystemTools::ReplaceString(arg1, "${LANG}", lang); @@ -831,8 +832,8 @@ void cmLocalGenerator::InsertRuleLauncher(std::string& s, std::string cmLocalGenerator::ConvertToIncludeReference( std::string const& path, OutputFormat format, bool forceFullPaths) { - return this->ConvertToOutputForExisting( - path, forceFullPaths ? FULL : START_OUTPUT, format); + static_cast<void>(forceFullPaths); + return this->ConvertToOutputForExisting(path, format); } std::string cmLocalGenerator::GetIncludeFlags( @@ -871,7 +872,7 @@ std::string cmLocalGenerator::GetIncludeFlags( // normal flag is repeated for each directory. std::string sysFlagVar = "CMAKE_INCLUDE_SYSTEM_FLAG_"; sysFlagVar += lang; - const char* sysIncludeFlag = 0; + const char* sysIncludeFlag = CM_NULLPTR; if (repeatFlag) { sysIncludeFlag = this->Makefile->GetDefinition(sysFlagVar); } @@ -943,7 +944,7 @@ std::string cmLocalGenerator::GetIncludeFlags( void cmLocalGenerator::AddCompileDefinitions(std::set<std::string>& defines, cmGeneratorTarget const* target, const std::string& config, - const std::string& lang) + const std::string& lang) const { std::vector<std::string> targetDefines; target->GetCompileDefinitions(targetDefines, config, lang); @@ -1152,13 +1153,11 @@ void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags, } void cmLocalGenerator::GetTargetFlags( - std::string& linkLibs, std::string& flags, std::string& linkFlags, - std::string& frameworkPath, std::string& linkPath, cmGeneratorTarget* target, - bool useWatcomQuote) + const std::string& config, std::string& linkLibs, std::string& flags, + std::string& linkFlags, std::string& frameworkPath, std::string& linkPath, + cmGeneratorTarget* target, bool useWatcomQuote) { - std::string buildType = - this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); - buildType = cmSystemTools::UpperCase(buildType); + const std::string buildType = cmSystemTools::UpperCase(config); const char* libraryLinkVariable = "CMAKE_SHARED_LINKER_FLAGS"; // default to shared library @@ -1273,6 +1272,112 @@ void cmLocalGenerator::GetTargetFlags( } } +void cmLocalGenerator::GetTargetCompileFlags(cmGeneratorTarget* target, + std::string const& config, + std::string const& lang, + std::string& flags) +{ + cmMakefile* mf = this->GetMakefile(); + + // Add language-specific flags. + this->AddLanguageFlags(flags, lang, config); + + if (target->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION", config)) { + this->AppendFeatureOptions(flags, lang, "IPO"); + } + + this->AddArchitectureFlags(flags, target, lang, config); + + if (lang == "Fortran") { + this->AppendFlags(flags, this->GetTargetFortranFlags(target, config)); + } + + this->AddCMP0018Flags(flags, target, lang, config); + this->AddVisibilityPresetFlags(flags, target, lang); + this->AppendFlags(flags, mf->GetDefineFlags()); + this->AppendFlags(flags, this->GetFrameworkFlags(lang, config, target)); + this->AddCompileOptions(flags, target, lang, config); +} + +static std::string GetFrameworkFlags(const std::string& lang, + const std::string& config, + cmGeneratorTarget* target) +{ + cmLocalGenerator* lg = target->GetLocalGenerator(); + cmMakefile* mf = lg->GetMakefile(); + + if (!mf->IsOn("APPLE")) { + return std::string(); + } + + std::string fwSearchFlagVar = "CMAKE_" + lang + "_FRAMEWORK_SEARCH_FLAG"; + const char* fwSearchFlag = mf->GetDefinition(fwSearchFlagVar); + if (!(fwSearchFlag && *fwSearchFlag)) { + return std::string(); + } + + std::set<std::string> emitted; +#ifdef __APPLE__ /* don't insert this when crosscompiling e.g. to iphone */ + emitted.insert("/System/Library/Frameworks"); +#endif + std::vector<std::string> includes; + + lg->GetIncludeDirectories(includes, target, "C", config); + // check all include directories for frameworks as this + // will already have added a -F for the framework + for (std::vector<std::string>::iterator i = includes.begin(); + i != includes.end(); ++i) { + if (lg->GetGlobalGenerator()->NameResolvesToFramework(*i)) { + std::string frameworkDir = *i; + frameworkDir += "/../"; + frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir); + emitted.insert(frameworkDir); + } + } + + std::string flags; + if (cmComputeLinkInformation* cli = target->GetLinkInformation(config)) { + std::vector<std::string> const& frameworks = cli->GetFrameworkPaths(); + for (std::vector<std::string>::const_iterator i = frameworks.begin(); + i != frameworks.end(); ++i) { + if (emitted.insert(*i).second) { + flags += fwSearchFlag; + flags += lg->ConvertToOutputFormat(*i, cmOutputConverter::SHELL); + flags += " "; + } + } + } + return flags; +} + +std::string cmLocalGenerator::GetFrameworkFlags(std::string const& l, + std::string const& config, + cmGeneratorTarget* target) +{ + return ::GetFrameworkFlags(l, config, target); +} + +void cmLocalGenerator::GetTargetDefines(cmGeneratorTarget const* target, + std::string const& config, + std::string const& lang, + std::set<std::string>& defines) const +{ + // Add the export symbol definition for shared library objects. + if (const char* exportMacro = target->GetExportMacro()) { + this->AppendDefines(defines, exportMacro); + } + + // Add preprocessor definitions for this target and configuration. + this->AddCompileDefinitions(defines, target, config, lang.c_str()); +} + +std::string cmLocalGenerator::GetTargetFortranFlags(cmGeneratorTarget const*, + std::string const&) +{ + // Implemented by specific generators that override this. + return std::string(); +} + std::string cmLocalGenerator::ConvertToLinkReference(std::string const& lib, OutputFormat format) { @@ -1350,7 +1455,7 @@ void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries, w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0065) << "\n" "For compatibility with older versions of CMake, " "additional flags may be added to export symbols on all " - "executables regardless of thier ENABLE_EXPORTS property."; + "executables regardless of their ENABLE_EXPORTS property."; /* clang-format on */ this->IssueMessage(cmake::AUTHOR_WARNING, w.str()); } @@ -1398,7 +1503,7 @@ void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries, for (std::vector<std::string>::const_iterator libDir = libDirs.begin(); libDir != libDirs.end(); ++libDir) { std::string libpath = - this->ConvertToOutputForExisting(*libDir, START_OUTPUT, shellFormat); + this->ConvertToOutputForExisting(*libDir, shellFormat); linkPath += " " + libPathFlag; linkPath += libpath; linkPath += libPathTerminator; @@ -1475,16 +1580,12 @@ void cmLocalGenerator::AddArchitectureFlags(std::string& flags, const std::string& config) { // Only add Mac OS X specific flags on Darwin platforms (OSX and iphone): - if (!this->Makefile->IsOn("APPLE")) { - return; - } - - if (this->EmitUniversalBinaryFlags) { + if (this->Makefile->IsOn("APPLE") && this->EmitUniversalBinaryFlags) { std::vector<std::string> archs; target->GetAppleArchs(config, archs); const char* sysroot = this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT"); if (sysroot && sysroot[0] == '/' && !sysroot[1]) { - sysroot = 0; + sysroot = CM_NULLPTR; } std::string sysrootFlagVar = std::string("CMAKE_") + lang + "_SYSROOT_FLAG"; @@ -1824,7 +1925,7 @@ void cmLocalGenerator::AddVisibilityPresetFlags( } std::string warnCMP0063; - std::string* pWarnCMP0063 = 0; + std::string* pWarnCMP0063 = CM_NULLPTR; if (target->GetType() != cmState::SHARED_LIBRARY && target->GetType() != cmState::MODULE_LIBRARY && !target->IsExecutableWithExports()) { @@ -1935,7 +2036,7 @@ void cmLocalGenerator::AddPositionIndependentFlags(std::string& flags, std::string const& lang, int targetType) { - const char* picFlags = 0; + const char* picFlags = CM_NULLPTR; if (targetType == cmState::EXECUTABLE) { std::string flagsVar = "CMAKE_"; @@ -1999,7 +2100,7 @@ void cmLocalGenerator::AppendFlagEscape(std::string& flags, } void cmLocalGenerator::AppendDefines(std::set<std::string>& defines, - const char* defines_list) + const char* defines_list) const { // Short-circuit if there are no definitions. if (!defines_list) { @@ -2013,7 +2114,8 @@ void cmLocalGenerator::AppendDefines(std::set<std::string>& defines, } void cmLocalGenerator::AppendDefines( - std::set<std::string>& defines, const std::vector<std::string>& defines_vec) + std::set<std::string>& defines, + const std::vector<std::string>& defines_vec) const { for (std::vector<std::string>::const_iterator di = defines_vec.begin(); di != defines_vec.end(); ++di) { @@ -2115,7 +2217,7 @@ const char* cmLocalGenerator::GetFeature(const std::string& feature, } snp = snp.GetBuildsystemDirectoryParent(); } - return 0; + return CM_NULLPTR; } std::string cmLocalGenerator::GetProjectName() const @@ -2178,7 +2280,7 @@ void cmLocalGenerator::GenerateTargetInstallRules( // Include the user-specified pre-install script for this target. if (const char* preinstall = (*l)->GetProperty("PRE_INSTALL_SCRIPT")) { - cmInstallScriptGenerator g(preinstall, false, 0, false); + cmInstallScriptGenerator g(preinstall, false, CM_NULLPTR, false); g.Generate(os, config, configurationTypes); } @@ -2231,7 +2333,7 @@ void cmLocalGenerator::GenerateTargetInstallRules( // Include the user-specified post-install script for this target. if (const char* postinstall = (*l)->GetProperty("POST_INSTALL_SCRIPT")) { - cmInstallScriptGenerator g(postinstall, false, 0, false); + cmInstallScriptGenerator g(postinstall, false, CM_NULLPTR, false); g.Generate(os, config, configurationTypes); } } |