diff options
33 files changed, 1368 insertions, 1310 deletions
diff --git a/Help/release/dev/FindIce-imported-targets.rst b/Help/release/dev/FindIce-imported-targets.rst new file mode 100644 index 0000000..7e1b2f4 --- /dev/null +++ b/Help/release/dev/FindIce-imported-targets.rst @@ -0,0 +1,4 @@ +FindIce-imported-targets +------------------------ + +* The :module:`FindIce` module now provides imported targets. diff --git a/Modules/Compiler/AppleClang-CXX.cmake b/Modules/Compiler/AppleClang-CXX.cmake index 5194da4..1ba8a77 100644 --- a/Modules/Compiler/AppleClang-CXX.cmake +++ b/Modules/Compiler/AppleClang-CXX.cmake @@ -13,7 +13,10 @@ if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.0) set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++11") endif() -if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1) +if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.1) + set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++14") + set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++14") +elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1) # AppleClang 5.0 knows this flag, but does not set a __cplusplus macro greater than 201103L set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++1y") set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++1y") diff --git a/Modules/FindIce.cmake b/Modules/FindIce.cmake index c88c1b8..3fa6cab 100644 --- a/Modules/FindIce.cmake +++ b/Modules/FindIce.cmake @@ -20,6 +20,13 @@ # Ice_SLICE_DIRS - the directories containing the Ice slice interface # definitions # +# Imported targets:: +# +# Ice::<C> +# +# Where ``<C>`` is the name of an Ice component, for example +# ``Ice::Glacier2``. +# # Ice slice programs are reported in:: # # Ice_SLICE2CPP_EXECUTABLE - path to slice2cpp executable @@ -433,13 +440,21 @@ if(Ice_FOUND) set(_Ice_component_cache "Ice_${_Ice_component_upcase}_LIBRARY") set(_Ice_component_lib "Ice_${_Ice_component_upcase}_LIBRARIES") set(_Ice_component_found "${_Ice_component_upcase}_FOUND") + set(_Ice_imported_target "Ice::${_Ice_component}") if(${_Ice_component_found}) set("${_Ice_component_lib}" "${${_Ice_component_cache}}") + if(NOT TARGET ${_Ice_imported_target}) + add_library(${_Ice_imported_target} UNKNOWN IMPORTED) + set_target_properties(${_Ice_imported_target} PROPERTIES + IMPORTED_LOCATION "${${_Ice_component_cache}}" + INTERFACE_INCLUDE_DIRECTORIES "${Ice_INCLUDE_DIR}") + endif() endif() unset(_Ice_component_upcase) unset(_Ice_component_cache) unset(_Ice_component_lib) unset(_Ice_component_found) + unset(_Ice_imported_target) endforeach() endif() diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 6940187..d5fe7d1 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -165,6 +165,8 @@ set(SRCS cmCommandArgumentLexer.cxx cmCommandArgumentParser.cxx cmCommandArgumentParserHelper.cxx + cmCommonTargetGenerator.cxx + cmCommonTargetGenerator.h cmComputeComponentGraph.cxx cmComputeComponentGraph.h cmComputeLinkDepends.cxx @@ -260,6 +262,8 @@ set(SRCS cmGeneratorExpression.h cmGeneratorTarget.cxx cmGeneratorTarget.h + cmGlobalCommonGenerator.cxx + cmGlobalCommonGenerator.h cmGlobalGenerator.cxx cmGlobalGenerator.h cmGlobalGeneratorFactory.h @@ -285,6 +289,8 @@ set(SRCS cmListFileCache.cxx cmListFileCache.h cmListFileLexer.c + cmLocalCommonGenerator.cxx + cmLocalCommonGenerator.h cmLocalGenerator.cxx cmLocalGenerator.h cmLocalUnixMakefileGenerator3.cxx diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index eadcb9e..c79f13a 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 3) -set(CMake_VERSION_PATCH 20150709) +set(CMake_VERSION_PATCH 20150710) #set(CMake_VERSION_RC 1) diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx new file mode 100644 index 0000000..ce351ee --- /dev/null +++ b/Source/cmCommonTargetGenerator.cxx @@ -0,0 +1,360 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2015 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#include "cmCommonTargetGenerator.h" + +#include "cmComputeLinkInformation.h" +#include "cmGeneratorTarget.h" +#include "cmGlobalCommonGenerator.h" +#include "cmLocalCommonGenerator.h" +#include "cmMakefile.h" +#include "cmSourceFile.h" +#include "cmSystemTools.h" +#include "cmTarget.h" + +cmCommonTargetGenerator::cmCommonTargetGenerator(cmGeneratorTarget* gt) + : GeneratorTarget(gt) + , Target(gt->Target) + , Makefile(gt->Makefile) + , LocalGenerator(static_cast<cmLocalCommonGenerator*>(gt->LocalGenerator)) + , GlobalGenerator(static_cast<cmGlobalCommonGenerator*>( + gt->LocalGenerator->GetGlobalGenerator())) + , ConfigName(LocalGenerator->GetConfigName()) + , ModuleDefinitionFile(GeneratorTarget->GetModuleDefinitionFile(ConfigName)) + , FortranModuleDirectoryComputed(false) +{ +} + +cmCommonTargetGenerator::~cmCommonTargetGenerator() +{ +} + +std::string const& cmCommonTargetGenerator::GetConfigName() const +{ + return this->ConfigName; +} + +std::string cmCommonTargetGenerator::Convert( + std::string const& source, + cmLocalGenerator::RelativeRoot relative, + cmLocalGenerator::OutputFormat output) +{ + return this->LocalGenerator->Convert(source, relative, output); +} + +//---------------------------------------------------------------------------- +const char* cmCommonTargetGenerator::GetFeature(const std::string& feature) +{ + return this->GeneratorTarget->GetFeature(feature, this->ConfigName); +} + +//---------------------------------------------------------------------------- +bool cmCommonTargetGenerator::GetFeatureAsBool(const std::string& feature) +{ + return this->GeneratorTarget->GetFeatureAsBool(feature, this->ConfigName); +} + +//---------------------------------------------------------------------------- +void cmCommonTargetGenerator::AddFeatureFlags( + std::string& flags, const std::string& lang + ) +{ + // Add language-specific flags. + this->LocalGenerator->AddLanguageFlags(flags, lang, this->ConfigName); + + if(this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION")) + { + this->LocalGenerator->AppendFeatureOptions(flags, lang, "IPO"); + } +} + +//---------------------------------------------------------------------------- +void cmCommonTargetGenerator::AddModuleDefinitionFlag(std::string& flags) +{ + if(this->ModuleDefinitionFile.empty()) + { + return; + } + + // TODO: Create a per-language flag variable. + const char* defFileFlag = + this->Makefile->GetDefinition("CMAKE_LINK_DEF_FILE_FLAG"); + if(!defFileFlag) + { + return; + } + + // Append the flag and value. Use ConvertToLinkReference to help + // vs6's "cl -link" pass it to the linker. + std::string flag = defFileFlag; + flag += (this->LocalGenerator->ConvertToLinkReference( + this->ModuleDefinitionFile)); + this->LocalGenerator->AppendFlags(flags, flag); +} + +//---------------------------------------------------------------------------- +const char* cmCommonTargetGenerator::GetFortranModuleDirectory() +{ + // Compute the module directory. + if(!this->FortranModuleDirectoryComputed) + { + const char* target_mod_dir = + this->Target->GetProperty("Fortran_MODULE_DIRECTORY"); + const char* moddir_flag = + this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_FLAG"); + if(target_mod_dir && moddir_flag) + { + // Compute the full path to the module directory. + if(cmSystemTools::FileIsFullPath(target_mod_dir)) + { + // Already a full path. + this->FortranModuleDirectory = target_mod_dir; + } + else + { + // Interpret relative to the current output directory. + this->FortranModuleDirectory = + this->Makefile->GetCurrentBinaryDirectory(); + this->FortranModuleDirectory += "/"; + this->FortranModuleDirectory += target_mod_dir; + } + + // Make sure the module output directory exists. + cmSystemTools::MakeDirectory(this->FortranModuleDirectory.c_str()); + } + this->FortranModuleDirectoryComputed = true; + } + + // Return the computed directory. + if(this->FortranModuleDirectory.empty()) + { + return 0; + } + else + { + return this->FortranModuleDirectory.c_str(); + } +} + +//---------------------------------------------------------------------------- +void cmCommonTargetGenerator::AddFortranFlags(std::string& flags) +{ + // Enable module output if necessary. + if(const char* modout_flag = + this->Makefile->GetDefinition("CMAKE_Fortran_MODOUT_FLAG")) + { + this->LocalGenerator->AppendFlags(flags, modout_flag); + } + + // Add a module output directory flag if necessary. + const char* mod_dir = this->GetFortranModuleDirectory(); + if(!mod_dir) + { + mod_dir = this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_DEFAULT"); + } + if(mod_dir) + { + const char* moddir_flag = + this->Makefile->GetRequiredDefinition("CMAKE_Fortran_MODDIR_FLAG"); + std::string modflag = moddir_flag; + modflag += this->Convert(mod_dir, + cmLocalGenerator::START_OUTPUT, + cmLocalGenerator::SHELL); + this->LocalGenerator->AppendFlags(flags, modflag); + } + + // If there is a separate module path flag then duplicate the + // include path with it. This compiler does not search the include + // path for modules. + if(const char* modpath_flag = + this->Makefile->GetDefinition("CMAKE_Fortran_MODPATH_FLAG")) + { + std::vector<std::string> includes; + const std::string& config = + this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); + this->LocalGenerator->GetIncludeDirectories(includes, + this->GeneratorTarget, + "C", config); + for(std::vector<std::string>::const_iterator idi = includes.begin(); + idi != includes.end(); ++idi) + { + std::string flg = modpath_flag; + flg += this->Convert(*idi, + cmLocalGenerator::NONE, + cmLocalGenerator::SHELL); + this->LocalGenerator->AppendFlags(flags, flg); + } + } +} + +//---------------------------------------------------------------------------- +void +cmCommonTargetGenerator +::AppendFortranFormatFlags(std::string& flags, cmSourceFile const& source) +{ + const char* srcfmt = source.GetProperty("Fortran_FORMAT"); + cmLocalGenerator::FortranFormat format = + this->LocalGenerator->GetFortranFormat(srcfmt); + if(format == cmLocalGenerator::FortranFormatNone) + { + const char* tgtfmt = this->Target->GetProperty("Fortran_FORMAT"); + format = this->LocalGenerator->GetFortranFormat(tgtfmt); + } + const char* var = 0; + switch (format) + { + case cmLocalGenerator::FortranFormatFixed: + var = "CMAKE_Fortran_FORMAT_FIXED_FLAG"; break; + case cmLocalGenerator::FortranFormatFree: + var = "CMAKE_Fortran_FORMAT_FREE_FLAG"; break; + default: break; + } + if(var) + { + this->LocalGenerator->AppendFlags( + flags, this->Makefile->GetDefinition(var)); + } +} + +//---------------------------------------------------------------------------- +std::string cmCommonTargetGenerator::GetFrameworkFlags(std::string const& l) +{ + if(!this->Makefile->IsOn("APPLE")) + { + return std::string(); + } + + std::string fwSearchFlagVar = "CMAKE_" + l + "_FRAMEWORK_SEARCH_FLAG"; + const char* fwSearchFlag = + this->Makefile->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; + + const std::string& config = + this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); + this->LocalGenerator->GetIncludeDirectories(includes, + this->GeneratorTarget, + "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(this->Target->NameResolvesToFramework(*i)) + { + std::string frameworkDir = *i; + frameworkDir += "/../"; + frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir); + emitted.insert(frameworkDir); + } + } + + std::string flags; + const char* cfg = this->LocalGenerator->GetConfigName().c_str(); + if(cmComputeLinkInformation* cli = this->Target->GetLinkInformation(cfg)) + { + 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 += this->LocalGenerator + ->ConvertToOutputFormat(*i, cmLocalGenerator::SHELL); + flags += " "; + } + } + } + return flags; +} + +//---------------------------------------------------------------------------- +std::string cmCommonTargetGenerator::GetFlags(const std::string &l) +{ + ByLanguageMap::iterator i = this->FlagsByLanguage.find(l); + if (i == this->FlagsByLanguage.end()) + { + std::string flags; + const char *lang = l.c_str(); + + // Add language feature flags. + this->AddFeatureFlags(flags, lang); + + this->LocalGenerator->AddArchitectureFlags(flags, this->GeneratorTarget, + lang, this->ConfigName); + + // Fortran-specific flags computed for this target. + if(l == "Fortran") + { + this->AddFortranFlags(flags); + } + + this->LocalGenerator->AddCMP0018Flags(flags, this->Target, + lang, this->ConfigName); + + this->LocalGenerator->AddVisibilityPresetFlags(flags, this->Target, + lang); + + // Add include directory flags. + this->AddIncludeFlags(flags, lang); + + // Append old-style preprocessor definition flags. + this->LocalGenerator-> + AppendFlags(flags, this->Makefile->GetDefineFlags()); + + // Add framework directory flags. + this->LocalGenerator-> + AppendFlags(flags,this->GetFrameworkFlags(l)); + + // Add target-specific flags. + this->LocalGenerator->AddCompileOptions(flags, this->Target, + lang, this->ConfigName); + + ByLanguageMap::value_type entry(l, flags); + i = this->FlagsByLanguage.insert(entry).first; + } + return i->second; +} + +std::string cmCommonTargetGenerator::GetDefines(const std::string &l) +{ + ByLanguageMap::iterator i = this->DefinesByLanguage.find(l); + if (i == this->DefinesByLanguage.end()) + { + std::set<std::string> defines; + const char *lang = l.c_str(); + // Add the export symbol definition for shared library objects. + if(const char* exportMacro = this->Target->GetExportMacro()) + { + this->LocalGenerator->AppendDefines(defines, exportMacro); + } + + // Add preprocessor definitions for this target and configuration. + this->LocalGenerator->AddCompileDefinitions(defines, this->Target, + this->LocalGenerator->GetConfigName(), l); + + std::string definesString; + this->LocalGenerator->JoinDefines(defines, definesString, lang); + + ByLanguageMap::value_type entry(l, definesString); + i = this->DefinesByLanguage.insert(entry).first; + } + return i->second; +} diff --git a/Source/cmCommonTargetGenerator.h b/Source/cmCommonTargetGenerator.h new file mode 100644 index 0000000..e184dba --- /dev/null +++ b/Source/cmCommonTargetGenerator.h @@ -0,0 +1,88 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2015 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#ifndef cmCommonTargetGenerator_h +#define cmCommonTargetGenerator_h + +#include "cmStandardIncludes.h" + +#include "cmLocalGenerator.h" + +class cmGeneratorTarget; +class cmGlobalCommonGenerator; +class cmLocalCommonGenerator; +class cmMakefile; +class cmSourceFile; +class cmTarget; + +/** \class cmCommonTargetGenerator + * \brief Common infrastructure for Makefile and Ninja per-target generators + */ +class cmCommonTargetGenerator +{ +public: + cmCommonTargetGenerator(cmGeneratorTarget* gt); + virtual ~cmCommonTargetGenerator(); + + std::string const& GetConfigName() const; + +protected: + + // Add language feature flags. + void AddFeatureFlags(std::string& flags, const std::string& lang); + + // Feature query methods. + const char* GetFeature(const std::string& feature); + bool GetFeatureAsBool(const std::string& feature); + + // Helper to add flag for windows .def file. + void AddModuleDefinitionFlag(std::string& flags); + + cmGeneratorTarget* GeneratorTarget; + cmTarget* Target; + cmMakefile* Makefile; + cmLocalCommonGenerator* LocalGenerator; + cmGlobalCommonGenerator* GlobalGenerator; + std::string ConfigName; + + // The windows module definition source file (.def), if any. + std::string ModuleDefinitionFile; + + // Target-wide Fortran module output directory. + bool FortranModuleDirectoryComputed; + std::string FortranModuleDirectory; + const char* GetFortranModuleDirectory(); + + // Compute target-specific Fortran language flags. + void AddFortranFlags(std::string& flags); + + std::string Convert(std::string const& source, + cmLocalGenerator::RelativeRoot relative, + cmLocalGenerator::OutputFormat output = + cmLocalGenerator::UNCHANGED); + + void AppendFortranFormatFlags(std::string& flags, + cmSourceFile const& source); + + // Return the a string with -F flags on apple + std::string GetFrameworkFlags(std::string const& l); + + virtual void AddIncludeFlags(std::string& flags, + std::string const& lang) = 0; + + typedef std::map<std::string, std::string> ByLanguageMap; + std::string GetFlags(const std::string &l); + ByLanguageMap FlagsByLanguage; + std::string GetDefines(const std::string &l); + ByLanguageMap DefinesByLanguage; +}; + +#endif diff --git a/Source/cmGlobalCommonGenerator.cxx b/Source/cmGlobalCommonGenerator.cxx new file mode 100644 index 0000000..dc8e5a7 --- /dev/null +++ b/Source/cmGlobalCommonGenerator.cxx @@ -0,0 +1,21 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2015 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#include "cmGlobalCommonGenerator.h" + +cmGlobalCommonGenerator::cmGlobalCommonGenerator(cmake* cm): + cmGlobalGenerator(cm) +{ +} + +cmGlobalCommonGenerator::~cmGlobalCommonGenerator() +{ +} diff --git a/Source/cmGlobalCommonGenerator.h b/Source/cmGlobalCommonGenerator.h new file mode 100644 index 0000000..7bb0e55 --- /dev/null +++ b/Source/cmGlobalCommonGenerator.h @@ -0,0 +1,27 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2015 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#ifndef cmGlobalCommonGenerator_h +#define cmGlobalCommonGenerator_h + +#include "cmGlobalGenerator.h" + +/** \class cmGlobalCommonGenerator + * \brief Common infrastructure for Makefile and Ninja global generators. + */ +class cmGlobalCommonGenerator : public cmGlobalGenerator +{ +public: + cmGlobalCommonGenerator(cmake* cm); + ~cmGlobalCommonGenerator(); +}; + +#endif diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 722294b..b88b8c8 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -505,7 +505,7 @@ void cmGlobalNinjaGenerator::WriteDefault(std::ostream& os, cmGlobalNinjaGenerator::cmGlobalNinjaGenerator(cmake* cm) - : cmGlobalGenerator(cm) + : cmGlobalCommonGenerator(cm) , BuildFileStream(0) , RulesFileStream(0) , CompileCommandsStream(0) diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index ffd1cdc..2a749c1 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -13,7 +13,7 @@ #ifndef cmGlobalNinjaGenerator_h # define cmGlobalNinjaGenerator_h -# include "cmGlobalGenerator.h" +# include "cmGlobalCommonGenerator.h" # include "cmGlobalGeneratorFactory.h" # include "cmNinjaTypes.h" @@ -42,7 +42,7 @@ class cmGeneratorTarget; * - We extensively use Ninja variable overloading system to minimize the * number of generated rules. */ -class cmGlobalNinjaGenerator : public cmGlobalGenerator +class cmGlobalNinjaGenerator : public cmGlobalCommonGenerator { public: /// The default name of Ninja's build file. Typically: build.ninja. diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index e6a67d3..c5fca91 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -21,7 +21,7 @@ #include "cmAlgorithms.h" cmGlobalUnixMakefileGenerator3::cmGlobalUnixMakefileGenerator3(cmake* cm) - : cmGlobalGenerator(cm) + : cmGlobalCommonGenerator(cm) { // This type of makefile always requires unix style paths this->ForceUnixPaths = true; @@ -483,7 +483,7 @@ cmGlobalUnixMakefileGenerator3 if((!check_all || !gtarget->GetPropertyAsBool("EXCLUDE_FROM_ALL")) && (!check_relink || gtarget->Target - ->NeedRelinkBeforeInstall(lg->ConfigurationName))) + ->NeedRelinkBeforeInstall(lg->GetConfigName()))) { std::string tname = lg->GetRelativeTargetDirectory(*gtarget->Target); tname += "/"; @@ -692,7 +692,7 @@ cmGlobalUnixMakefileGenerator3 // Add a local name for the rule to relink the target before // installation. if(gtarget->Target - ->NeedRelinkBeforeInstall(lg->ConfigurationName)) + ->NeedRelinkBeforeInstall(lg->GetConfigName())) { makeTargetName = lg->GetRelativeTargetDirectory(*gtarget->Target); makeTargetName += "/preinstall"; @@ -865,7 +865,7 @@ cmGlobalUnixMakefileGenerator3 // Add rules to prepare the target for installation. if(gtarget->Target - ->NeedRelinkBeforeInstall(lg->ConfigurationName)) + ->NeedRelinkBeforeInstall(lg->GetConfigName())) { localName = lg->GetRelativeTargetDirectory(*gtarget->Target); localName += "/preinstall"; diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h index 14adf2e..fc53fa8 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.h +++ b/Source/cmGlobalUnixMakefileGenerator3.h @@ -12,7 +12,7 @@ #ifndef cmGlobalUnixMakefileGenerator3_h #define cmGlobalUnixMakefileGenerator3_h -#include "cmGlobalGenerator.h" +#include "cmGlobalCommonGenerator.h" #include "cmGlobalGeneratorFactory.h" class cmGeneratedFileStream; @@ -51,7 +51,7 @@ class cmLocalUnixMakefileGenerator3; */ -class cmGlobalUnixMakefileGenerator3 : public cmGlobalGenerator +class cmGlobalUnixMakefileGenerator3 : public cmGlobalCommonGenerator { public: cmGlobalUnixMakefileGenerator3(cmake* cm); diff --git a/Source/cmLocalCommonGenerator.cxx b/Source/cmLocalCommonGenerator.cxx new file mode 100644 index 0000000..4583446 --- /dev/null +++ b/Source/cmLocalCommonGenerator.cxx @@ -0,0 +1,40 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2015 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#include "cmLocalCommonGenerator.h" + +#include "cmMakefile.h" + +cmLocalCommonGenerator::cmLocalCommonGenerator(cmGlobalGenerator* gg, + cmLocalGenerator* parent, + cmState::Snapshot snapshot): + cmLocalGenerator(gg, parent, snapshot) +{ +} + +cmLocalCommonGenerator::~cmLocalCommonGenerator() +{ +} + +void cmLocalCommonGenerator::SetConfigName() +{ + // Store the configuration name that will be generated. + if(const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE")) + { + // Use the build type given by the user. + this->ConfigName = config; + } + else + { + // No configuration type given. + this->ConfigName = ""; + } +} diff --git a/Source/cmLocalCommonGenerator.h b/Source/cmLocalCommonGenerator.h new file mode 100644 index 0000000..af94cda --- /dev/null +++ b/Source/cmLocalCommonGenerator.h @@ -0,0 +1,39 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2015 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#ifndef cmLocalCommonGenerator_h +#define cmLocalCommonGenerator_h + +#include "cmLocalGenerator.h" + +class cmCommonTargetGenerator; + +/** \class cmLocalCommonGenerator + * \brief Common infrastructure for Makefile and Ninja local generators. + */ +class cmLocalCommonGenerator: public cmLocalGenerator +{ +public: + cmLocalCommonGenerator(cmGlobalGenerator* gg, + cmLocalGenerator* parent, + cmState::Snapshot snapshot); + ~cmLocalCommonGenerator(); + + std::string const& GetConfigName() { return this->ConfigName; } + +protected: + void SetConfigName(); + std::string ConfigName; + + friend class cmCommonTargetGenerator; +}; + +#endif diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 6f98ee2..e170253 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -32,8 +32,6 @@ # include <cmsys/MD5.h> #endif -#include <cmsys/System.h> - #include <ctype.h> // for isalpha #include <assert.h> diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 4db36fc..a293d06 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -25,8 +25,7 @@ cmLocalNinjaGenerator::cmLocalNinjaGenerator(cmGlobalGenerator* gg, cmLocalGenerator* parent, cmState::Snapshot snapshot) - : cmLocalGenerator(gg, parent, snapshot) - , ConfigName("") + : cmLocalCommonGenerator(gg, parent, snapshot) , HomeRelativeOutputPath("") { this->TargetImplib = "$TARGET_IMPLIB"; @@ -261,22 +260,6 @@ void cmLocalNinjaGenerator::WriteNinjaFilesInclusion(std::ostream& os) os << "\n"; } -void cmLocalNinjaGenerator::SetConfigName() -{ - // Store the configuration name that will be generated. - if(const char* config = - this->GetMakefile()->GetDefinition("CMAKE_BUILD_TYPE")) - { - // Use the build type given by the user. - this->ConfigName = config; - } - else - { - // No configuration type given. - this->ConfigName = ""; - } -} - //---------------------------------------------------------------------------- void cmLocalNinjaGenerator::ComputeObjectFilenames( std::map<cmSourceFile const*, std::string>& mapping, diff --git a/Source/cmLocalNinjaGenerator.h b/Source/cmLocalNinjaGenerator.h index ce966ff..d10be0c 100644 --- a/Source/cmLocalNinjaGenerator.h +++ b/Source/cmLocalNinjaGenerator.h @@ -13,7 +13,7 @@ #ifndef cmLocalNinjaGenerator_h # define cmLocalNinjaGenerator_h -# include "cmLocalGenerator.h" +# include "cmLocalCommonGenerator.h" # include "cmNinjaTypes.h" class cmCustomCommandGenerator; @@ -28,7 +28,7 @@ class cmake; * cmLocalNinjaGenerator produces a local build.ninja file from its * member Makefile. */ -class cmLocalNinjaGenerator : public cmLocalGenerator +class cmLocalNinjaGenerator : public cmLocalCommonGenerator { public: cmLocalNinjaGenerator(cmGlobalGenerator* gg, cmLocalGenerator* parent, @@ -46,9 +46,6 @@ public: const cmake* GetCMakeInstance() const; cmake* GetCMakeInstance(); - std::string const& GetConfigName() const - { return this->ConfigName; } - /// @returns the relative path between the HomeOutputDirectory and this /// local generators StartOutputDirectory. std::string GetHomeRelativeOutputPath() const @@ -110,8 +107,6 @@ private: void WriteProcessedMakefile(std::ostream& os); void WritePools(std::ostream& os); - void SetConfigName(); - void WriteCustomCommandRule(); void WriteCustomCommandBuildStatement(cmCustomCommand const *cc, const cmNinjaDeps& orderOnlyDeps); @@ -120,7 +115,6 @@ private: std::string MakeCustomLauncher(cmCustomCommandGenerator const& ccg); - std::string ConfigName; std::string HomeRelativeOutputPath; typedef std::map<cmCustomCommand const*, std::set<cmTarget*> > diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index e292ba7..5d17a40 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -82,7 +82,7 @@ static std::string cmSplitExtension(std::string const& in, std::string& base) cmLocalUnixMakefileGenerator3:: cmLocalUnixMakefileGenerator3(cmGlobalGenerator* gg, cmLocalGenerator* parent, cmState::Snapshot snapshot) - : cmLocalGenerator(gg, parent, snapshot) + : cmLocalCommonGenerator(gg, parent, snapshot) { this->MakefileVariableSize = 0; this->ColorMakefile = false; @@ -100,17 +100,7 @@ cmLocalUnixMakefileGenerator3::~cmLocalUnixMakefileGenerator3() //---------------------------------------------------------------------------- void cmLocalUnixMakefileGenerator3::Generate() { - // Store the configuration name that will be generated. - if(const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE")) - { - // Use the build type given by the user. - this->ConfigurationName = config; - } - else - { - // No configuration type given. - this->ConfigurationName = ""; - } + this->SetConfigName(); // Record whether some options are enabled to avoid checking many // times later. @@ -497,7 +487,7 @@ void cmLocalUnixMakefileGenerator3 // Add a local name for the rule to relink the target before // installation. if(t->second->Target - ->NeedRelinkBeforeInstall(this->ConfigurationName)) + ->NeedRelinkBeforeInstall(this->ConfigName)) { makeTargetName = this->GetRelativeTargetDirectory(*t->second->Target); makeTargetName += "/preinstall"; @@ -1017,7 +1007,7 @@ cmLocalUnixMakefileGenerator3 for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin(); i != ccs.end(); ++i) { - cmCustomCommandGenerator ccg(*i, this->ConfigurationName, + cmCustomCommandGenerator ccg(*i, this->ConfigName, this->Makefile); this->AppendCustomDepend(depends, ccg); } @@ -1034,7 +1024,7 @@ cmLocalUnixMakefileGenerator3 { // Lookup the real name of the dependency in case it is a CMake target. std::string dep; - if(this->GetRealDependency(*d, this->ConfigurationName, + if(this->GetRealDependency(*d, this->ConfigName, dep)) { depends.push_back(dep); @@ -1053,7 +1043,7 @@ cmLocalUnixMakefileGenerator3 for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin(); i != ccs.end(); ++i) { - cmCustomCommandGenerator ccg(*i, this->ConfigurationName, + cmCustomCommandGenerator ccg(*i, this->ConfigName, this->Makefile); this->AppendCustomCommand(commands, ccg, target, true, relative); } @@ -2043,7 +2033,7 @@ void cmLocalUnixMakefileGenerator3 // Build a list of preprocessor definitions for the target. std::set<std::string> defines; this->AddCompileDefinitions(defines, &target, - this->ConfigurationName, l->first); + this->ConfigName, l->first); if(!defines.empty()) { cmakefileStream diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h index b097c95..01ac01b 100644 --- a/Source/cmLocalUnixMakefileGenerator3.h +++ b/Source/cmLocalUnixMakefileGenerator3.h @@ -12,7 +12,7 @@ #ifndef cmLocalUnixMakefileGenerator3_h #define cmLocalUnixMakefileGenerator3_h -#include "cmLocalGenerator.h" +#include "cmLocalCommonGenerator.h" // for cmDepends::DependencyVector #include "cmDepends.h" @@ -31,7 +31,7 @@ class cmSourceFile; * cmLocalUnixMakefileGenerator3 produces a LocalUnix makefile from its * member Makefile. */ -class cmLocalUnixMakefileGenerator3 : public cmLocalGenerator +class cmLocalUnixMakefileGenerator3 : public cmLocalCommonGenerator { public: cmLocalUnixMakefileGenerator3(cmGlobalGenerator* gg, @@ -46,7 +46,6 @@ public: */ virtual void Generate(); - // this returns the relative path between the HomeOutputDirectory and this // local generators StartOutputDirectory const std::string &GetHomeRelativeOutputPath(); @@ -253,8 +252,6 @@ private: ImplicitDependTargetMap ImplicitDepends; - std::string ConfigurationName; - std::string HomeRelativeOutputPath; struct LocalObjectEntry diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index a0e9e4d..0e5e7a5 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -23,8 +23,6 @@ #include "cmComputeLinkInformation.h" #include "cmGeneratedFileStream.h" -#include <cmsys/System.h> - #include <ctype.h> // for isspace static bool cmLVS6G_IsFAT(const char* dir); diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 09fad5c..ef4bbbe 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -33,23 +33,19 @@ #include <ctype.h> cmMakefileTargetGenerator::cmMakefileTargetGenerator(cmGeneratorTarget* target) - : OSXBundleGenerator(0) + : cmCommonTargetGenerator(target) + , OSXBundleGenerator(0) , MacOSXContentGenerator(0) { this->BuildFileStream = 0; this->InfoFileStream = 0; this->FlagFileStream = 0; this->CustomCommandDriver = OnBuild; - this->FortranModuleDirectoryComputed = false; - this->Target = target->Target; - this->Makefile = this->Target->GetMakefile(); this->LocalGenerator = static_cast<cmLocalUnixMakefileGenerator3*>(target->GetLocalGenerator()); - this->ConfigName = this->LocalGenerator->ConfigurationName.c_str(); this->GlobalGenerator = static_cast<cmGlobalUnixMakefileGenerator3*>( this->LocalGenerator->GetGlobalGenerator()); - this->GeneratorTarget = target; cmake* cm = this->GlobalGenerator->GetCMakeInstance(); this->NoRuleMessages = false; if(const char* ruleStatus = cm->GetState() @@ -276,80 +272,6 @@ void cmMakefileTargetGenerator::WriteCommonCodeRules() << "\n\n"; } -//---------------------------------------------------------------------------- -std::string cmMakefileTargetGenerator::GetFlags(const std::string &l) -{ - ByLanguageMap::iterator i = this->FlagsByLanguage.find(l); - if (i == this->FlagsByLanguage.end()) - { - std::string flags; - const char *lang = l.c_str(); - - // Add language feature flags. - this->AddFeatureFlags(flags, lang); - - this->LocalGenerator->AddArchitectureFlags(flags, this->GeneratorTarget, - lang, this->ConfigName); - - // Fortran-specific flags computed for this target. - if(l == "Fortran") - { - this->AddFortranFlags(flags); - } - - this->LocalGenerator->AddCMP0018Flags(flags, this->Target, - lang, this->ConfigName); - - this->LocalGenerator->AddVisibilityPresetFlags(flags, this->Target, - lang); - - // Add include directory flags. - this->AddIncludeFlags(flags, lang); - - // Append old-style preprocessor definition flags. - this->LocalGenerator-> - AppendFlags(flags, this->Makefile->GetDefineFlags()); - - // Add include directory flags. - this->LocalGenerator-> - AppendFlags(flags,this->GetFrameworkFlags(l)); - - // Add target-specific flags. - this->LocalGenerator->AddCompileOptions(flags, this->Target, - lang, this->ConfigName); - - ByLanguageMap::value_type entry(l, flags); - i = this->FlagsByLanguage.insert(entry).first; - } - return i->second; -} - -std::string cmMakefileTargetGenerator::GetDefines(const std::string &l) -{ - ByLanguageMap::iterator i = this->DefinesByLanguage.find(l); - if (i == this->DefinesByLanguage.end()) - { - std::set<std::string> defines; - const char *lang = l.c_str(); - // Add the export symbol definition for shared library objects. - if(const char* exportMacro = this->Target->GetExportMacro()) - { - this->LocalGenerator->AppendDefines(defines, exportMacro); - } - - // Add preprocessor definitions for this target and configuration. - this->LocalGenerator->AddCompileDefinitions(defines, this->Target, - this->LocalGenerator->ConfigurationName, l); - - std::string definesString; - this->LocalGenerator->JoinDefines(defines, definesString, lang); - - ByLanguageMap::value_type entry(l, definesString); - i = this->DefinesByLanguage.insert(entry).first; - } - return i->second; -} - void cmMakefileTargetGenerator::WriteTargetLanguageFlags() { // write language flags for target @@ -511,35 +433,6 @@ void cmMakefileTargetGenerator //---------------------------------------------------------------------------- void cmMakefileTargetGenerator -::AppendFortranFormatFlags(std::string& flags, cmSourceFile const& source) -{ - const char* srcfmt = source.GetProperty("Fortran_FORMAT"); - cmLocalGenerator::FortranFormat format = - this->LocalGenerator->GetFortranFormat(srcfmt); - if(format == cmLocalGenerator::FortranFormatNone) - { - const char* tgtfmt = this->Target->GetProperty("Fortran_FORMAT"); - format = this->LocalGenerator->GetFortranFormat(tgtfmt); - } - const char* var = 0; - switch (format) - { - case cmLocalGenerator::FortranFormatFixed: - var = "CMAKE_Fortran_FORMAT_FIXED_FLAG"; break; - case cmLocalGenerator::FortranFormatFree: - var = "CMAKE_Fortran_FORMAT_FREE_FLAG"; break; - default: break; - } - if(var) - { - this->LocalGenerator->AppendFlags( - flags, this->Makefile->GetDefinition(var)); - } -} - -//---------------------------------------------------------------------------- -void -cmMakefileTargetGenerator ::WriteObjectBuildFile(std::string &obj, const std::string& lang, cmSourceFile const& source, @@ -567,7 +460,7 @@ cmMakefileTargetGenerator this->LocalGenerator->AppendFlags(flags, langFlags); std::string configUpper = - cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName); + cmSystemTools::UpperCase(this->LocalGenerator->GetConfigName()); // Add Fortran format flags. if(lang == "Fortran") @@ -1158,7 +1051,7 @@ void cmMakefileTargetGenerator::WriteTargetDependRules() << "# Targets to which this target links.\n" << "set(CMAKE_TARGET_LINKED_INFO_FILES\n"; std::set<cmTarget const*> emitted; - const char* cfg = this->LocalGenerator->ConfigurationName.c_str(); + const char* cfg = this->LocalGenerator->GetConfigName().c_str(); if(cmComputeLinkInformation* cli = this->Target->GetLinkInformation(cfg)) { cmComputeLinkInformation::ItemVector const& items = cli->GetItems(); @@ -1558,67 +1451,6 @@ void cmMakefileTargetGenerator::WriteTargetDriverRule( } //---------------------------------------------------------------------------- -std::string cmMakefileTargetGenerator::GetFrameworkFlags(std::string const& l) -{ - if(!this->Makefile->IsOn("APPLE")) - { - return std::string(); - } - - std::string fwSearchFlagVar = "CMAKE_" + l + "_FRAMEWORK_SEARCH_FLAG"; - const char* fwSearchFlag = - this->Makefile->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; - - const std::string& config = - this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); - this->LocalGenerator->GetIncludeDirectories(includes, - this->GeneratorTarget, - "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(this->Target->NameResolvesToFramework(*i)) - { - std::string frameworkDir = *i; - frameworkDir += "/../"; - frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir); - emitted.insert(frameworkDir); - } - } - - std::string flags; - const char* cfg = this->LocalGenerator->ConfigurationName.c_str(); - if(cmComputeLinkInformation* cli = this->Target->GetLinkInformation(cfg)) - { - 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 += this->LocalGenerator - ->ConvertToOutputFormat(*i, cmLocalGenerator::SHELL); - flags += " "; - } - } - } - return flags; -} - -//---------------------------------------------------------------------------- void cmMakefileTargetGenerator ::AppendTargetDepends(std::vector<std::string>& depends) { @@ -1629,7 +1461,7 @@ void cmMakefileTargetGenerator } // Loop over all library dependencies. - const char* cfg = this->LocalGenerator->ConfigurationName.c_str(); + const char* cfg = this->LocalGenerator->GetConfigName().c_str(); if(cmComputeLinkInformation* cli = this->Target->GetLinkInformation(cfg)) { std::vector<std::string> const& libDeps = cli->GetDepends(); @@ -1671,11 +1503,9 @@ void cmMakefileTargetGenerator this->AppendTargetDepends(depends); // Add a dependency on the link definitions file, if any. - std::string def = this->GeneratorTarget->GetModuleDefinitionFile( - this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE")); - if(!def.empty()) + if(!this->ModuleDefinitionFile.empty()) { - depends.push_back(def); + depends.push_back(this->ModuleDefinitionFile); } // Add user-specified dependencies. @@ -1982,149 +1812,3 @@ void cmMakefileTargetGenerator::AddIncludeFlags(std::string& flags, this->LocalGenerator->AppendFlags(flags, includeFlags); } } - -//---------------------------------------------------------------------------- -const char* cmMakefileTargetGenerator::GetFortranModuleDirectory() -{ - // Compute the module directory. - if(!this->FortranModuleDirectoryComputed) - { - const char* target_mod_dir = - this->Target->GetProperty("Fortran_MODULE_DIRECTORY"); - const char* moddir_flag = - this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_FLAG"); - if(target_mod_dir && moddir_flag) - { - // Compute the full path to the module directory. - if(cmSystemTools::FileIsFullPath(target_mod_dir)) - { - // Already a full path. - this->FortranModuleDirectory = target_mod_dir; - } - else - { - // Interpret relative to the current output directory. - this->FortranModuleDirectory = - this->Makefile->GetCurrentBinaryDirectory(); - this->FortranModuleDirectory += "/"; - this->FortranModuleDirectory += target_mod_dir; - } - - // Make sure the module output directory exists. - cmSystemTools::MakeDirectory(this->FortranModuleDirectory.c_str()); - } - this->FortranModuleDirectoryComputed = true; - } - - // Return the computed directory. - if(this->FortranModuleDirectory.empty()) - { - return 0; - } - else - { - return this->FortranModuleDirectory.c_str(); - } -} - -//---------------------------------------------------------------------------- -void cmMakefileTargetGenerator::AddFortranFlags(std::string& flags) -{ - // Enable module output if necessary. - if(const char* modout_flag = - this->Makefile->GetDefinition("CMAKE_Fortran_MODOUT_FLAG")) - { - this->LocalGenerator->AppendFlags(flags, modout_flag); - } - - // Add a module output directory flag if necessary. - const char* mod_dir = this->GetFortranModuleDirectory(); - if(!mod_dir) - { - mod_dir = this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_DEFAULT"); - } - if(mod_dir) - { - const char* moddir_flag = - this->Makefile->GetRequiredDefinition("CMAKE_Fortran_MODDIR_FLAG"); - std::string modflag = moddir_flag; - modflag += this->Convert(mod_dir, - cmLocalGenerator::START_OUTPUT, - cmLocalGenerator::SHELL); - this->LocalGenerator->AppendFlags(flags, modflag); - } - - // If there is a separate module path flag then duplicate the - // include path with it. This compiler does not search the include - // path for modules. - if(const char* modpath_flag = - this->Makefile->GetDefinition("CMAKE_Fortran_MODPATH_FLAG")) - { - std::vector<std::string> includes; - const std::string& config = - this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); - this->LocalGenerator->GetIncludeDirectories(includes, - this->GeneratorTarget, - "C", config); - for(std::vector<std::string>::const_iterator idi = includes.begin(); - idi != includes.end(); ++idi) - { - std::string flg = modpath_flag; - flg += this->Convert(*idi, - cmLocalGenerator::NONE, - cmLocalGenerator::SHELL); - this->LocalGenerator->AppendFlags(flags, flg); - } - } -} - -//---------------------------------------------------------------------------- -void cmMakefileTargetGenerator::AddModuleDefinitionFlag(std::string& flags) -{ - std::string def = this->GeneratorTarget->GetModuleDefinitionFile( - this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE")); - if(def.empty()) - { - return; - } - - // TODO: Create a per-language flag variable. - const char* defFileFlag = - this->Makefile->GetDefinition("CMAKE_LINK_DEF_FILE_FLAG"); - if(!defFileFlag) - { - return; - } - - // Append the flag and value. Use ConvertToLinkReference to help - // vs6's "cl -link" pass it to the linker. - std::string flag = defFileFlag; - flag += (this->LocalGenerator->ConvertToLinkReference(def)); - this->LocalGenerator->AppendFlags(flags, flag); -} - -//---------------------------------------------------------------------------- -const char* cmMakefileTargetGenerator::GetFeature(const std::string& feature) -{ - return this->GeneratorTarget->GetFeature(feature, this->ConfigName); -} - -//---------------------------------------------------------------------------- -bool cmMakefileTargetGenerator::GetFeatureAsBool(const std::string& feature) -{ - return this->GeneratorTarget->GetFeatureAsBool(feature, this->ConfigName); -} - -//---------------------------------------------------------------------------- -void cmMakefileTargetGenerator::AddFeatureFlags( - std::string& flags, const std::string& lang - ) -{ - // Add language-specific flags. - this->LocalGenerator->AddLanguageFlags(flags, lang, this->ConfigName); - - if(this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION")) - { - this->LocalGenerator->AppendFeatureOptions(flags, lang, "IPO"); - } -} diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h index 9182236..b885672 100644 --- a/Source/cmMakefileTargetGenerator.h +++ b/Source/cmMakefileTargetGenerator.h @@ -12,6 +12,8 @@ #ifndef cmMakefileTargetGenerator_h #define cmMakefileTargetGenerator_h +#include "cmCommonTargetGenerator.h" + #include "cmLocalUnixMakefileGenerator3.h" #include "cmOSXBundleGenerator.h" @@ -30,7 +32,7 @@ class cmSourceFile; * \brief Support Routines for writing makefiles * */ -class cmMakefileTargetGenerator +class cmMakefileTargetGenerator: public cmCommonTargetGenerator { public: // constructor to set the ivars @@ -124,12 +126,6 @@ protected: void DriveCustomCommands(std::vector<std::string>& depends); - // Return the a string with -F flags on apple - std::string GetFrameworkFlags(std::string const& l); - - void AppendFortranFormatFlags(std::string& flags, - cmSourceFile const& source); - // append intertarget dependencies void AppendTargetDepends(std::vector<std::string>& depends); @@ -173,12 +169,8 @@ protected: virtual void CloseFileStreams(); void RemoveForbiddenFlags(const char* flagVar, const std::string& linkLang, std::string& linkFlags); - cmTarget *Target; - cmGeneratorTarget* GeneratorTarget; cmLocalUnixMakefileGenerator3 *LocalGenerator; cmGlobalUnixMakefileGenerator3 *GlobalGenerator; - cmMakefile *Makefile; - std::string ConfigName; enum CustomCommandDriveType { OnBuild, OnDepends, OnUtility }; CustomCommandDriveType CustomCommandDriver; @@ -242,42 +234,6 @@ protected: std::set<std::string> MacContentFolders; cmOSXBundleGenerator* OSXBundleGenerator; MacOSXContentGeneratorType* MacOSXContentGenerator; - - typedef std::map<std::string, std::string> ByLanguageMap; - std::string GetFlags(const std::string &l); - ByLanguageMap FlagsByLanguage; - std::string GetDefines(const std::string &l); - ByLanguageMap DefinesByLanguage; - - // Target-wide Fortran module output directory. - bool FortranModuleDirectoryComputed; - std::string FortranModuleDirectory; - const char* GetFortranModuleDirectory(); - - // Compute target-specific Fortran language flags. - void AddFortranFlags(std::string& flags); - - // Helper to add flag for windows .def file. - void AddModuleDefinitionFlag(std::string& flags); - - // Add language feature flags. - void AddFeatureFlags(std::string& flags, const std::string& lang); - - // Feature query methods. - const char* GetFeature(const std::string& feature); - bool GetFeatureAsBool(const std::string& feature); - - //================================================================== - // Convenience routines that do nothing more than forward to - // implementaitons - std::string Convert(const std::string& source, - cmLocalGenerator::RelativeRoot relative, - cmLocalGenerator::OutputFormat output = - cmLocalGenerator::UNCHANGED) - { - return this->LocalGenerator->Convert(source, relative, output); - } - }; #endif diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index b18f368..a72bc72 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -58,17 +58,14 @@ cmNinjaTargetGenerator::New(cmGeneratorTarget* target) } cmNinjaTargetGenerator::cmNinjaTargetGenerator(cmGeneratorTarget* target) - : + : cmCommonTargetGenerator(target), MacOSXContentGenerator(0), OSXBundleGenerator(0), MacContentFolders(), - Target(target->Target), - Makefile(target->Makefile), LocalGenerator( static_cast<cmLocalNinjaGenerator*>(target->GetLocalGenerator())), Objects() { - this->GeneratorTarget = target; MacOSXContentGenerator = new MacOSXContentGeneratorType(this); } @@ -92,11 +89,6 @@ cmGlobalNinjaGenerator* cmNinjaTargetGenerator::GetGlobalGenerator() const return this->LocalGenerator->GetGlobalNinjaGenerator(); } -std::string const& cmNinjaTargetGenerator::GetConfigName() const -{ - return this->LocalGenerator->GetConfigName(); -} - std::string cmNinjaTargetGenerator::LanguageCompilerRule( const std::string& lang) const { @@ -104,32 +96,6 @@ std::string cmNinjaTargetGenerator::LanguageCompilerRule( cmGlobalNinjaGenerator::EncodeRuleName(this->Target->GetName()); } -// TODO: Picked up from cmMakefileTargetGenerator. Refactor it. -const char* cmNinjaTargetGenerator::GetFeature(const std::string& feature) -{ - return this->GeneratorTarget->GetFeature(feature, this->GetConfigName()); -} - -// TODO: Picked up from cmMakefileTargetGenerator. Refactor it. -bool cmNinjaTargetGenerator::GetFeatureAsBool(const std::string& feature) -{ - return this->GeneratorTarget->GetFeatureAsBool(feature, - this->GetConfigName()); -} - -// TODO: Picked up from cmMakefileTargetGenerator. Refactor it. -void cmNinjaTargetGenerator::AddFeatureFlags(std::string& flags, - const std::string& lang) -{ - // Add language-specific flags. - this->LocalGenerator->AddLanguageFlags(flags, lang, this->GetConfigName()); - - if(this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION")) - { - this->LocalGenerator->AppendFeatureOptions(flags, lang, "IPO"); - } -} - std::string cmNinjaTargetGenerator::OrderDependsTargetForTarget() { @@ -144,71 +110,37 @@ std::string cmNinjaTargetGenerator::ComputeFlagsForObject(cmSourceFile const* source, const std::string& language) { - // TODO: Fortran support. - // // Fortran-specific flags computed for this target. - // if(*l == "Fortran") - // { - // this->AddFortranFlags(flags); - // } - - bool hasLangCached = this->LanguageFlags.count(language) != 0; - std::string& languageFlags = this->LanguageFlags[language]; - if(!hasLangCached) - { - this->AddFeatureFlags(languageFlags, language); - - this->GetLocalGenerator()->AddArchitectureFlags(languageFlags, - this->GeneratorTarget, - language, - this->GetConfigName()); - - // Add shared-library flags if needed. - this->LocalGenerator->AddCMP0018Flags(languageFlags, this->Target, - language, - this->GetConfigName()); - - this->LocalGenerator->AddVisibilityPresetFlags(languageFlags, this->Target, - language); - - std::vector<std::string> includes; - this->LocalGenerator->GetIncludeDirectories(includes, - this->GeneratorTarget, - language, - this->GetConfigName()); - // Add include directory flags. - std::string includeFlags = - this->LocalGenerator->GetIncludeFlags(includes, this->GeneratorTarget, - language, - language == "RC" ? true : false, // full include paths for RC - // needed by cmcldeps - false, - this->GetConfigName()); - if (this->GetGlobalGenerator()->IsGCCOnWindows()) - cmSystemTools::ReplaceString(includeFlags, "\\", "/"); - - this->LocalGenerator->AppendFlags(languageFlags, includeFlags); - - // Append old-style preprocessor definition flags. - this->LocalGenerator->AppendFlags(languageFlags, - this->Makefile->GetDefineFlags()); - - // Add target-specific flags. - this->LocalGenerator->AddCompileOptions(languageFlags, this->Target, - language, - this->GetConfigName()); - } - - std::string flags = languageFlags; + std::string flags = this->GetFlags(language); // Add source file specific flags. this->LocalGenerator->AppendFlags(flags, source->GetProperty("COMPILE_FLAGS")); - // TODO: Handle Apple frameworks. - return flags; } +void cmNinjaTargetGenerator::AddIncludeFlags(std::string& languageFlags, + std::string const& language) +{ + std::vector<std::string> includes; + this->LocalGenerator->GetIncludeDirectories(includes, + this->GeneratorTarget, + language, + this->GetConfigName()); + // Add include directory flags. + std::string includeFlags = + this->LocalGenerator->GetIncludeFlags(includes, this->GeneratorTarget, + language, + language == "RC" ? true : false, // full include paths for RC + // needed by cmcldeps + false, + this->GetConfigName()); + if (this->GetGlobalGenerator()->IsGCCOnWindows()) + cmSystemTools::ReplaceString(includeFlags, "\\", "/"); + + this->LocalGenerator->AppendFlags(languageFlags, includeFlags); +} + bool cmNinjaTargetGenerator::NeedDepTypeMSVC(const std::string& lang) const { if (lang == "C" || lang == "CXX") @@ -231,16 +163,6 @@ cmNinjaTargetGenerator:: ComputeDefines(cmSourceFile const* source, const std::string& language) { std::set<std::string> defines; - - // Add the export symbol definition for shared library objects. - if(const char* exportMacro = this->Target->GetExportMacro()) - { - this->LocalGenerator->AppendDefines(defines, exportMacro); - } - - // Add preprocessor definitions for this target and configuration. - this->LocalGenerator->AddCompileDefinitions(defines, this->Target, - this->GetConfigName(), language); this->LocalGenerator->AppendDefines (defines, source->GetProperty("COMPILE_DEFINITIONS")); @@ -252,7 +174,7 @@ ComputeDefines(cmSourceFile const* source, const std::string& language) source->GetProperty(defPropName)); } - std::string definesString; + std::string definesString = this->GetDefines(language); this->LocalGenerator->JoinDefines(defines, definesString, language); @@ -278,7 +200,7 @@ cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const // Add a dependency on the link definitions file, if any. if(!this->ModuleDefinitionFile.empty()) { - result.push_back(this->ModuleDefinitionFile); + result.push_back(this->ConvertToNinjaPath(this->ModuleDefinitionFile)); } return result; @@ -608,11 +530,6 @@ cmNinjaTargetGenerator { this->WriteObjectBuildStatement(*si, !orderOnlyDeps.empty()); } - std::string def = this->GeneratorTarget->GetModuleDefinitionFile(config); - if(!def.empty()) - { - this->ModuleDefinitionFile = this->ConvertToNinjaPath(def); - } this->GetBuildFileStream() << "\n"; } @@ -762,32 +679,6 @@ cmNinjaTargetGenerator } } -//---------------------------------------------------------------------------- -void -cmNinjaTargetGenerator -::AddModuleDefinitionFlag(std::string& flags) -{ - if(this->ModuleDefinitionFile.empty()) - { - return; - } - - // TODO: Create a per-language flag variable. - const char* defFileFlag = - this->Makefile->GetDefinition("CMAKE_LINK_DEF_FILE_FLAG"); - if(!defFileFlag) - { - return; - } - - // Append the flag and value. Use ConvertToLinkReference to help - // vs6's "cl -link" pass it to the linker. - std::string flag = defFileFlag; - flag += (this->LocalGenerator->ConvertToLinkReference( - this->ModuleDefinitionFile)); - this->LocalGenerator->AppendFlags(flags, flag); -} - void cmNinjaTargetGenerator ::EnsureDirectoryExists(const std::string& path) const diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index fc361b2..8912431 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -13,6 +13,8 @@ #ifndef cmNinjaTargetGenerator_h #define cmNinjaTargetGenerator_h +#include "cmCommonTargetGenerator.h" + #include "cmStandardIncludes.h" #include "cmNinjaTypes.h" #include "cmLocalNinjaGenerator.h" @@ -26,7 +28,7 @@ class cmMakefile; class cmSourceFile; class cmCustomCommand; -class cmNinjaTargetGenerator +class cmNinjaTargetGenerator: public cmCommonTargetGenerator { public: /// Create a cmNinjaTargetGenerator according to the @a target's type. @@ -65,14 +67,8 @@ protected: cmMakefile* GetMakefile() const { return this->Makefile; } - std::string const& GetConfigName() const; - std::string LanguageCompilerRule(const std::string& lang) const; - const char* GetFeature(const std::string& feature); - bool GetFeatureAsBool(const std::string& feature); - void AddFeatureFlags(std::string& flags, const std::string& lang); - std::string OrderDependsTargetForTarget(); std::string ComputeOrderDependsForTarget(); @@ -85,6 +81,8 @@ protected: std::string ComputeFlagsForObject(cmSourceFile const* source, const std::string& language); + void AddIncludeFlags(std::string& flags, std::string const& lang); + std::string ComputeDefines(cmSourceFile const* source, const std::string& language); @@ -119,9 +117,6 @@ protected: cmNinjaDeps GetObjects() const { return this->Objects; } - // Helper to add flag for windows .def file. - void AddModuleDefinitionFlag(std::string& flags); - void EnsureDirectoryExists(const std::string& dir) const; void EnsureParentDirectoryExists(const std::string& path) const; @@ -150,19 +145,10 @@ protected: cmNinjaVars& vars); private: - cmTarget* Target; - cmGeneratorTarget* GeneratorTarget; - cmMakefile* Makefile; cmLocalNinjaGenerator* LocalGenerator; /// List of object files for this target. cmNinjaDeps Objects; std::vector<cmCustomCommand const*> CustomCommands; - - typedef std::map<std::string, std::string> LanguageFlagMap; - LanguageFlagMap LanguageFlags; - - // The windows module definition source file (.def), if any. - std::string ModuleDefinitionFile; }; #endif // ! cmNinjaTargetGenerator_h diff --git a/Source/cmOutputConverter.cxx b/Source/cmOutputConverter.cxx index b0a30a1..7cd6a47 100644 --- a/Source/cmOutputConverter.cxx +++ b/Source/cmOutputConverter.cxx @@ -14,10 +14,11 @@ #include "cmAlgorithms.h" #include "cmake.h" -#include <cmsys/System.h> - #include <assert.h> +#include <string.h> /* strlen */ +#include <ctype.h> /* isalpha */ + cmOutputConverter::cmOutputConverter(cmState::Snapshot snapshot) : StateSnapshot(snapshot), LinkScriptShell(false) { @@ -330,51 +331,51 @@ std::string cmOutputConverter::EscapeForShell(const std::string& str, int flags = 0; if(this->GetState()->UseWindowsVSIDE()) { - flags |= cmsysSystem_Shell_Flag_VSIDE; + flags |= Shell_Flag_VSIDE; } else if(!this->LinkScriptShell) { - flags |= cmsysSystem_Shell_Flag_Make; + flags |= Shell_Flag_Make; } if(makeVars) { - flags |= cmsysSystem_Shell_Flag_AllowMakeVariables; + flags |= Shell_Flag_AllowMakeVariables; } if(forEcho) { - flags |= cmsysSystem_Shell_Flag_EchoWindows; + flags |= Shell_Flag_EchoWindows; } if(useWatcomQuote) { - flags |= cmsysSystem_Shell_Flag_WatcomQuote; + flags |= Shell_Flag_WatcomQuote; } if(this->GetState()->UseWatcomWMake()) { - flags |= cmsysSystem_Shell_Flag_WatcomWMake; + flags |= Shell_Flag_WatcomWMake; } if(this->GetState()->UseMinGWMake()) { - flags |= cmsysSystem_Shell_Flag_MinGWMake; + flags |= Shell_Flag_MinGWMake; } if(this->GetState()->UseNMake()) { - flags |= cmsysSystem_Shell_Flag_NMake; + flags |= Shell_Flag_NMake; } // Compute the buffer size needed. int size = (this->GetState()->UseWindowsShell() ? - cmsysSystem_Shell_GetArgumentSizeForWindows(str.c_str(), flags) : - cmsysSystem_Shell_GetArgumentSizeForUnix(str.c_str(), flags)); + Shell_GetArgumentSizeForWindows(str.c_str(), flags) : + Shell_GetArgumentSizeForUnix(str.c_str(), flags)); // Compute the shell argument itself. std::vector<char> arg(size); if(this->GetState()->UseWindowsShell()) { - cmsysSystem_Shell_GetArgumentForWindows(str.c_str(), &arg[0], flags); + Shell_GetArgumentForWindows(str.c_str(), &arg[0], flags); } else { - cmsysSystem_Shell_GetArgumentForUnix(str.c_str(), &arg[0], flags); + Shell_GetArgumentForUnix(str.c_str(), &arg[0], flags); } return std::string(&arg[0]); } @@ -412,6 +413,26 @@ std::string cmOutputConverter::EscapeForCMake(const std::string& str) } //---------------------------------------------------------------------------- +std::string +cmOutputConverter::EscapeWindowsShellArgument(const char* arg, int shell_flags) +{ + char local_buffer[1024]; + char* buffer = local_buffer; + int size = Shell_GetArgumentSizeForWindows(arg, shell_flags); + if(size > 1024) + { + buffer = new char[size]; + } + Shell_GetArgumentForWindows(arg, buffer, shell_flags); + std::string result(buffer); + if(buffer != local_buffer) + { + delete [] buffer; + } + return result; +} + +//---------------------------------------------------------------------------- cmOutputConverter::FortranFormat cmOutputConverter::GetFortranFormat(const char* value) { @@ -445,3 +466,585 @@ cmState* cmOutputConverter::GetState() const { return this->StateSnapshot.GetState(); } + +//---------------------------------------------------------------------------- +/* + +Notes: + +Make variable replacements open a can of worms. Sometimes they should +be quoted and sometimes not. Sometimes their replacement values are +already quoted. + +VS variables cause problems. In order to pass the referenced value +with spaces the reference must be quoted. If the variable value ends +in a backslash then it will escape the ending quote! In order to make +the ending backslash appear we need this: + + "$(InputDir)\" + +However if there is not a trailing backslash then this will put a +quote in the value so we need: + + "$(InputDir)" + +Make variable references are platform specific so we should probably +just NOT quote them and let the listfile author deal with it. + +*/ + +/* +TODO: For windows echo: + +To display a pipe (|) or redirection character (< or >) when using the +echo command, use a caret character immediately before the pipe or +redirection character (for example, ^>, ^<, or ^| ). If you need to +use the caret character itself (^), use two in a row (^^). +*/ + +/*--------------------------------------------------------------------------*/ +int cmOutputConverter::Shell__CharIsWhitespace(char c) +{ + return ((c == ' ') || (c == '\t')); +} + +/*--------------------------------------------------------------------------*/ +int cmOutputConverter::Shell__CharNeedsQuotesOnUnix(char c) +{ + return ((c == '\'') || (c == '`') || (c == ';') || (c == '#') || + (c == '&') || (c == '$') || (c == '(') || (c == ')') || + (c == '~') || (c == '<') || (c == '>') || (c == '|') || + (c == '*') || (c == '^') || (c == '\\')); +} + +/*--------------------------------------------------------------------------*/ +int cmOutputConverter::Shell__CharNeedsQuotesOnWindows(char c) +{ + return ((c == '\'') || (c == '#') || (c == '&') || + (c == '<') || (c == '>') || (c == '|') || (c == '^')); +} + +/*--------------------------------------------------------------------------*/ +int cmOutputConverter::Shell__CharNeedsQuotes(char c, int isUnix, int flags) +{ + /* On Windows the built-in command shell echo never needs quotes. */ + if(!isUnix && (flags & Shell_Flag_EchoWindows)) + { + return 0; + } + + /* On all platforms quotes are needed to preserve whitespace. */ + if(Shell__CharIsWhitespace(c)) + { + return 1; + } + + if(isUnix) + { + /* On UNIX several special characters need quotes to preserve them. */ + if(Shell__CharNeedsQuotesOnUnix(c)) + { + return 1; + } + } + else + { + /* On Windows several special characters need quotes to preserve them. */ + if(Shell__CharNeedsQuotesOnWindows(c)) + { + return 1; + } + } + return 0; +} + +/*--------------------------------------------------------------------------*/ +int cmOutputConverter::Shell__CharIsMakeVariableName(char c) +{ + return c && (c == '_' || isalpha(((int)c))); +} + +/*--------------------------------------------------------------------------*/ +const char* cmOutputConverter::Shell__SkipMakeVariables(const char* c) +{ + while(*c == '$' && *(c+1) == '(') + { + const char* skip = c+2; + while(Shell__CharIsMakeVariableName(*skip)) + { + ++skip; + } + if(*skip == ')') + { + c = skip+1; + } + else + { + break; + } + } + return c; +} + +/* +Allowing make variable replacements opens a can of worms. Sometimes +they should be quoted and sometimes not. Sometimes their replacement +values are already quoted or contain escapes. + +Some Visual Studio variables cause problems. In order to pass the +referenced value with spaces the reference must be quoted. If the +variable value ends in a backslash then it will escape the ending +quote! In order to make the ending backslash appear we need this: + + "$(InputDir)\" + +However if there is not a trailing backslash then this will put a +quote in the value so we need: + + "$(InputDir)" + +This macro decides whether we quote an argument just because it +contains a make variable reference. This should be replaced with a +flag later when we understand applications of this better. +*/ +#define KWSYS_SYSTEM_SHELL_QUOTE_MAKE_VARIABLES 0 + +/*--------------------------------------------------------------------------*/ +int cmOutputConverter::Shell__ArgumentNeedsQuotes(const char* in, + int isUnix, int flags) +{ + /* The empty string needs quotes. */ + if(!*in) + { + return 1; + } + + /* Scan the string for characters that require quoting. */ + { + const char* c; + for(c=in; *c; ++c) + { + /* Look for $(MAKEVAR) syntax if requested. */ + if(flags & Shell_Flag_AllowMakeVariables) + { +#if KWSYS_SYSTEM_SHELL_QUOTE_MAKE_VARIABLES + const char* skip = Shell__SkipMakeVariables(c); + if(skip != c) + { + /* We need to quote make variable references to preserve the + string with contents substituted in its place. */ + return 1; + } +#else + /* Skip over the make variable references if any are present. */ + c = Shell__SkipMakeVariables(c); + + /* Stop if we have reached the end of the string. */ + if(!*c) + { + break; + } +#endif + } + + /* Check whether this character needs quotes. */ + if(Shell__CharNeedsQuotes(*c, isUnix, flags)) + { + return 1; + } + } + } + + /* On Windows some single character arguments need quotes. */ + if(!isUnix && *in && !*(in+1)) + { + char c = *in; + if((c == '?') || (c == '&') || (c == '^') || (c == '|') || (c == '#')) + { + return 1; + } + } + + return 0; +} + +/*--------------------------------------------------------------------------*/ +int cmOutputConverter::Shell__GetArgumentSize(const char* in, + int isUnix, int flags) +{ + /* Start with the length of the original argument, plus one for + either a terminating null or a separating space. */ + int size = (int)strlen(in) + 1; + + /* String iterator. */ + const char* c; + + /* Keep track of how many backslashes have been encountered in a row. */ + int windows_backslashes = 0; + + /* Scan the string for characters that require escaping or quoting. */ + for(c=in; *c; ++c) + { + /* Look for $(MAKEVAR) syntax if requested. */ + if(flags & Shell_Flag_AllowMakeVariables) + { + /* Skip over the make variable references if any are present. */ + c = Shell__SkipMakeVariables(c); + + /* Stop if we have reached the end of the string. */ + if(!*c) + { + break; + } + } + + /* Check whether this character needs escaping for the shell. */ + if(isUnix) + { + /* On Unix a few special characters need escaping even inside a + quoted argument. */ + if(*c == '\\' || *c == '"' || *c == '`' || *c == '$') + { + /* This character needs a backslash to escape it. */ + ++size; + } + } + else if(flags & Shell_Flag_EchoWindows) + { + /* On Windows the built-in command shell echo never needs escaping. */ + } + else + { + /* On Windows only backslashes and double-quotes need escaping. */ + if(*c == '\\') + { + /* Found a backslash. It may need to be escaped later. */ + ++windows_backslashes; + } + else if(*c == '"') + { + /* Found a double-quote. We need to escape it and all + immediately preceding backslashes. */ + size += windows_backslashes + 1; + windows_backslashes = 0; + } + else + { + /* Found another character. This eliminates the possibility + that any immediately preceding backslashes will be + escaped. */ + windows_backslashes = 0; + } + } + + /* Check whether this character needs escaping for a make tool. */ + if(*c == '$') + { + if(flags & Shell_Flag_Make) + { + /* In Makefiles a dollar is written $$ so we need one extra + character. */ + ++size; + } + else if(flags & Shell_Flag_VSIDE) + { + /* In a VS IDE a dollar is written "$" so we need two extra + characters. */ + size += 2; + } + } + else if(*c == '#') + { + if((flags & Shell_Flag_Make) && + (flags & Shell_Flag_WatcomWMake)) + { + /* In Watcom WMake makefiles a pound is written $# so we need + one extra character. */ + ++size; + } + } + else if(*c == '%') + { + if((flags & Shell_Flag_VSIDE) || + ((flags & Shell_Flag_Make) && + ((flags & Shell_Flag_MinGWMake) || + (flags & Shell_Flag_NMake)))) + { + /* In the VS IDE, NMake, or MinGW make a percent is written %% + so we need one extra characters. */ + size += 1; + } + } + else if(*c == ';') + { + if(flags & Shell_Flag_VSIDE) + { + /* In a VS IDE a semicolon is written ";" so we need two extra + characters. */ + size += 2; + } + } + } + + /* Check whether the argument needs surrounding quotes. */ + if(Shell__ArgumentNeedsQuotes(in, isUnix, flags)) + { + /* Surrounding quotes are needed. Allocate space for them. */ + if((flags & Shell_Flag_WatcomQuote) && (isUnix)) + { + size += 2; + } + size += 2; + + /* We must escape all ending backslashes when quoting on windows. */ + size += windows_backslashes; + } + + return size; +} + +/*--------------------------------------------------------------------------*/ +char* cmOutputConverter::Shell__GetArgument(const char* in, char* out, + int isUnix, int flags) +{ + /* String iterator. */ + const char* c; + + /* Keep track of how many backslashes have been encountered in a row. */ + int windows_backslashes = 0; + + /* Whether the argument must be quoted. */ + int needQuotes = Shell__ArgumentNeedsQuotes(in, isUnix, flags); + if(needQuotes) + { + /* Add the opening quote for this argument. */ + if(flags & Shell_Flag_WatcomQuote) + { + if(isUnix) + { + *out++ = '"'; + } + *out++ = '\''; + } + else + { + *out++ = '"'; + } + } + + /* Scan the string for characters that require escaping or quoting. */ + for(c=in; *c; ++c) + { + /* Look for $(MAKEVAR) syntax if requested. */ + if(flags & Shell_Flag_AllowMakeVariables) + { + const char* skip = Shell__SkipMakeVariables(c); + if(skip != c) + { + /* Copy to the end of the make variable references. */ + while(c != skip) + { + *out++ = *c++; + } + + /* The make variable reference eliminates any escaping needed + for preceding backslashes. */ + windows_backslashes = 0; + + /* Stop if we have reached the end of the string. */ + if(!*c) + { + break; + } + } + } + + /* Check whether this character needs escaping for the shell. */ + if(isUnix) + { + /* On Unix a few special characters need escaping even inside a + quoted argument. */ + if(*c == '\\' || *c == '"' || *c == '`' || *c == '$') + { + /* This character needs a backslash to escape it. */ + *out++ = '\\'; + } + } + else if(flags & Shell_Flag_EchoWindows) + { + /* On Windows the built-in command shell echo never needs escaping. */ + } + else + { + /* On Windows only backslashes and double-quotes need escaping. */ + if(*c == '\\') + { + /* Found a backslash. It may need to be escaped later. */ + ++windows_backslashes; + } + else if(*c == '"') + { + /* Found a double-quote. Escape all immediately preceding + backslashes. */ + while(windows_backslashes > 0) + { + --windows_backslashes; + *out++ = '\\'; + } + + /* Add the backslash to escape the double-quote. */ + *out++ = '\\'; + } + else + { + /* We encountered a normal character. This eliminates any + escaping needed for preceding backslashes. */ + windows_backslashes = 0; + } + } + + /* Check whether this character needs escaping for a make tool. */ + if(*c == '$') + { + if(flags & Shell_Flag_Make) + { + /* In Makefiles a dollar is written $$. The make tool will + replace it with just $ before passing it to the shell. */ + *out++ = '$'; + *out++ = '$'; + } + else if(flags & Shell_Flag_VSIDE) + { + /* In a VS IDE a dollar is written "$". If this is written in + an un-quoted argument it starts a quoted segment, inserts + the $ and ends the segment. If it is written in a quoted + argument it ends quoting, inserts the $ and restarts + quoting. Either way the $ is isolated from surrounding + text to avoid looking like a variable reference. */ + *out++ = '"'; + *out++ = '$'; + *out++ = '"'; + } + else + { + /* Otherwise a dollar is written just $. */ + *out++ = '$'; + } + } + else if(*c == '#') + { + if((flags & Shell_Flag_Make) && + (flags & Shell_Flag_WatcomWMake)) + { + /* In Watcom WMake makefiles a pound is written $#. The make + tool will replace it with just # before passing it to the + shell. */ + *out++ = '$'; + *out++ = '#'; + } + else + { + /* Otherwise a pound is written just #. */ + *out++ = '#'; + } + } + else if(*c == '%') + { + if((flags & Shell_Flag_VSIDE) || + ((flags & Shell_Flag_Make) && + ((flags & Shell_Flag_MinGWMake) || + (flags & Shell_Flag_NMake)))) + { + /* In the VS IDE, NMake, or MinGW make a percent is written %%. */ + *out++ = '%'; + *out++ = '%'; + } + else + { + /* Otherwise a percent is written just %. */ + *out++ = '%'; + } + } + else if(*c == ';') + { + if(flags & Shell_Flag_VSIDE) + { + /* In a VS IDE a semicolon is written ";". If this is written + in an un-quoted argument it starts a quoted segment, + inserts the ; and ends the segment. If it is written in a + quoted argument it ends quoting, inserts the ; and restarts + quoting. Either way the ; is isolated. */ + *out++ = '"'; + *out++ = ';'; + *out++ = '"'; + } + else + { + /* Otherwise a semicolon is written just ;. */ + *out++ = ';'; + } + } + else + { + /* Store this character. */ + *out++ = *c; + } + } + + if(needQuotes) + { + /* Add enough backslashes to escape any trailing ones. */ + while(windows_backslashes > 0) + { + --windows_backslashes; + *out++ = '\\'; + } + + /* Add the closing quote for this argument. */ + if(flags & Shell_Flag_WatcomQuote) + { + *out++ = '\''; + if(isUnix) + { + *out++ = '"'; + } + } + else + { + *out++ = '"'; + } + } + + /* Store a terminating null without incrementing. */ + *out = 0; + + return out; +} + +/*--------------------------------------------------------------------------*/ +char* cmOutputConverter::Shell_GetArgumentForWindows(const char* in, + char* out, int flags) +{ + return Shell__GetArgument(in, out, 0, flags); +} + +/*--------------------------------------------------------------------------*/ +char* cmOutputConverter::Shell_GetArgumentForUnix(const char* in, + char* out, int flags) +{ + return Shell__GetArgument(in, out, 1, flags); +} + +/*--------------------------------------------------------------------------*/ +int cmOutputConverter::Shell_GetArgumentSizeForWindows(const char* in, + int flags) +{ + return Shell__GetArgumentSize(in, 0, flags); +} + +/*--------------------------------------------------------------------------*/ +int cmOutputConverter::Shell_GetArgumentSizeForUnix(const char* in, + int flags) +{ + return Shell__GetArgumentSize(in, 1, flags); +} diff --git a/Source/cmOutputConverter.h b/Source/cmOutputConverter.h index 482a64b..ed7739e 100644 --- a/Source/cmOutputConverter.h +++ b/Source/cmOutputConverter.h @@ -64,6 +64,63 @@ public: void SetLinkScriptShell(bool linkScriptShell); + /** + * Flags to pass to Shell_GetArgumentForWindows or + * Shell_GetArgumentForUnix. These modify the generated + * quoting and escape sequences to work under alternative + * environments. + */ + enum Shell_Flag_e + { + /** The target shell is in a makefile. */ + Shell_Flag_Make = (1<<0), + + /** The target shell is in a VS project file. Do not use with + Shell_Flag_Make. */ + Shell_Flag_VSIDE = (1<<1), + + /** In a windows shell the argument is being passed to "echo". */ + Shell_Flag_EchoWindows = (1<<2), + + /** The target shell is in a Watcom WMake makefile. */ + Shell_Flag_WatcomWMake = (1<<3), + + /** The target shell is in a MinGW Make makefile. */ + Shell_Flag_MinGWMake = (1<<4), + + /** The target shell is in a NMake makefile. */ + Shell_Flag_NMake = (1<<5), + + /** Make variable reference syntax $(MAKEVAR) should not be escaped + to allow a build tool to replace it. Replacement values + containing spaces, quotes, backslashes, or other + non-alphanumeric characters that have significance to some makes + or shells produce undefined behavior. */ + Shell_Flag_AllowMakeVariables = (1<<6), + + /** The target shell quoting uses extra single Quotes for Watcom tools. */ + Shell_Flag_WatcomQuote = (1<<7) + }; + + /** + * Transform the given command line argument for use in a Windows or + * Unix shell. Returns a pointer to the end of the command line + * argument in the provided output buffer. Flags may be passed to + * modify the generated quoting and escape sequences to work under + * alternative environments. + */ + static char* Shell_GetArgumentForWindows(const char* in, char* out, + int flags); + static char* Shell_GetArgumentForUnix(const char* in, char* out, int flags); + + /** + * Compute the size of the buffer required to store the output from + * Shell_GetArgumentForWindows or Shell_GetArgumentForUnix. The flags + * passed must be identical between the two calls. + */ + static int Shell_GetArgumentSizeForWindows(const char* in, int flags); + static int Shell_GetArgumentSizeForUnix(const char* in, int flags); + std::string EscapeForShell(const std::string& str, bool makeVars = false, bool forEcho = false, @@ -71,6 +128,11 @@ public: static std::string EscapeForCMake(const std::string& str); + /** Compute an escaped version of the given argument for use in a + windows shell. */ + static std::string EscapeWindowsShellArgument(const char* arg, + int shell_flags); + enum FortranFormat { FortranFormatNone, @@ -97,6 +159,19 @@ private: std::string const& result, OutputFormat format) const; + static int Shell__CharIsWhitespace(char c); + static int Shell__CharNeedsQuotesOnUnix(char c); + static int Shell__CharNeedsQuotesOnWindows(char c); + static int Shell__CharNeedsQuotes(char c, int isUnix, int flags); + static int Shell__CharIsMakeVariableName(char c); + static const char* Shell__SkipMakeVariables(const char* c); + static int Shell__ArgumentNeedsQuotes(const char* in, + int isUnix, int flags); + static int Shell__GetArgumentSize(const char* in, + int isUnix, int flags); + static char* Shell__GetArgument(const char* in, char* out, + int isUnix, int flags); + private: cmState::Snapshot StateSnapshot; diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 7230a64..2543e68 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -556,25 +556,6 @@ void cmSystemTools::ParseUnixCommandLine(const char* command, argv.Store(args); } -std::string cmSystemTools::EscapeWindowsShellArgument(const char* arg, - int shell_flags) -{ - char local_buffer[1024]; - char* buffer = local_buffer; - int size = cmsysSystem_Shell_GetArgumentSizeForWindows(arg, shell_flags); - if(size > 1024) - { - buffer = new char[size]; - } - cmsysSystem_Shell_GetArgumentForWindows(arg, buffer, shell_flags); - std::string result(buffer); - if(buffer != local_buffer) - { - delete [] buffer; - } - return result; -} - std::vector<std::string> cmSystemTools::ParseArguments(const char* command) { std::vector<std::string> args; diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 8ebb4e3..fb58307 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -256,11 +256,6 @@ public: static void ParseUnixCommandLine(const char* command, std::vector<std::string>& args); - /** Compute an escaped version of the given argument for use in a - windows shell. See kwsys/System.h.in for details. */ - static std::string EscapeWindowsShellArgument(const char* arg, - int shell_flags); - static void EnableMessages() { s_DisableMessages = false; } static void DisableMessages() { s_DisableMessages = true; } static void DisableRunCommandOutput() {s_DisableRunCommandOutput = true; } diff --git a/Source/cmVisualStudioGeneratorOptions.cxx b/Source/cmVisualStudioGeneratorOptions.cxx index 6512fc2..abd350e 100644 --- a/Source/cmVisualStudioGeneratorOptions.cxx +++ b/Source/cmVisualStudioGeneratorOptions.cxx @@ -1,6 +1,6 @@ #include "cmVisualStudioGeneratorOptions.h" +#include "cmOutputConverter.h" #include "cmSystemTools.h" -#include <cmsys/System.h> #include "cmVisualStudio10TargetGenerator.h" static @@ -246,10 +246,10 @@ void cmVisualStudioGeneratorOptions::StoreUnknownFlag(const char* flag) // This option is not known. Store it in the output flags. this->FlagString += " "; this->FlagString += - cmSystemTools::EscapeWindowsShellArgument( + cmOutputConverter::EscapeWindowsShellArgument( flag, - cmsysSystem_Shell_Flag_AllowMakeVariables | - cmsysSystem_Shell_Flag_VSIDE); + cmOutputConverter::Shell_Flag_AllowMakeVariables | + cmOutputConverter::Shell_Flag_VSIDE); } //---------------------------------------------------------------------------- diff --git a/Source/kwsys/System.c b/Source/kwsys/System.c index 1ee26fa..ccc7e81 100644 --- a/Source/kwsys/System.c +++ b/Source/kwsys/System.c @@ -20,8 +20,8 @@ #include <stddef.h> /* ptrdiff_t */ #include <stdlib.h> /* malloc, free */ -#include <string.h> /* strlen */ -#include <ctype.h> /* isalpha */ +#include <string.h> /* memcpy */ +#include <ctype.h> /* isspace */ #include <stdio.h> @@ -31,587 +31,6 @@ typedef ptrdiff_t kwsysSystem_ptrdiff_t; typedef int kwsysSystem_ptrdiff_t; #endif -/* - -Notes: - -Make variable replacements open a can of worms. Sometimes they should -be quoted and sometimes not. Sometimes their replacement values are -already quoted. - -VS variables cause problems. In order to pass the referenced value -with spaces the reference must be quoted. If the variable value ends -in a backslash then it will escape the ending quote! In order to make -the ending backslash appear we need this: - - "$(InputDir)\" - -However if there is not a trailing backslash then this will put a -quote in the value so we need: - - "$(InputDir)" - -Make variable references are platform specific so we should probably -just NOT quote them and let the listfile author deal with it. - -*/ - -/* -TODO: For windows echo: - -To display a pipe (|) or redirection character (< or >) when using the -echo command, use a caret character immediately before the pipe or -redirection character (for example, ^>, ^<, or ^| ). If you need to -use the caret character itself (^), use two in a row (^^). -*/ - -/*--------------------------------------------------------------------------*/ -static int kwsysSystem_Shell__CharIsWhitespace(char c) -{ - return ((c == ' ') || (c == '\t')); -} - -/*--------------------------------------------------------------------------*/ -static int kwsysSystem_Shell__CharNeedsQuotesOnUnix(char c) -{ - return ((c == '\'') || (c == '`') || (c == ';') || (c == '#') || - (c == '&') || (c == '$') || (c == '(') || (c == ')') || - (c == '~') || (c == '<') || (c == '>') || (c == '|') || - (c == '*') || (c == '^') || (c == '\\')); -} - -/*--------------------------------------------------------------------------*/ -static int kwsysSystem_Shell__CharNeedsQuotesOnWindows(char c) -{ - return ((c == '\'') || (c == '#') || (c == '&') || - (c == '<') || (c == '>') || (c == '|') || (c == '^')); -} - -/*--------------------------------------------------------------------------*/ -static int kwsysSystem_Shell__CharNeedsQuotes(char c, int isUnix, int flags) -{ - /* On Windows the built-in command shell echo never needs quotes. */ - if(!isUnix && (flags & kwsysSystem_Shell_Flag_EchoWindows)) - { - return 0; - } - - /* On all platforms quotes are needed to preserve whitespace. */ - if(kwsysSystem_Shell__CharIsWhitespace(c)) - { - return 1; - } - - if(isUnix) - { - /* On UNIX several special characters need quotes to preserve them. */ - if(kwsysSystem_Shell__CharNeedsQuotesOnUnix(c)) - { - return 1; - } - } - else - { - /* On Windows several special characters need quotes to preserve them. */ - if(kwsysSystem_Shell__CharNeedsQuotesOnWindows(c)) - { - return 1; - } - } - return 0; -} - -/*--------------------------------------------------------------------------*/ -static int kwsysSystem_Shell__CharIsMakeVariableName(char c) -{ - return c && (c == '_' || isalpha(((int)c))); -} - -/*--------------------------------------------------------------------------*/ -static const char* kwsysSystem_Shell__SkipMakeVariables(const char* c) -{ - while(*c == '$' && *(c+1) == '(') - { - const char* skip = c+2; - while(kwsysSystem_Shell__CharIsMakeVariableName(*skip)) - { - ++skip; - } - if(*skip == ')') - { - c = skip+1; - } - else - { - break; - } - } - return c; -} - -/* -Allowing make variable replacements opens a can of worms. Sometimes -they should be quoted and sometimes not. Sometimes their replacement -values are already quoted or contain escapes. - -Some Visual Studio variables cause problems. In order to pass the -referenced value with spaces the reference must be quoted. If the -variable value ends in a backslash then it will escape the ending -quote! In order to make the ending backslash appear we need this: - - "$(InputDir)\" - -However if there is not a trailing backslash then this will put a -quote in the value so we need: - - "$(InputDir)" - -This macro decides whether we quote an argument just because it -contains a make variable reference. This should be replaced with a -flag later when we understand applications of this better. -*/ -#define KWSYS_SYSTEM_SHELL_QUOTE_MAKE_VARIABLES 0 - -/*--------------------------------------------------------------------------*/ -static int kwsysSystem_Shell__ArgumentNeedsQuotes(const char* in, int isUnix, - int flags) -{ - /* The empty string needs quotes. */ - if(!*in) - { - return 1; - } - - /* Scan the string for characters that require quoting. */ - { - const char* c; - for(c=in; *c; ++c) - { - /* Look for $(MAKEVAR) syntax if requested. */ - if(flags & kwsysSystem_Shell_Flag_AllowMakeVariables) - { -#if KWSYS_SYSTEM_SHELL_QUOTE_MAKE_VARIABLES - const char* skip = kwsysSystem_Shell__SkipMakeVariables(c); - if(skip != c) - { - /* We need to quote make variable references to preserve the - string with contents substituted in its place. */ - return 1; - } -#else - /* Skip over the make variable references if any are present. */ - c = kwsysSystem_Shell__SkipMakeVariables(c); - - /* Stop if we have reached the end of the string. */ - if(!*c) - { - break; - } -#endif - } - - /* Check whether this character needs quotes. */ - if(kwsysSystem_Shell__CharNeedsQuotes(*c, isUnix, flags)) - { - return 1; - } - } - } - - /* On Windows some single character arguments need quotes. */ - if(!isUnix && *in && !*(in+1)) - { - char c = *in; - if((c == '?') || (c == '&') || (c == '^') || (c == '|') || (c == '#')) - { - return 1; - } - } - - return 0; -} - -/*--------------------------------------------------------------------------*/ -static int kwsysSystem_Shell__GetArgumentSize(const char* in, - int isUnix, int flags) -{ - /* Start with the length of the original argument, plus one for - either a terminating null or a separating space. */ - int size = (int)strlen(in) + 1; - - /* String iterator. */ - const char* c; - - /* Keep track of how many backslashes have been encountered in a row. */ - int windows_backslashes = 0; - - /* Scan the string for characters that require escaping or quoting. */ - for(c=in; *c; ++c) - { - /* Look for $(MAKEVAR) syntax if requested. */ - if(flags & kwsysSystem_Shell_Flag_AllowMakeVariables) - { - /* Skip over the make variable references if any are present. */ - c = kwsysSystem_Shell__SkipMakeVariables(c); - - /* Stop if we have reached the end of the string. */ - if(!*c) - { - break; - } - } - - /* Check whether this character needs escaping for the shell. */ - if(isUnix) - { - /* On Unix a few special characters need escaping even inside a - quoted argument. */ - if(*c == '\\' || *c == '"' || *c == '`' || *c == '$') - { - /* This character needs a backslash to escape it. */ - ++size; - } - } - else if(flags & kwsysSystem_Shell_Flag_EchoWindows) - { - /* On Windows the built-in command shell echo never needs escaping. */ - } - else - { - /* On Windows only backslashes and double-quotes need escaping. */ - if(*c == '\\') - { - /* Found a backslash. It may need to be escaped later. */ - ++windows_backslashes; - } - else if(*c == '"') - { - /* Found a double-quote. We need to escape it and all - immediately preceding backslashes. */ - size += windows_backslashes + 1; - windows_backslashes = 0; - } - else - { - /* Found another character. This eliminates the possibility - that any immediately preceding backslashes will be - escaped. */ - windows_backslashes = 0; - } - } - - /* Check whether this character needs escaping for a make tool. */ - if(*c == '$') - { - if(flags & kwsysSystem_Shell_Flag_Make) - { - /* In Makefiles a dollar is written $$ so we need one extra - character. */ - ++size; - } - else if(flags & kwsysSystem_Shell_Flag_VSIDE) - { - /* In a VS IDE a dollar is written "$" so we need two extra - characters. */ - size += 2; - } - } - else if(*c == '#') - { - if((flags & kwsysSystem_Shell_Flag_Make) && - (flags & kwsysSystem_Shell_Flag_WatcomWMake)) - { - /* In Watcom WMake makefiles a pound is written $# so we need - one extra character. */ - ++size; - } - } - else if(*c == '%') - { - if((flags & kwsysSystem_Shell_Flag_VSIDE) || - ((flags & kwsysSystem_Shell_Flag_Make) && - ((flags & kwsysSystem_Shell_Flag_MinGWMake) || - (flags & kwsysSystem_Shell_Flag_NMake)))) - { - /* In the VS IDE, NMake, or MinGW make a percent is written %% - so we need one extra characters. */ - size += 1; - } - } - else if(*c == ';') - { - if(flags & kwsysSystem_Shell_Flag_VSIDE) - { - /* In a VS IDE a semicolon is written ";" so we need two extra - characters. */ - size += 2; - } - } - } - - /* Check whether the argument needs surrounding quotes. */ - if(kwsysSystem_Shell__ArgumentNeedsQuotes(in, isUnix, flags)) - { - /* Surrounding quotes are needed. Allocate space for them. */ - if((flags & kwsysSystem_Shell_Flag_WatcomQuote) && (isUnix)) - { - size += 2; - } - size += 2; - - /* We must escape all ending backslashes when quoting on windows. */ - size += windows_backslashes; - } - - return size; -} - -/*--------------------------------------------------------------------------*/ -static char* kwsysSystem_Shell__GetArgument(const char* in, char* out, - int isUnix, int flags) -{ - /* String iterator. */ - const char* c; - - /* Keep track of how many backslashes have been encountered in a row. */ - int windows_backslashes = 0; - - /* Whether the argument must be quoted. */ - int needQuotes = kwsysSystem_Shell__ArgumentNeedsQuotes(in, isUnix, flags); - if(needQuotes) - { - /* Add the opening quote for this argument. */ - if(flags & kwsysSystem_Shell_Flag_WatcomQuote) - { - if(isUnix) - { - *out++ = '"'; - } - *out++ = '\''; - } - else - { - *out++ = '"'; - } - } - - /* Scan the string for characters that require escaping or quoting. */ - for(c=in; *c; ++c) - { - /* Look for $(MAKEVAR) syntax if requested. */ - if(flags & kwsysSystem_Shell_Flag_AllowMakeVariables) - { - const char* skip = kwsysSystem_Shell__SkipMakeVariables(c); - if(skip != c) - { - /* Copy to the end of the make variable references. */ - while(c != skip) - { - *out++ = *c++; - } - - /* The make variable reference eliminates any escaping needed - for preceding backslashes. */ - windows_backslashes = 0; - - /* Stop if we have reached the end of the string. */ - if(!*c) - { - break; - } - } - } - - /* Check whether this character needs escaping for the shell. */ - if(isUnix) - { - /* On Unix a few special characters need escaping even inside a - quoted argument. */ - if(*c == '\\' || *c == '"' || *c == '`' || *c == '$') - { - /* This character needs a backslash to escape it. */ - *out++ = '\\'; - } - } - else if(flags & kwsysSystem_Shell_Flag_EchoWindows) - { - /* On Windows the built-in command shell echo never needs escaping. */ - } - else - { - /* On Windows only backslashes and double-quotes need escaping. */ - if(*c == '\\') - { - /* Found a backslash. It may need to be escaped later. */ - ++windows_backslashes; - } - else if(*c == '"') - { - /* Found a double-quote. Escape all immediately preceding - backslashes. */ - while(windows_backslashes > 0) - { - --windows_backslashes; - *out++ = '\\'; - } - - /* Add the backslash to escape the double-quote. */ - *out++ = '\\'; - } - else - { - /* We encountered a normal character. This eliminates any - escaping needed for preceding backslashes. */ - windows_backslashes = 0; - } - } - - /* Check whether this character needs escaping for a make tool. */ - if(*c == '$') - { - if(flags & kwsysSystem_Shell_Flag_Make) - { - /* In Makefiles a dollar is written $$. The make tool will - replace it with just $ before passing it to the shell. */ - *out++ = '$'; - *out++ = '$'; - } - else if(flags & kwsysSystem_Shell_Flag_VSIDE) - { - /* In a VS IDE a dollar is written "$". If this is written in - an un-quoted argument it starts a quoted segment, inserts - the $ and ends the segment. If it is written in a quoted - argument it ends quoting, inserts the $ and restarts - quoting. Either way the $ is isolated from surrounding - text to avoid looking like a variable reference. */ - *out++ = '"'; - *out++ = '$'; - *out++ = '"'; - } - else - { - /* Otherwise a dollar is written just $. */ - *out++ = '$'; - } - } - else if(*c == '#') - { - if((flags & kwsysSystem_Shell_Flag_Make) && - (flags & kwsysSystem_Shell_Flag_WatcomWMake)) - { - /* In Watcom WMake makefiles a pound is written $#. The make - tool will replace it with just # before passing it to the - shell. */ - *out++ = '$'; - *out++ = '#'; - } - else - { - /* Otherwise a pound is written just #. */ - *out++ = '#'; - } - } - else if(*c == '%') - { - if((flags & kwsysSystem_Shell_Flag_VSIDE) || - ((flags & kwsysSystem_Shell_Flag_Make) && - ((flags & kwsysSystem_Shell_Flag_MinGWMake) || - (flags & kwsysSystem_Shell_Flag_NMake)))) - { - /* In the VS IDE, NMake, or MinGW make a percent is written %%. */ - *out++ = '%'; - *out++ = '%'; - } - else - { - /* Otherwise a percent is written just %. */ - *out++ = '%'; - } - } - else if(*c == ';') - { - if(flags & kwsysSystem_Shell_Flag_VSIDE) - { - /* In a VS IDE a semicolon is written ";". If this is written - in an un-quoted argument it starts a quoted segment, - inserts the ; and ends the segment. If it is written in a - quoted argument it ends quoting, inserts the ; and restarts - quoting. Either way the ; is isolated. */ - *out++ = '"'; - *out++ = ';'; - *out++ = '"'; - } - else - { - /* Otherwise a semicolon is written just ;. */ - *out++ = ';'; - } - } - else - { - /* Store this character. */ - *out++ = *c; - } - } - - if(needQuotes) - { - /* Add enough backslashes to escape any trailing ones. */ - while(windows_backslashes > 0) - { - --windows_backslashes; - *out++ = '\\'; - } - - /* Add the closing quote for this argument. */ - if(flags & kwsysSystem_Shell_Flag_WatcomQuote) - { - *out++ = '\''; - if(isUnix) - { - *out++ = '"'; - } - } - else - { - *out++ = '"'; - } - } - - /* Store a terminating null without incrementing. */ - *out = 0; - - return out; -} - -/*--------------------------------------------------------------------------*/ -char* kwsysSystem_Shell_GetArgumentForWindows(const char* in, - char* out, - int flags) -{ - return kwsysSystem_Shell__GetArgument(in, out, 0, flags); -} - -/*--------------------------------------------------------------------------*/ -char* kwsysSystem_Shell_GetArgumentForUnix(const char* in, - char* out, - int flags) -{ - return kwsysSystem_Shell__GetArgument(in, out, 1, flags); -} - -/*--------------------------------------------------------------------------*/ -int kwsysSystem_Shell_GetArgumentSizeForWindows(const char* in, int flags) -{ - return kwsysSystem_Shell__GetArgumentSize(in, 0, flags); -} - -/*--------------------------------------------------------------------------*/ -int kwsysSystem_Shell_GetArgumentSizeForUnix(const char* in, int flags) -{ - return kwsysSystem_Shell__GetArgumentSize(in, 1, flags); -} - /*--------------------------------------------------------------------------*/ static int kwsysSystem__AppendByte(char* local, char** begin, char** end, diff --git a/Source/kwsys/System.h.in b/Source/kwsys/System.h.in index f21bf0d..3f3d3f4 100644 --- a/Source/kwsys/System.h.in +++ b/Source/kwsys/System.h.in @@ -24,28 +24,6 @@ #endif #if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS # define kwsysSystem_Parse_CommandForUnix kwsys_ns(System_Parse_CommandForUnix) -# define kwsysSystem_Shell_GetArgumentForWindows kwsys_ns(System_Shell_GetArgumentForWindows) -# define kwsysSystem_Shell_GetArgumentForUnix kwsys_ns(System_Shell_GetArgumentForUnix) -# define kwsysSystem_Shell_GetArgumentSizeForWindows kwsys_ns(System_Shell_GetArgumentSizeForWindows) -# define kwsysSystem_Shell_GetArgumentSizeForUnix kwsys_ns(System_Shell_GetArgumentSizeForUnix) -# define kwsysSystem_Shell_Flag_e kwsys_ns(System_Shell_Flag_e) -# define kwsysSystem_Shell_Flag_Make kwsys_ns(System_Shell_Flag_Make) -# define kwsysSystem_Shell_Flag_VSIDE kwsys_ns(System_Shell_Flag_VSIDE) -# define kwsysSystem_Shell_Flag_EchoWindows kwsys_ns(System_Shell_Flag_EchoWindows) -# define kwsysSystem_Shell_Flag_WatcomWMake kwsys_ns(System_Shell_Flag_WatcomWMake) -# define kwsysSystem_Shell_Flag_MinGWMake kwsys_ns(System_Shell_Flag_MinGWMake) -# define kwsysSystem_Shell_Flag_NMake kwsys_ns(System_Shell_Flag_NMake) -# define kwsysSystem_Shell_Flag_AllowMakeVariables kwsys_ns(System_Shell_Flag_AllowMakeVariables) -# define kwsysSystem_Shell_Flag_WatcomQuote kwsys_ns(System_Shell_Flag_WatcomQuote) -#endif - -#ifdef __VMS -#define @KWSYS_NAMESPACE@System_Shell_GetArgumentForUnix \ - @KWSYS_NAMESPACE@System_Shell_UnixGA -#define @KWSYS_NAMESPACE@System_Shell_GetArgumentSizeForUnix \ - @KWSYS_NAMESPACE@System_Shell_UnixGAS -#define @KWSYS_NAMESPACE@System_Shell_GetArgumentForWindows \ - @KWSYS_NAMESPACE@System_Shell_WindowsGA #endif #if defined(__cplusplus) @@ -54,69 +32,6 @@ extern "C" #endif /** - * Transform the given command line argument for use in a Windows or - * Unix shell. Returns a pointer to the end of the command line - * argument in the provided output buffer. Flags may be passed to - * modify the generated quoting and escape sequences to work under - * alternative environments. - */ -kwsysEXPORT char* kwsysSystem_Shell_GetArgumentForWindows(const char* in, - char* out, - int flags); -kwsysEXPORT char* kwsysSystem_Shell_GetArgumentForUnix(const char* in, - char* out, - int flags); - -/** - * Compute the size of the buffer required to store the output from - * kwsysSystem_Shell_GetArgumentForWindows or - * kwsysSystem_Shell_GetArgumentForUnix. The flags passed must be - * identical between the two calls. - */ -kwsysEXPORT int kwsysSystem_Shell_GetArgumentSizeForWindows(const char* in, - int flags); -kwsysEXPORT int kwsysSystem_Shell_GetArgumentSizeForUnix(const char* in, - int flags); - -/** - * Flags to pass to kwsysSystem_Shell_GetArgumentForWindows or - * kwsysSystem_Shell_GetArgumentForUnix. These modify the generated - * quoting and escape sequences to work under alternative - * environments. - */ -enum kwsysSystem_Shell_Flag_e -{ - /** The target shell is in a makefile. */ - kwsysSystem_Shell_Flag_Make = (1<<0), - - /** The target shell is in a VS project file. Do not use with - Shell_Flag_Make. */ - kwsysSystem_Shell_Flag_VSIDE = (1<<1), - - /** In a windows shell the argument is being passed to "echo". */ - kwsysSystem_Shell_Flag_EchoWindows = (1<<2), - - /** The target shell is in a Watcom WMake makefile. */ - kwsysSystem_Shell_Flag_WatcomWMake = (1<<3), - - /** The target shell is in a MinGW Make makefile. */ - kwsysSystem_Shell_Flag_MinGWMake = (1<<4), - - /** The target shell is in a NMake makefile. */ - kwsysSystem_Shell_Flag_NMake = (1<<5), - - /** Make variable reference syntax $(MAKEVAR) should not be escaped - to allow a build tool to replace it. Replacement values - containing spaces, quotes, backslashes, or other - non-alphanumeric characters that have significance to some makes - or shells produce undefined behavior. */ - kwsysSystem_Shell_Flag_AllowMakeVariables = (1<<6), - - /** The target shell quoting uses extra single Quotes for Watcom tools. */ - kwsysSystem_Shell_Flag_WatcomQuote = (1<<7) -}; - -/** * Parse a unix-style command line string into separate arguments. * * On success, returns a pointer to an array of pointers to individual @@ -148,19 +63,6 @@ kwsysEXPORT char** kwsysSystem_Parse_CommandForUnix(const char* command, # undef kwsysEXPORT # if !defined(KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS # undef kwsysSystem_Parse_CommandForUnix -# undef kwsysSystem_Shell_GetArgumentForWindows -# undef kwsysSystem_Shell_GetArgumentForUnix -# undef kwsysSystem_Shell_GetArgumentSizeForWindows -# undef kwsysSystem_Shell_GetArgumentSizeForUnix -# undef kwsysSystem_Shell_Flag_e -# undef kwsysSystem_Shell_Flag_Make -# undef kwsysSystem_Shell_Flag_VSIDE -# undef kwsysSystem_Shell_Flag_EchoWindows -# undef kwsysSystem_Shell_Flag_WatcomWMake -# undef kwsysSystem_Shell_Flag_MinGWMake -# undef kwsysSystem_Shell_Flag_NMake -# undef kwsysSystem_Shell_Flag_AllowMakeVariables -# undef kwsysSystem_Shell_Flag_WatcomQuote # endif #endif @@ -248,6 +248,7 @@ CMAKE_CXX_SOURCES="\ cmCommandArgumentLexer \ cmCommandArgumentParser \ cmCommandArgumentParserHelper \ + cmCommonTargetGenerator \ cmCPackPropertiesGenerator \ cmDefinitions \ cmDepends \ @@ -276,8 +277,10 @@ CMAKE_CXX_SOURCES="\ cmGeneratorExpressionNode \ cmGeneratorExpressionParser \ cmGeneratorExpression \ + cmGlobalCommonGenerator \ cmGlobalGenerator \ cmInstallDirectoryGenerator \ + cmLocalCommonGenerator \ cmLocalGenerator \ cmInstalledFile \ cmInstallGenerator \ |