summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2008-01-18 00:58:01 (GMT)
committerBrad King <brad.king@kitware.com>2008-01-18 00:58:01 (GMT)
commit8d1d5500c8cb7ebabce73777c79c33074e679ab5 (patch)
tree27c37321fe8aff93398c9309462eb4f05b735778
parent7f589c9f23ee64ca0d36e81a02a70a87bc7fbbbe (diff)
downloadCMake-8d1d5500c8cb7ebabce73777c79c33074e679ab5.zip
CMake-8d1d5500c8cb7ebabce73777c79c33074e679ab5.tar.gz
CMake-8d1d5500c8cb7ebabce73777c79c33074e679ab5.tar.bz2
ENH: Enable use of COMPILE_DEFINITIONS property for Fortran sources.
-rw-r--r--Modules/CMakeFortranInformation.cmake2
-rw-r--r--Modules/Platform/Windows-ifort.cmake2
-rw-r--r--Source/cmDependsFortran.cxx21
-rw-r--r--Source/cmLocalGenerator.cxx32
-rw-r--r--Source/cmLocalGenerator.h5
-rw-r--r--Source/cmLocalUnixMakefileGenerator3.cxx47
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
- "<CMAKE_Fortran_COMPILER> -o <OBJECT> <FLAGS> -c <SOURCE>")
+ "<CMAKE_Fortran_COMPILER> -o <OBJECT> <DEFINES> <FLAGS> -c <SOURCE>")
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} <LINK_FLAGS> /o
# compile a C++ file into an object file
SET(CMAKE_Fortran_COMPILE_OBJECT
- "<CMAKE_Fortran_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO} /fpp /Fo<OBJECT> <FLAGS> -c <SOURCE>${CMAKE_END_TEMP_FILE}")
+ "<CMAKE_Fortran_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO} /fpp /Fo<OBJECT> <DEFINES> <FLAGS> -c <SOURCE>${CMAKE_END_TEMP_FILE}")
SET(CMAKE_COMPILE_RESOURCE "rc <FLAGS> /fo<OBJECT> <SOURCE>")
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<std::string>::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<std::string> 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<std::string> 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<std::string>::const_iterator di = defines.begin();
+ di != defines.end(); ++di)
+ {
+ cmakefileStream
+ << " " << this->EscapeForCMake(di->c_str()) << "\n";
+ }
+ cmakefileStream
+ << " )\n";
+ }
}
//----------------------------------------------------------------------------