diff options
Diffstat (limited to 'Source/cmNinjaNormalTargetGenerator.cxx')
-rw-r--r-- | Source/cmNinjaNormalTargetGenerator.cxx | 70 |
1 files changed, 47 insertions, 23 deletions
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 2bad32c..8b86a98 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -47,8 +47,7 @@ cmNinjaNormalTargetGenerator(cmTarget* target) { // on Windows the output dir is already needed at compile time // ensure the directory exists (OutDir test) - std::string outpath = target->GetDirectory(this->GetConfigName()); - cmSystemTools::MakeDirectory(outpath.c_str()); + EnsureDirectoryExists(target->GetDirectory(this->GetConfigName())); } } @@ -56,6 +55,21 @@ cmNinjaNormalTargetGenerator::~cmNinjaNormalTargetGenerator() { } +void +cmNinjaNormalTargetGenerator +::EnsureDirectoryExists(const std::string& dir) +{ + cmSystemTools::MakeDirectory(dir.c_str()); +} + +void +cmNinjaNormalTargetGenerator +::EnsureParentDirectoryExists(const std::string& path) +{ + EnsureDirectoryExists(cmSystemTools::GetParentDirectory(path.c_str())); +} + + void cmNinjaNormalTargetGenerator::Generate() { if (!this->TargetLinkLanguage) { @@ -152,6 +166,7 @@ cmNinjaNormalTargetGenerator cmLocalGenerator::SHELL); vars.ObjectDir = objdir.c_str(); vars.Target = "$out"; + vars.SONameFlag = "$SONAME_FLAG"; vars.TargetSOName = "$SONAME"; vars.TargetInstallNameDir = "$INSTALLNAME_DIR"; vars.TargetPDB = "$TARGET_PDB"; @@ -178,12 +193,13 @@ cmNinjaNormalTargetGenerator vars.LinkFlags = "$LINK_FLAGS"; std::string langFlags; - this->GetLocalGenerator()->AddLanguageFlags(langFlags, - this->TargetLinkLanguage, - this->GetConfigName()); - if (targetType != cmTarget::EXECUTABLE) + if (targetType != cmTarget::EXECUTABLE) { + this->GetLocalGenerator()->AddLanguageFlags(langFlags, + this->TargetLinkLanguage, + this->GetConfigName()); langFlags += " $ARCH_FLAGS"; - vars.LanguageCompileFlags = langFlags.c_str(); + vars.LanguageCompileFlags = langFlags.c_str(); + } // Rule for linking library. std::vector<std::string> linkCmds = this->ComputeLinkCmd(); @@ -366,27 +382,35 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() this->GetTarget(), this->TargetLinkLanguage, this->GetConfigName()); - vars["SONAME"] = this->TargetNameSO; - - if (targetType == cmTarget::SHARED_LIBRARY) { - std::string install_name_dir = - this->GetTarget()->GetInstallNameDirForBuildTree(this->GetConfigName()); - - if (!install_name_dir.empty()) { - vars["INSTALLNAME_DIR"] = - this->GetLocalGenerator()->Convert(install_name_dir.c_str(), - cmLocalGenerator::NONE, - cmLocalGenerator::SHELL, false); + if (this->GetTarget()->HasSOName(this->GetConfigName())) { + vars["SONAME_FLAG"] = + this->GetMakefile()->GetSONameFlag(this->TargetLinkLanguage); + vars["SONAME"] = this->TargetNameSO; + if (targetType == cmTarget::SHARED_LIBRARY) { + std::string install_name_dir = this->GetTarget() + ->GetInstallNameDirForBuildTree(this->GetConfigName()); + + if (!install_name_dir.empty()) { + vars["INSTALLNAME_DIR"] = + this->GetLocalGenerator()->Convert(install_name_dir.c_str(), + cmLocalGenerator::NONE, + cmLocalGenerator::SHELL, false); + } } } + std::string path; if (!this->TargetNameImport.empty()) { - vars["TARGET_IMPLIB"] = this->GetLocalGenerator()->ConvertToOutputFormat( - targetOutputImplib.c_str(), cmLocalGenerator::SHELL); + path = this->GetLocalGenerator()->ConvertToOutputFormat( + targetOutputImplib.c_str(), cmLocalGenerator::SHELL); + vars["TARGET_IMPLIB"] = path; + EnsureParentDirectoryExists(path); } - vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat( - this->GetTargetPDB().c_str(), cmLocalGenerator::SHELL); + path = this->GetLocalGenerator()->ConvertToOutputFormat( + this->GetTargetPDB().c_str(), cmLocalGenerator::SHELL); + vars["TARGET_PDB"] = path; + EnsureParentDirectoryExists(path); std::vector<cmCustomCommand> *cmdLists[3] = { &this->GetTarget()->GetPreBuildCommands(), @@ -413,7 +437,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() // If we have any PRE_LINK commands, we need to go back to HOME_OUTPUT for // the link commands. if (!preLinkCmdLines.empty()) { - std::string path = this->GetLocalGenerator()->ConvertToOutputFormat( + path = this->GetLocalGenerator()->ConvertToOutputFormat( this->GetMakefile()->GetHomeOutputDirectory(), cmLocalGenerator::SHELL); preLinkCmdLines.push_back("cd " + path); |