ENH: Enable use of COMPILE_DEFINITIONS property for Fortran sources.

This commit is contained in:
Brad King 2008-01-17 19:58:01 -05:00
parent 7f589c9f23
commit 8d1d5500c8
6 changed files with 83 additions and 26 deletions

View File

@ -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

View File

@ -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>")

View File

@ -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);
}
}

View File

@ -2947,6 +2947,38 @@ std::string cmLocalGenerator::EscapeForShell(const char* str, bool makeVars,
return std::string(&arg[0]);
}
//----------------------------------------------------------------------------
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

View File

@ -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.
*/

View File

@ -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";
}
}
//----------------------------------------------------------------------------