Ninja: Avoid preprocessing twice with explicit Fortran_PREPROCESS
Fix spurious warnings from gfortran+Ninja for preprocessing. Fixes: #23248
This commit is contained in:
parent
352ea99bba
commit
6b4885b58b
@ -101,7 +101,8 @@ void cmCommonTargetGenerator::AppendFortranFormatFlags(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cmCommonTargetGenerator::AppendFortranPreprocessFlags(
|
void cmCommonTargetGenerator::AppendFortranPreprocessFlags(
|
||||||
std::string& flags, cmSourceFile const& source)
|
std::string& flags, cmSourceFile const& source,
|
||||||
|
PreprocessFlagsRequired requires_pp)
|
||||||
{
|
{
|
||||||
const std::string srcpp = source.GetSafeProperty("Fortran_PREPROCESS");
|
const std::string srcpp = source.GetSafeProperty("Fortran_PREPROCESS");
|
||||||
cmOutputConverter::FortranPreprocess preprocess =
|
cmOutputConverter::FortranPreprocess preprocess =
|
||||||
@ -114,7 +115,9 @@ void cmCommonTargetGenerator::AppendFortranPreprocessFlags(
|
|||||||
const char* var = nullptr;
|
const char* var = nullptr;
|
||||||
switch (preprocess) {
|
switch (preprocess) {
|
||||||
case cmOutputConverter::FortranPreprocess::Needed:
|
case cmOutputConverter::FortranPreprocess::Needed:
|
||||||
var = "CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON";
|
if (requires_pp == PreprocessFlagsRequired::YES) {
|
||||||
|
var = "CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON";
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case cmOutputConverter::FortranPreprocess::NotNeeded:
|
case cmOutputConverter::FortranPreprocess::NotNeeded:
|
||||||
var = "CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF";
|
var = "CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF";
|
||||||
|
@ -46,8 +46,14 @@ protected:
|
|||||||
void AppendFortranFormatFlags(std::string& flags,
|
void AppendFortranFormatFlags(std::string& flags,
|
||||||
cmSourceFile const& source);
|
cmSourceFile const& source);
|
||||||
|
|
||||||
void AppendFortranPreprocessFlags(std::string& flags,
|
enum class PreprocessFlagsRequired
|
||||||
cmSourceFile const& source);
|
{
|
||||||
|
YES,
|
||||||
|
NO
|
||||||
|
};
|
||||||
|
void AppendFortranPreprocessFlags(
|
||||||
|
std::string& flags, cmSourceFile const& source,
|
||||||
|
PreprocessFlagsRequired requires_pp = PreprocessFlagsRequired::YES);
|
||||||
|
|
||||||
virtual void AddIncludeFlags(std::string& flags, std::string const& lang,
|
virtual void AddIncludeFlags(std::string& flags, std::string const& lang,
|
||||||
const std::string& config) = 0;
|
const std::string& config) = 0;
|
||||||
|
@ -216,7 +216,8 @@ std::string cmNinjaTargetGenerator::ComputeFlagsForObject(
|
|||||||
// Add Fortran format flags.
|
// Add Fortran format flags.
|
||||||
if (language == "Fortran") {
|
if (language == "Fortran") {
|
||||||
this->AppendFortranFormatFlags(flags, *source);
|
this->AppendFortranFormatFlags(flags, *source);
|
||||||
this->AppendFortranPreprocessFlags(flags, *source);
|
this->AppendFortranPreprocessFlags(flags, *source,
|
||||||
|
PreprocessFlagsRequired::NO);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add source file specific flags.
|
// Add source file specific flags.
|
||||||
|
@ -129,6 +129,12 @@ if(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON AND
|
|||||||
add_executable(preprocess_target preprocess2.f)
|
add_executable(preprocess_target preprocess2.f)
|
||||||
set_property(TARGET preprocess_target PROPERTY Fortran_PREPROCESS ON)
|
set_property(TARGET preprocess_target PROPERTY Fortran_PREPROCESS ON)
|
||||||
|
|
||||||
|
if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
|
||||||
|
# gfortran might report spurious warnings if we include the
|
||||||
|
# preprocessing flags at the compilation stage
|
||||||
|
target_compile_options(preprocess_target PRIVATE -Wall -Werror)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Test that we can preprocess a single source file
|
# Test that we can preprocess a single source file
|
||||||
add_executable(preprocess_source preprocess3.f)
|
add_executable(preprocess_source preprocess3.f)
|
||||||
set_property(SOURCE preprocess3.f PROPERTY Fortran_PREPROCESS ON)
|
set_property(SOURCE preprocess3.f PROPERTY Fortran_PREPROCESS ON)
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#define int INTEGER
|
#define int INTEGER
|
||||||
|
! This single unmatched quote ' should not cause an error during compilation
|
||||||
PROGRAM PREPRO
|
PROGRAM PREPRO
|
||||||
int f
|
int f = 1
|
||||||
|
PRINT*, f
|
||||||
END
|
END
|
||||||
|
Loading…
Reference in New Issue
Block a user