diff options
author | Kitware Robot <kwrobot@kitware.com> | 2016-05-16 14:34:04 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-05-16 20:05:19 (GMT) |
commit | d9fd2f5402eeaa345691313658e02b51038f570b (patch) | |
tree | dca71b9a7e267f4c6300da3eb770415381726785 /Source/cmNinjaNormalTargetGenerator.cxx | |
parent | 82df6deaafb36cbbfd450202bb20b320f637751a (diff) | |
download | CMake-d9fd2f5402eeaa345691313658e02b51038f570b.zip CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.gz CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.bz2 |
Revise C++ coding style using clang-format
Run the `Utilities/Scripts/clang-format.bash` script to update
all our C++ code to a new style defined by `.clang-format`.
Use `clang-format` version 3.8.
* If you reached this commit for a line in `git blame`, re-run the blame
operation starting at the parent of this commit to see older history
for the content.
* See the parent commit for instructions to rebase a change across this
style transition commit.
Diffstat (limited to 'Source/cmNinjaNormalTargetGenerator.cxx')
-rw-r--r-- | Source/cmNinjaNormalTargetGenerator.cxx | 591 |
1 files changed, 239 insertions, 352 deletions
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 04e84fe..831d44b 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -30,9 +30,8 @@ #include <unistd.h> #endif - -cmNinjaNormalTargetGenerator:: -cmNinjaNormalTargetGenerator(cmGeneratorTarget* target) +cmNinjaNormalTargetGenerator::cmNinjaNormalTargetGenerator( + cmGeneratorTarget* target) : cmNinjaTargetGenerator(target) , TargetNameOut() , TargetNameSO() @@ -43,28 +42,23 @@ cmNinjaNormalTargetGenerator(cmGeneratorTarget* target) { this->TargetLinkLanguage = target->GetLinkerLanguage(this->GetConfigName()); if (target->GetType() == cmState::EXECUTABLE) - this->GetGeneratorTarget()->GetExecutableNames(this->TargetNameOut, - this->TargetNameReal, - this->TargetNameImport, - this->TargetNamePDB, - GetLocalGenerator()->GetConfigName()); + this->GetGeneratorTarget()->GetExecutableNames( + this->TargetNameOut, this->TargetNameReal, this->TargetNameImport, + this->TargetNamePDB, GetLocalGenerator()->GetConfigName()); else - this->GetGeneratorTarget()->GetLibraryNames(this->TargetNameOut, - this->TargetNameSO, - this->TargetNameReal, - this->TargetNameImport, - this->TargetNamePDB, - GetLocalGenerator()->GetConfigName()); - - if(target->GetType() != cmState::OBJECT_LIBRARY) - { + this->GetGeneratorTarget()->GetLibraryNames( + this->TargetNameOut, this->TargetNameSO, this->TargetNameReal, + this->TargetNameImport, this->TargetNamePDB, + GetLocalGenerator()->GetConfigName()); + + if (target->GetType() != cmState::OBJECT_LIBRARY) { // on Windows the output dir is already needed at compile time // ensure the directory exists (OutDir test) EnsureDirectoryExists(target->GetDirectory(this->GetConfigName())); - } + } - this->OSXBundleGenerator = new cmOSXBundleGenerator(target, - this->GetConfigName()); + this->OSXBundleGenerator = + new cmOSXBundleGenerator(target, this->GetConfigName()); this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders); } @@ -88,14 +82,11 @@ void cmNinjaNormalTargetGenerator::Generate() // Write the build statements this->WriteObjectBuildStatements(); - if(this->GetGeneratorTarget()->GetType() == cmState::OBJECT_LIBRARY) - { + if (this->GetGeneratorTarget()->GetType() == cmState::OBJECT_LIBRARY) { this->WriteObjectLibStatement(); - } - else - { + } else { this->WriteLinkStatement(); - } + } } void cmNinjaNormalTargetGenerator::WriteLanguagesRules() @@ -105,34 +96,28 @@ void cmNinjaNormalTargetGenerator::WriteLanguagesRules() this->GetRulesFileStream() << "# Rules for each languages for " << cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType()) - << " target " - << this->GetTargetName() - << "\n\n"; + << " target " << this->GetTargetName() << "\n\n"; #endif // Write rules for languages compiled in this target. std::set<std::string> languages; std::vector<cmSourceFile*> sourceFiles; - this->GetGeneratorTarget()->GetSourceFiles(sourceFiles, - this->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE")); - for(std::vector<cmSourceFile*>::const_iterator - i = sourceFiles.begin(); i != sourceFiles.end(); ++i) - { + this->GetGeneratorTarget()->GetSourceFiles( + sourceFiles, this->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE")); + for (std::vector<cmSourceFile*>::const_iterator i = sourceFiles.begin(); + i != sourceFiles.end(); ++i) { const std::string& lang = (*i)->GetLanguage(); - if(!lang.empty()) - { + if (!lang.empty()) { languages.insert(lang); - } } - for(std::set<std::string>::const_iterator l = languages.begin(); - l != languages.end(); - ++l) - { + } + for (std::set<std::string>::const_iterator l = languages.begin(); + l != languages.end(); ++l) { this->WriteLanguageRules(*l); - } + } } -const char *cmNinjaNormalTargetGenerator::GetVisibleTypeName() const +const char* cmNinjaNormalTargetGenerator::GetVisibleTypeName() const { switch (this->GetGeneratorTarget()->GetType()) { case cmState::STATIC_LIBRARY: @@ -151,25 +136,17 @@ const char *cmNinjaNormalTargetGenerator::GetVisibleTypeName() const } } -std::string -cmNinjaNormalTargetGenerator -::LanguageLinkerRule() const +std::string cmNinjaNormalTargetGenerator::LanguageLinkerRule() const { - return this->TargetLinkLanguage - + "_" - + cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType()) - + "_LINKER__" - + cmGlobalNinjaGenerator::EncodeRuleName( - this->GetGeneratorTarget()->GetName()) - ; + return this->TargetLinkLanguage + "_" + + cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType()) + + "_LINKER__" + cmGlobalNinjaGenerator::EncodeRuleName( + this->GetGeneratorTarget()->GetName()); } -void -cmNinjaNormalTargetGenerator -::WriteLinkRule(bool useResponseFile) +void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile) { - cmState::TargetType targetType = - this->GetGeneratorTarget()->GetType(); + cmState::TargetType targetType = this->GetGeneratorTarget()->GetType(); std::string ruleName = this->LanguageLinkerRule(); // Select whether to use a response file for objects. @@ -187,29 +164,29 @@ cmNinjaNormalTargetGenerator vars.Objects = "$in"; vars.LinkLibraries = "$LINK_PATH $LINK_LIBRARIES"; } else { - std::string cmakeVarLang = "CMAKE_"; - cmakeVarLang += this->TargetLinkLanguage; - - // build response file name - std::string cmakeLinkVar = cmakeVarLang + "_RESPONSE_FILE_LINK_FLAG"; - const char * flag = GetMakefile()->GetDefinition(cmakeLinkVar); - if(flag) { - responseFlag = flag; - } else { - responseFlag = "@"; - } - rspfile = "$RSP_FILE"; - responseFlag += rspfile; - - // build response file content - if (this->GetGlobalGenerator()->IsGCCOnWindows()) { - rspcontent = "$in"; - } else { - rspcontent = "$in_newline"; - } - rspcontent += " $LINK_PATH $LINK_LIBRARIES"; - vars.Objects = responseFlag.c_str(); - vars.LinkLibraries = ""; + std::string cmakeVarLang = "CMAKE_"; + cmakeVarLang += this->TargetLinkLanguage; + + // build response file name + std::string cmakeLinkVar = cmakeVarLang + "_RESPONSE_FILE_LINK_FLAG"; + const char* flag = GetMakefile()->GetDefinition(cmakeLinkVar); + if (flag) { + responseFlag = flag; + } else { + responseFlag = "@"; + } + rspfile = "$RSP_FILE"; + responseFlag += rspfile; + + // build response file content + if (this->GetGlobalGenerator()->IsGCCOnWindows()) { + rspcontent = "$in"; + } else { + rspcontent = "$in_newline"; + } + rspcontent += " $LINK_PATH $LINK_LIBRARIES"; + vars.Objects = responseFlag.c_str(); + vars.LinkLibraries = ""; } vars.ObjectDir = "$OBJECT_DIR"; @@ -225,15 +202,15 @@ cmNinjaNormalTargetGenerator std::string targetVersionMajor; std::string targetVersionMinor; { - std::ostringstream majorStream; - std::ostringstream minorStream; - int major; - int minor; - this->GetGeneratorTarget()->GetTargetVersion(major, minor); - majorStream << major; - minorStream << minor; - targetVersionMajor = majorStream.str(); - targetVersionMinor = minorStream.str(); + std::ostringstream majorStream; + std::ostringstream minorStream; + int major; + int minor; + this->GetGeneratorTarget()->GetTargetVersion(major, minor); + majorStream << major; + minorStream << minor; + targetVersionMajor = majorStream.str(); + targetVersionMinor = minorStream.str(); } vars.TargetVersionMajor = targetVersionMajor.c_str(); vars.TargetVersionMinor = targetVersionMinor.c_str(); @@ -243,20 +220,17 @@ cmNinjaNormalTargetGenerator vars.Manifests = "$MANIFESTS"; std::string langFlags; - if (targetType != cmState::EXECUTABLE) - { + if (targetType != cmState::EXECUTABLE) { langFlags += "$LANGUAGE_COMPILE_FLAGS $ARCH_FLAGS"; vars.LanguageCompileFlags = langFlags.c_str(); - } + } // Rule for linking library/executable. std::vector<std::string> linkCmds = this->ComputeLinkCmd(); - for(std::vector<std::string>::iterator i = linkCmds.begin(); - i != linkCmds.end(); - ++i) - { + for (std::vector<std::string>::iterator i = linkCmds.begin(); + i != linkCmds.end(); ++i) { this->GetLocalGenerator()->ExpandRuleVariables(*i, vars); - } + } linkCmds.insert(linkCmds.begin(), "$PRE_LINK"); linkCmds.push_back("$POST_BUILD"); std::string linkCmd = @@ -269,93 +243,84 @@ cmNinjaNormalTargetGenerator std::ostringstream description; description << "Linking " << this->TargetLinkLanguage << " " << this->GetVisibleTypeName() << " $TARGET_FILE"; - this->GetGlobalGenerator()->AddRule(ruleName, - linkCmd, - description.str(), + this->GetGlobalGenerator()->AddRule(ruleName, linkCmd, description.str(), comment.str(), /*depfile*/ "", - /*deptype*/ "", - rspfile, - rspcontent, + /*deptype*/ "", rspfile, rspcontent, /*restat*/ "$RESTAT", /*generator*/ false); } if (this->TargetNameOut != this->TargetNameReal && - !this->GetGeneratorTarget()->IsFrameworkOnApple()) { + !this->GetGeneratorTarget()->IsFrameworkOnApple()) { std::string cmakeCommand = this->GetLocalGenerator()->ConvertToOutputFormat( cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL); if (targetType == cmState::EXECUTABLE) - this->GetGlobalGenerator()->AddRule("CMAKE_SYMLINK_EXECUTABLE", - cmakeCommand + - " -E cmake_symlink_executable" - " $in $out && $POST_BUILD", - "Creating executable symlink $out", - "Rule for creating " - "executable symlink.", - /*depfile*/ "", - /*deptype*/ "", - /*rspfile*/ "", - /*rspcontent*/ "", - /*restat*/ "", - /*generator*/ false); + this->GetGlobalGenerator()->AddRule( + "CMAKE_SYMLINK_EXECUTABLE", + cmakeCommand + " -E cmake_symlink_executable" + " $in $out && $POST_BUILD", + "Creating executable symlink $out", "Rule for creating " + "executable symlink.", + /*depfile*/ "", + /*deptype*/ "", + /*rspfile*/ "", + /*rspcontent*/ "", + /*restat*/ "", + /*generator*/ false); else - this->GetGlobalGenerator()->AddRule("CMAKE_SYMLINK_LIBRARY", - cmakeCommand + - " -E cmake_symlink_library" - " $in $SONAME $out && $POST_BUILD", - "Creating library symlink $out", - "Rule for creating " - "library symlink.", - /*depfile*/ "", - /*deptype*/ "", - /*rspfile*/ "", - /*rspcontent*/ "", - /*restat*/ "", - /*generator*/ false); + this->GetGlobalGenerator()->AddRule( + "CMAKE_SYMLINK_LIBRARY", + cmakeCommand + " -E cmake_symlink_library" + " $in $SONAME $out && $POST_BUILD", + "Creating library symlink $out", "Rule for creating " + "library symlink.", + /*depfile*/ "", + /*deptype*/ "", + /*rspfile*/ "", + /*rspcontent*/ "", + /*restat*/ "", + /*generator*/ false); } } -std::vector<std::string> -cmNinjaNormalTargetGenerator -::ComputeLinkCmd() +std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd() { std::vector<std::string> linkCmds; cmMakefile* mf = this->GetMakefile(); { - std::string linkCmdVar = this->GetGeneratorTarget() - ->GetCreateRuleVariable(this->TargetLinkLanguage, this->GetConfigName()); - const char *linkCmd = mf->GetDefinition(linkCmdVar); - if (linkCmd) - { - cmSystemTools::ExpandListArgument(linkCmd, linkCmds); - return linkCmds; + std::string linkCmdVar = this->GetGeneratorTarget()->GetCreateRuleVariable( + this->TargetLinkLanguage, this->GetConfigName()); + const char* linkCmd = mf->GetDefinition(linkCmdVar); + if (linkCmd) { + cmSystemTools::ExpandListArgument(linkCmd, linkCmds); + return linkCmds; } } switch (this->GetGeneratorTarget()->GetType()) { case cmState::STATIC_LIBRARY: { // We have archive link commands set. First, delete the existing archive. { - std::string cmakeCommand = - this->GetLocalGenerator()->ConvertToOutputFormat( - cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL); - linkCmds.push_back(cmakeCommand + " -E remove $TARGET_FILE"); + std::string cmakeCommand = + this->GetLocalGenerator()->ConvertToOutputFormat( + cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL); + linkCmds.push_back(cmakeCommand + " -E remove $TARGET_FILE"); } // TODO: Use ARCHIVE_APPEND for archives over a certain size. { - std::string linkCmdVar = "CMAKE_"; - linkCmdVar += this->TargetLinkLanguage; - linkCmdVar += "_ARCHIVE_CREATE"; - const char *linkCmd = mf->GetRequiredDefinition(linkCmdVar); - cmSystemTools::ExpandListArgument(linkCmd, linkCmds); + std::string linkCmdVar = "CMAKE_"; + linkCmdVar += this->TargetLinkLanguage; + linkCmdVar += "_ARCHIVE_CREATE"; + const char* linkCmd = mf->GetRequiredDefinition(linkCmdVar); + cmSystemTools::ExpandListArgument(linkCmd, linkCmds); } { - std::string linkCmdVar = "CMAKE_"; - linkCmdVar += this->TargetLinkLanguage; - linkCmdVar += "_ARCHIVE_FINISH"; - const char *linkCmd = mf->GetRequiredDefinition(linkCmdVar); - cmSystemTools::ExpandListArgument(linkCmd, linkCmds); + std::string linkCmdVar = "CMAKE_"; + linkCmdVar += this->TargetLinkLanguage; + linkCmdVar += "_ARCHIVE_FINISH"; + const char* linkCmd = mf->GetRequiredDefinition(linkCmdVar); + cmSystemTools::ExpandListArgument(linkCmd, linkCmds); } return linkCmds; } @@ -369,7 +334,6 @@ cmNinjaNormalTargetGenerator return std::vector<std::string>(); } - static int calculateCommandLineLengthLimit(int linkRuleLength) { static int const limits[] = { @@ -389,31 +353,27 @@ static int calculateCommandLineLengthLimit(int linkRuleLength) size_t const arrSz = cmArraySize(limits); int const sz = *std::min_element(limits, limits + arrSz); - if (sz == std::numeric_limits<int>::max()) - { + if (sz == std::numeric_limits<int>::max()) { return -1; - } + } return sz - linkRuleLength; } - void cmNinjaNormalTargetGenerator::WriteLinkStatement() { cmGeneratorTarget& gt = *this->GetGeneratorTarget(); const std::string cfgName = this->GetConfigName(); - std::string targetOutput = ConvertToNinjaPath( - gt.GetFullPath(cfgName)); - std::string targetOutputReal = ConvertToNinjaPath( - gt.GetFullPath(cfgName, + std::string targetOutput = ConvertToNinjaPath(gt.GetFullPath(cfgName)); + std::string targetOutputReal = + ConvertToNinjaPath(gt.GetFullPath(cfgName, /*implib=*/false, /*realpath=*/true)); - std::string targetOutputImplib = ConvertToNinjaPath( - gt.GetFullPath(cfgName, - /*implib=*/true)); + std::string targetOutputImplib = + ConvertToNinjaPath(gt.GetFullPath(cfgName, + /*implib=*/true)); - if (gt.IsAppBundleOnApple()) - { + if (gt.IsAppBundleOnApple()) { // Create the app bundle std::string outpath = gt.GetDirectory(cfgName); this->OSXBundleGenerator->CreateAppBundle(this->TargetNameOut, outpath); @@ -427,37 +387,30 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() targetOutputReal += "/"; targetOutputReal += this->TargetNameReal; targetOutputReal = this->ConvertToNinjaPath(targetOutputReal); - } - else if (gt.IsFrameworkOnApple()) - { + } else if (gt.IsFrameworkOnApple()) { // Create the library framework. this->OSXBundleGenerator->CreateFramework(this->TargetNameOut, gt.GetDirectory(cfgName)); - } - else if(gt.IsCFBundleOnApple()) - { + } else if (gt.IsCFBundleOnApple()) { // Create the core foundation bundle. this->OSXBundleGenerator->CreateCFBundle(this->TargetNameOut, gt.GetDirectory(cfgName)); - } + } // Write comments. cmGlobalNinjaGenerator::WriteDivider(this->GetBuildFileStream()); const cmState::TargetType targetType = gt.GetType(); - this->GetBuildFileStream() - << "# Link build statements for " - << cmState::GetTargetTypeName(targetType) - << " target " - << this->GetTargetName() - << "\n\n"; + this->GetBuildFileStream() << "# Link build statements for " + << cmState::GetTargetTypeName(targetType) + << " target " << this->GetTargetName() << "\n\n"; cmNinjaDeps emptyDeps; cmNinjaVars vars; // Compute the comment. std::ostringstream comment; - comment << - "Link the " << this->GetVisibleTypeName() << " " << targetOutputReal; + comment << "Link the " << this->GetVisibleTypeName() << " " + << targetOutputReal; // Compute outputs. cmNinjaDeps outputs; @@ -473,53 +426,43 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() std::string linkPath; cmGeneratorTarget& genTarget = *this->GetGeneratorTarget(); - std::string createRule = - genTarget.GetCreateRuleVariable(this->TargetLinkLanguage, - this->GetConfigName()); - bool useWatcomQuote = mf->IsOn(createRule+"_USE_WATCOM_QUOTE"); + std::string createRule = genTarget.GetCreateRuleVariable( + this->TargetLinkLanguage, this->GetConfigName()); + bool useWatcomQuote = mf->IsOn(createRule + "_USE_WATCOM_QUOTE"); cmLocalNinjaGenerator& localGen = *this->GetLocalGenerator(); vars["TARGET_FILE"] = localGen.ConvertToOutputFormat(targetOutputReal, cmLocalGenerator::SHELL); - localGen.GetTargetFlags(vars["LINK_LIBRARIES"], - vars["FLAGS"], - vars["LINK_FLAGS"], - frameworkPath, - linkPath, - &genTarget, - useWatcomQuote); - if(this->GetMakefile()->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS") - && gt.GetType() == cmState::SHARED_LIBRARY) - { - if(gt.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS")) - { - std::string name_of_def_file - = gt.GetSupportDirectory(); + localGen.GetTargetFlags(vars["LINK_LIBRARIES"], vars["FLAGS"], + vars["LINK_FLAGS"], frameworkPath, linkPath, + &genTarget, useWatcomQuote); + if (this->GetMakefile()->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS") && + gt.GetType() == cmState::SHARED_LIBRARY) { + if (gt.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS")) { + std::string name_of_def_file = gt.GetSupportDirectory(); name_of_def_file += "/" + gt.GetName(); name_of_def_file += ".def "; vars["LINK_FLAGS"] += " /DEF:"; - vars["LINK_FLAGS"] += this->GetLocalGenerator() - ->ConvertToOutputFormat(name_of_def_file.c_str(), - cmLocalGenerator::SHELL); - } + vars["LINK_FLAGS"] += this->GetLocalGenerator()->ConvertToOutputFormat( + name_of_def_file.c_str(), cmLocalGenerator::SHELL); } + } // Add OS X version flags, if any. - if(this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY || - this->GeneratorTarget->GetType() == cmState::MODULE_LIBRARY) - { + if (this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY || + this->GeneratorTarget->GetType() == cmState::MODULE_LIBRARY) { this->AppendOSXVerFlag(vars["LINK_FLAGS"], this->TargetLinkLanguage, "COMPATIBILITY", true); this->AppendOSXVerFlag(vars["LINK_FLAGS"], this->TargetLinkLanguage, "CURRENT", false); - } + } this->addPoolNinjaVariable("JOB_POOL_LINK", >, vars); this->AddModuleDefinitionFlag(vars["LINK_FLAGS"]); - vars["LINK_FLAGS"] = cmGlobalNinjaGenerator - ::EncodeLiteral(vars["LINK_FLAGS"]); + vars["LINK_FLAGS"] = + cmGlobalNinjaGenerator::EncodeLiteral(vars["LINK_FLAGS"]); vars["MANIFESTS"] = this->GetManifests(); @@ -528,56 +471,45 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() // Compute architecture specific link flags. Yes, these go into a different // variable for executables, probably due to a mistake made when duplicating // code between the Makefile executable and library generators. - if (targetType == cmState::EXECUTABLE) - { + if (targetType == cmState::EXECUTABLE) { std::string t = vars["FLAGS"]; localGen.AddArchitectureFlags(t, &genTarget, TargetLinkLanguage, cfgName); vars["FLAGS"] = t; - } - else - { + } else { std::string t = vars["ARCH_FLAGS"]; localGen.AddArchitectureFlags(t, &genTarget, TargetLinkLanguage, cfgName); vars["ARCH_FLAGS"] = t; t = ""; localGen.AddLanguageFlags(t, TargetLinkLanguage, cfgName); vars["LANGUAGE_COMPILE_FLAGS"] = t; - } + } - if (this->GetGeneratorTarget()->HasSOName(cfgName)) - { + if (this->GetGeneratorTarget()->HasSOName(cfgName)) { vars["SONAME_FLAG"] = mf->GetSONameFlag(this->TargetLinkLanguage); vars["SONAME"] = this->TargetNameSO; - if (targetType == cmState::SHARED_LIBRARY) - { + if (targetType == cmState::SHARED_LIBRARY) { std::string install_dir = - this->GetGeneratorTarget()->GetInstallNameDirForBuildTree(cfgName); - if (!install_dir.empty()) - { - vars["INSTALLNAME_DIR"] = localGen.Convert(install_dir, - cmLocalGenerator::NONE, - cmLocalGenerator::SHELL); - } + this->GetGeneratorTarget()->GetInstallNameDirForBuildTree(cfgName); + if (!install_dir.empty()) { + vars["INSTALLNAME_DIR"] = localGen.Convert( + install_dir, cmLocalGenerator::NONE, cmLocalGenerator::SHELL); } } + } cmNinjaDeps byproducts; - if (!this->TargetNameImport.empty()) - { + if (!this->TargetNameImport.empty()) { const std::string impLibPath = localGen.ConvertToOutputFormat( - targetOutputImplib, - cmLocalGenerator::SHELL); + targetOutputImplib, cmLocalGenerator::SHELL); vars["TARGET_IMPLIB"] = impLibPath; EnsureParentDirectoryExists(impLibPath); - if(genTarget.HasImportLibrary()) - { + if (genTarget.HasImportLibrary()) { byproducts.push_back(targetOutputImplib); - } } + } - if (!this->SetMsvcTargetPdbVariable(vars)) - { + if (!this->SetMsvcTargetPdbVariable(vars)) { // It is common to place debug symbols at a specific place, // so we need a plain target name in the rule available. std::string prefix; @@ -586,198 +518,155 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() this->GetGeneratorTarget()->GetFullNameComponents(prefix, base, suffix); std::string dbg_suffix = ".dbg"; // TODO: Where to document? - if (mf->GetDefinition("CMAKE_DEBUG_SYMBOL_SUFFIX")) - { + if (mf->GetDefinition("CMAKE_DEBUG_SYMBOL_SUFFIX")) { dbg_suffix = mf->GetDefinition("CMAKE_DEBUG_SYMBOL_SUFFIX"); - } - vars["TARGET_PDB"] = base + suffix + dbg_suffix; } + vars["TARGET_PDB"] = base + suffix + dbg_suffix; + } const std::string objPath = GetGeneratorTarget()->GetSupportDirectory(); - vars["OBJECT_DIR"] = - this->GetLocalGenerator()->ConvertToOutputFormat( - this->ConvertToNinjaPath(objPath), cmLocalGenerator::SHELL); + vars["OBJECT_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat( + this->ConvertToNinjaPath(objPath), cmLocalGenerator::SHELL); EnsureDirectoryExists(objPath); - if (this->GetGlobalGenerator()->IsGCCOnWindows()) - { + if (this->GetGlobalGenerator()->IsGCCOnWindows()) { // ar.exe can't handle backslashes in rsp files (implicitly used by gcc) std::string& linkLibraries = vars["LINK_LIBRARIES"]; std::replace(linkLibraries.begin(), linkLibraries.end(), '\\', '/'); std::string& link_path = vars["LINK_PATH"]; std::replace(link_path.begin(), link_path.end(), '\\', '/'); - } + } - const std::vector<cmCustomCommand> *cmdLists[3] = { - >.GetPreBuildCommands(), - >.GetPreLinkCommands(), + const std::vector<cmCustomCommand>* cmdLists[3] = { + >.GetPreBuildCommands(), >.GetPreLinkCommands(), >.GetPostBuildCommands() }; std::vector<std::string> preLinkCmdLines, postBuildCmdLines; - std::vector<std::string> *cmdLineLists[3] = { - &preLinkCmdLines, - &preLinkCmdLines, - &postBuildCmdLines - }; - - for (unsigned i = 0; i != 3; ++i) - { - for (std::vector<cmCustomCommand>::const_iterator - ci = cmdLists[i]->begin(); - ci != cmdLists[i]->end(); ++ci) - { + std::vector<std::string>* cmdLineLists[3] = { &preLinkCmdLines, + &preLinkCmdLines, + &postBuildCmdLines }; + + for (unsigned i = 0; i != 3; ++i) { + for (std::vector<cmCustomCommand>::const_iterator ci = + cmdLists[i]->begin(); + ci != cmdLists[i]->end(); ++ci) { cmCustomCommandGenerator ccg(*ci, cfgName, this->GetLocalGenerator()); localGen.AppendCustomCommandLines(ccg, *cmdLineLists[i]); std::vector<std::string> const& ccByproducts = ccg.GetByproducts(); std::transform(ccByproducts.begin(), ccByproducts.end(), std::back_inserter(byproducts), MapToNinjaPath()); - } } + } // maybe create .def file from list of objects if (gt.GetType() == cmState::SHARED_LIBRARY && - this->GetMakefile()->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS")) - { - if(gt.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS")) - { + this->GetMakefile()->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS")) { + if (gt.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS")) { std::string cmakeCommand = - this->GetLocalGenerator()->ConvertToOutputFormat( - cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL); - std::string name_of_def_file - = gt.GetSupportDirectory(); + this->GetLocalGenerator()->ConvertToOutputFormat( + cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL); + std::string name_of_def_file = gt.GetSupportDirectory(); name_of_def_file += "/" + gt.GetName(); name_of_def_file += ".def"; std::string cmd = cmakeCommand; cmd += " -E __create_def "; - cmd += this->GetLocalGenerator() - ->ConvertToOutputFormat(name_of_def_file.c_str(), - cmLocalGenerator::SHELL); + cmd += this->GetLocalGenerator()->ConvertToOutputFormat( + name_of_def_file.c_str(), cmLocalGenerator::SHELL); cmd += " "; cmNinjaDeps objs = this->GetObjects(); std::string obj_list_file = name_of_def_file; obj_list_file += ".objs"; - cmd += this->GetLocalGenerator() - ->ConvertToOutputFormat(obj_list_file.c_str(), - cmLocalGenerator::SHELL); + cmd += this->GetLocalGenerator()->ConvertToOutputFormat( + obj_list_file.c_str(), cmLocalGenerator::SHELL); preLinkCmdLines.push_back(cmd); // create a list of obj files for the -E __create_def to read cmGeneratedFileStream fout(obj_list_file.c_str()); - for(cmNinjaDeps::iterator i=objs.begin(); i != objs.end(); ++i) - { - if(cmHasLiteralSuffix(*i, ".obj")) - { + for (cmNinjaDeps::iterator i = objs.begin(); i != objs.end(); ++i) { + if (cmHasLiteralSuffix(*i, ".obj")) { fout << *i << "\n"; - } } } } + } // If we have any PRE_LINK commands, we need to go back to HOME_OUTPUT for // the link commands. - if (!preLinkCmdLines.empty()) - { + if (!preLinkCmdLines.empty()) { const std::string homeOutDir = localGen.ConvertToOutputFormat( - localGen.GetBinaryDirectory(), - cmLocalGenerator::SHELL); + localGen.GetBinaryDirectory(), cmLocalGenerator::SHELL); preLinkCmdLines.push_back("cd " + homeOutDir); - } + } vars["PRE_LINK"] = localGen.BuildCommandLine(preLinkCmdLines); std::string postBuildCmdLine = localGen.BuildCommandLine(postBuildCmdLines); cmNinjaVars symlinkVars; - if (targetOutput == targetOutputReal) - { + if (targetOutput == targetOutputReal) { vars["POST_BUILD"] = postBuildCmdLine; - } - else - { + } else { vars["POST_BUILD"] = ":"; symlinkVars["POST_BUILD"] = postBuildCmdLine; - } + } cmGlobalNinjaGenerator& globalGen = *this->GetGlobalGenerator(); int commandLineLengthLimit = -1; - if (!this->ForceResponseFile()) - { + if (!this->ForceResponseFile()) { commandLineLengthLimit = calculateCommandLineLengthLimit( - globalGen.GetRuleCmdLength(this->LanguageLinkerRule())); - } + globalGen.GetRuleCmdLength(this->LanguageLinkerRule())); + } const std::string rspfile = - std::string(cmake::GetCMakeFilesDirectoryPostSlash()) - + gt.GetName() + ".rsp"; + std::string(cmake::GetCMakeFilesDirectoryPostSlash()) + gt.GetName() + + ".rsp"; // Gather order-only dependencies. cmNinjaDeps orderOnlyDeps; this->GetLocalGenerator()->AppendTargetDepends(this->GetGeneratorTarget(), - orderOnlyDeps); + orderOnlyDeps); // Ninja should restat after linking if and only if there are byproducts. - vars["RESTAT"] = byproducts.empty()? "" : "1"; + vars["RESTAT"] = byproducts.empty() ? "" : "1"; for (cmNinjaDeps::const_iterator oi = byproducts.begin(), - oe = byproducts.end(); - oi != oe; ++oi) - { + oe = byproducts.end(); + oi != oe; ++oi) { this->GetGlobalGenerator()->SeenCustomCommandOutput(*oi); outputs.push_back(*oi); - } + } // Write the build statement for this target. bool usedResponseFile = false; - globalGen.WriteBuild(this->GetBuildFileStream(), - comment.str(), - this->LanguageLinkerRule(), - outputs, - explicitDeps, - implicitDeps, - orderOnlyDeps, - vars, - rspfile, - commandLineLengthLimit, - &usedResponseFile); + globalGen.WriteBuild(this->GetBuildFileStream(), comment.str(), + this->LanguageLinkerRule(), outputs, explicitDeps, + implicitDeps, orderOnlyDeps, vars, rspfile, + commandLineLengthLimit, &usedResponseFile); this->WriteLinkRule(usedResponseFile); - if (targetOutput != targetOutputReal && !gt.IsFrameworkOnApple()) - { - if (targetType == cmState::EXECUTABLE) - { - globalGen.WriteBuild(this->GetBuildFileStream(), - "Create executable symlink " + targetOutput, - "CMAKE_SYMLINK_EXECUTABLE", - cmNinjaDeps(1, targetOutput), - cmNinjaDeps(1, targetOutputReal), - emptyDeps, - emptyDeps, - symlinkVars); - } - else - { + if (targetOutput != targetOutputReal && !gt.IsFrameworkOnApple()) { + if (targetType == cmState::EXECUTABLE) { + globalGen.WriteBuild( + this->GetBuildFileStream(), + "Create executable symlink " + targetOutput, + "CMAKE_SYMLINK_EXECUTABLE", cmNinjaDeps(1, targetOutput), + cmNinjaDeps(1, targetOutputReal), emptyDeps, emptyDeps, symlinkVars); + } else { cmNinjaDeps symlinks; const std::string soName = this->GetTargetFilePath(this->TargetNameSO); // If one link has to be created. - if (targetOutputReal == soName || targetOutput == soName) - { + if (targetOutputReal == soName || targetOutput == soName) { symlinkVars["SONAME"] = soName; - } - else - { + } else { symlinkVars["SONAME"] = ""; symlinks.push_back(soName); - } - symlinks.push_back(targetOutput); - globalGen.WriteBuild(this->GetBuildFileStream(), - "Create library symlink " + targetOutput, - "CMAKE_SYMLINK_LIBRARY", - symlinks, - cmNinjaDeps(1, targetOutputReal), - emptyDeps, - emptyDeps, - symlinkVars); } + symlinks.push_back(targetOutput); + globalGen.WriteBuild( + this->GetBuildFileStream(), "Create library symlink " + targetOutput, + "CMAKE_SYMLINK_LIBRARY", symlinks, cmNinjaDeps(1, targetOutputReal), + emptyDeps, emptyDeps, symlinkVars); } + } // Add aliases for the file name and the target name. globalGen.AddTargetAlias(this->TargetNameOut, >); @@ -791,11 +680,9 @@ void cmNinjaNormalTargetGenerator::WriteObjectLibStatement() this->GetLocalGenerator()->AppendTargetOutputs(this->GetGeneratorTarget(), outputs); cmNinjaDeps depends = this->GetObjects(); - this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(), - "Object library " - + this->GetTargetName(), - outputs, - depends); + this->GetGlobalGenerator()->WritePhonyBuild( + this->GetBuildFileStream(), "Object library " + this->GetTargetName(), + outputs, depends); // Add aliases for the target name. this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(), |