From 8d1d5500c8cb7ebabce73777c79c33074e679ab5 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 17 Jan 2008 19:58:01 -0500 Subject: ENH: Enable use of COMPILE_DEFINITIONS property for Fortran sources. --- Modules/CMakeFortranInformation.cmake | 2 +- Modules/Platform/Windows-ifort.cmake | 2 +- Source/cmDependsFortran.cxx | 21 ++++---------- Source/cmLocalGenerator.cxx | 32 ++++++++++++++++++++++ Source/cmLocalGenerator.h | 5 +++- Source/cmLocalUnixMakefileGenerator3.cxx | 47 ++++++++++++++++++++++++++------ 6 files changed, 83 insertions(+), 26 deletions(-) diff --git a/Modules/CMakeFortranInformation.cmake b/Modules/CMakeFortranInformation.cmake index 09880c1..b4db0e3 100644 --- a/Modules/CMakeFortranInformation.cmake +++ b/Modules/CMakeFortranInformation.cmake @@ -124,7 +124,7 @@ ENDIF(NOT CMAKE_Fortran_CREATE_STATIC_LIBRARY) # compile a Fortran file into an object file IF(NOT CMAKE_Fortran_COMPILE_OBJECT) SET(CMAKE_Fortran_COMPILE_OBJECT - " -o -c ") + " -o -c ") ENDIF(NOT CMAKE_Fortran_COMPILE_OBJECT) # link a fortran program diff --git a/Modules/Platform/Windows-ifort.cmake b/Modules/Platform/Windows-ifort.cmake index 4c88910..7ea5581 100644 --- a/Modules/Platform/Windows-ifort.cmake +++ b/Modules/Platform/Windows-ifort.cmake @@ -19,7 +19,7 @@ SET(CMAKE_Fortran_CREATE_STATIC_LIBRARY "lib ${CMAKE_CL_NOLOGO} /o # compile a C++ file into an object file SET(CMAKE_Fortran_COMPILE_OBJECT - " ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO} /fpp /Fo -c ${CMAKE_END_TEMP_FILE}") + " ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO} /fpp /Fo -c ${CMAKE_END_TEMP_FILE}") SET(CMAKE_COMPILE_RESOURCE "rc /fo ") diff --git a/Source/cmDependsFortran.cxx b/Source/cmDependsFortran.cxx index 7a2f07c..1725c58 100644 --- a/Source/cmDependsFortran.cxx +++ b/Source/cmDependsFortran.cxx @@ -142,27 +142,18 @@ cmDependsFortran IncludePath(&includes), Internal(new cmDependsFortranInternals) { - // translate i.e. -DFOO=BAR to FOO and add it to the list of defined + // translate i.e. FOO=BAR to FOO and add it to the list of defined // preprocessor symbols - std::string def; for(std::vector::const_iterator it = definitions.begin(); it != definitions.end(); ++it) { - std::string::size_type match = it->find("-D"); - if(match != std::string::npos) + std::string def = *it; + std::string::size_type assignment = def.find("="); + if(assignment != std::string::npos) { - std::string::size_type assignment = it->find("="); - if(assignment != std::string::npos) - { - std::string::size_type length = assignment - (match+2); - def = it->substr(match+2, length); - } - else - { - def = it->substr(match+2); - } - this->PPDefinitions.push_back(def); + def = it->substr(0, assignment); } + this->PPDefinitions.push_back(def); } } diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 23179dc..66007d4 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2948,6 +2948,38 @@ std::string cmLocalGenerator::EscapeForShell(const char* str, bool makeVars, } //---------------------------------------------------------------------------- +std::string cmLocalGenerator::EscapeForCMake(const char* str) +{ + // Always double-quote the argument to take care of most escapes. + std::string result = "\""; + for(const char* c = str; *c; ++c) + { + if(*c == '"') + { + // Escape the double quote to avoid ending the argument. + result += "\\\""; + } + else if(*c == '$') + { + // Escape the dollar to avoid expanding variables. + result += "\\$"; + } + else if(*c == '\\') + { + // Escape the backslash to avoid other escapes. + result += "\\\\"; + } + else + { + // Other characters will be parsed correctly. + result += *c; + } + } + result += "\""; + return result; +} + +//---------------------------------------------------------------------------- std::string cmLocalGenerator::GetTargetDirectory(cmTarget const&) const { diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 721080e..25bedfc 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -227,7 +227,10 @@ public: /** Backwards-compatibility version of EscapeForShell. */ std::string EscapeForShellOldStyle(const char* str); - + + /** Escape the given string as an argument in a CMake script. */ + std::string EscapeForCMake(const char* str); + /** Return the directories into which object files will be put. * There maybe more than one for fat binary systems like OSX. */ diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index adabd0a..8445a6c 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -1478,7 +1478,8 @@ cmLocalUnixMakefileGenerator3 else if(lang == "Fortran") { std::vector defines; - if(const char* c_defines = mf->GetDefinition("CMAKE_DEFINITIONS")) + if(const char* c_defines = + mf->GetDefinition("CMAKE_TARGET_DEFINITIONS")) { cmSystemTools::ExpandListArgument(c_defines, defines); } @@ -1844,13 +1845,43 @@ void cmLocalUnixMakefileGenerator3 } } - cmakefileStream - << "\n" - << "# Preprocessor definitions for this directory.\n" - << "SET(CMAKE_DEFINITIONS\n" - << " " << this->Makefile->GetDefineFlags() << "\n" - << " )\n"; - + // Build a list of preprocessor definitions for the target. + std::vector defines; + { + std::string defPropName = "COMPILE_DEFINITIONS_"; + defPropName += this->ConfigurationName; + if(const char* ddefs = this->Makefile->GetProperty("COMPILE_DEFINITIONS")) + { + cmSystemTools::ExpandListArgument(ddefs, defines); + } + if(const char* cdefs = target.GetProperty("COMPILE_DEFINITIONS")) + { + cmSystemTools::ExpandListArgument(cdefs, defines); + } + if(const char* dcdefs = this->Makefile->GetProperty(defPropName.c_str())) + { + cmSystemTools::ExpandListArgument(dcdefs, defines); + } + if(const char* ccdefs = target.GetProperty(defPropName.c_str())) + { + cmSystemTools::ExpandListArgument(ccdefs, defines); + } + } + if(!defines.empty()) + { + cmakefileStream + << "\n" + << "# Preprocessor definitions for this target.\n" + << "SET(CMAKE_TARGET_DEFINITIONS\n"; + for(std::vector::const_iterator di = defines.begin(); + di != defines.end(); ++di) + { + cmakefileStream + << " " << this->EscapeForCMake(di->c_str()) << "\n"; + } + cmakefileStream + << " )\n"; + } } //---------------------------------------------------------------------------- -- cgit v0.12