mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-07 14:20:06 -06:00
Merge topic 'fortran-INCLUDE-defines'
fb9da8e6f4 Ninja: Pass preprocessor definitions when compiling with Intel Fortran
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3764
This commit is contained in:
@@ -8,6 +8,8 @@ set(CMAKE_Fortran_MODDIR_FLAG "-module ")
|
||||
set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-fixed")
|
||||
set(CMAKE_Fortran_FORMAT_FREE_FLAG "-free")
|
||||
|
||||
set(CMAKE_Fortran_COMPILE_WITH_DEFINES 1)
|
||||
|
||||
set(CMAKE_Fortran_CREATE_PREPROCESSED_SOURCE "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
|
||||
set(CMAKE_Fortran_CREATE_ASSEMBLY_SOURCE "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
|
||||
|
||||
|
||||
@@ -108,6 +108,13 @@ bool cmNinjaTargetGenerator::UsePreprocessedSource(
|
||||
return lang == "Fortran";
|
||||
}
|
||||
|
||||
bool cmNinjaTargetGenerator::CompilePreprocessedSourceWithDefines(
|
||||
std::string const& lang) const
|
||||
{
|
||||
return this->Makefile->IsOn(
|
||||
cmStrCat("CMAKE_", lang, "_COMPILE_WITH_DEFINES"));
|
||||
}
|
||||
|
||||
std::string cmNinjaTargetGenerator::LanguageDyndepRule(
|
||||
const std::string& lang) const
|
||||
{
|
||||
@@ -458,12 +465,14 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
|
||||
vars.ObjectDir = "$OBJECT_DIR";
|
||||
vars.ObjectFileDir = "$OBJECT_FILE_DIR";
|
||||
|
||||
cmMakefile* mf = this->GetMakefile();
|
||||
|
||||
// For some cases we do an explicit preprocessor invocation.
|
||||
bool const explicitPP = this->NeedExplicitPreprocessing(lang);
|
||||
bool const compilePPWithDefines = this->UsePreprocessedSource(lang) &&
|
||||
this->CompilePreprocessedSourceWithDefines(lang);
|
||||
bool const needDyndep = this->NeedDyndep(lang);
|
||||
|
||||
cmMakefile* mf = this->GetMakefile();
|
||||
|
||||
std::string flags = "$FLAGS";
|
||||
|
||||
std::string responseFlag;
|
||||
@@ -517,9 +526,14 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
|
||||
// Preprocessing and compilation use the same flags.
|
||||
std::string ppFlags = flags;
|
||||
|
||||
// Move preprocessor definitions to the preprocessor rule.
|
||||
ppVars.Defines = vars.Defines;
|
||||
vars.Defines = "";
|
||||
if (!compilePPWithDefines) {
|
||||
// Move preprocessor definitions to the preprocessor rule.
|
||||
ppVars.Defines = vars.Defines;
|
||||
vars.Defines = "";
|
||||
} else {
|
||||
// Copy preprocessor definitions to the preprocessor rule.
|
||||
ppVars.Defines = vars.Defines;
|
||||
}
|
||||
|
||||
// Copy include directories to the preprocessor rule. The Fortran
|
||||
// compilation rule still needs them for the INCLUDE directive.
|
||||
@@ -1011,6 +1025,8 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
|
||||
ppBuild.RspFile = ppFileName + ".rsp";
|
||||
|
||||
bool const compilePP = this->UsePreprocessedSource(language);
|
||||
bool const compilePPWithDefines =
|
||||
compilePP && this->CompilePreprocessedSourceWithDefines(language);
|
||||
if (compilePP) {
|
||||
// Move compilation dependencies to the preprocessing build statement.
|
||||
std::swap(ppBuild.ExplicitDeps, objBuild.ExplicitDeps);
|
||||
@@ -1039,7 +1055,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
|
||||
this->LocalGenerator->AppendFlags(vars["FLAGS"], postFlag);
|
||||
}
|
||||
|
||||
if (compilePP) {
|
||||
if (compilePP && !compilePPWithDefines) {
|
||||
// Move preprocessor definitions to the preprocessor build statement.
|
||||
std::swap(ppBuild.Variables["DEFINES"], vars["DEFINES"]);
|
||||
} else {
|
||||
|
||||
@@ -70,6 +70,7 @@ protected:
|
||||
std::string LanguageDyndepRule(std::string const& lang) const;
|
||||
bool NeedDyndep(std::string const& lang) const;
|
||||
bool UsePreprocessedSource(std::string const& lang) const;
|
||||
bool CompilePreprocessedSourceWithDefines(std::string const& lang) const;
|
||||
|
||||
std::string OrderDependsTargetForTarget();
|
||||
|
||||
|
||||
@@ -112,3 +112,11 @@ if("${CMAKE_GENERATOR}" MATCHES "Makefile" AND CMAKE_MAKE_PROGRAM)
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Test that with Intel Fortran we always compile with preprocessor
|
||||
# defines even if splitting the preprocessing and compilation steps.
|
||||
if(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
|
||||
add_executable(IntelIfDef IntelIfDef.f)
|
||||
set_property(TARGET IntelIfDef PROPERTY Fortran_FORMAT FIXED)
|
||||
target_compile_definitions(IntelIfDef PRIVATE SOME_DEF)
|
||||
endif()
|
||||
|
||||
3
Tests/FortranOnly/IntelIfDef.f
Normal file
3
Tests/FortranOnly/IntelIfDef.f
Normal file
@@ -0,0 +1,3 @@
|
||||
INCLUDE 'IntelIfDef.inc'
|
||||
PROGRAM IntelIfDef
|
||||
END
|
||||
3
Tests/FortranOnly/IntelIfDef.inc
Normal file
3
Tests/FortranOnly/IntelIfDef.inc
Normal file
@@ -0,0 +1,3 @@
|
||||
CDEC$ IF .NOT. DEFINED(SOME_DEF)
|
||||
CDEC$ INCLUDE 'SOME_DEF not defined'
|
||||
CDEC$ END IF
|
||||
Reference in New Issue
Block a user