diff options
| author | Brad King <brad.king@kitware.com> | 2022-02-25 13:07:22 (GMT) |
|---|---|---|
| committer | Kitware Robot <kwrobot@kitware.com> | 2022-02-25 13:07:36 (GMT) |
| commit | d4ad5fcd5d2303c1ac89c699e59a770e201c817b (patch) | |
| tree | a88346eea86816bbe7361508304ae93d3e8bbdc0 | |
| parent | c515ac41ee5a7249b9816d2cceb36cebf828a7f7 (diff) | |
| parent | 6b4885b58b8204153919d068363f5fe42fef6ec4 (diff) | |
| download | CMake-d4ad5fcd5d2303c1ac89c699e59a770e201c817b.zip CMake-d4ad5fcd5d2303c1ac89c699e59a770e201c817b.tar.gz CMake-d4ad5fcd5d2303c1ac89c699e59a770e201c817b.tar.bz2 | |
Merge topic 'ninja-gfortran-preprocess'
6b4885b58b Ninja: Avoid preprocessing twice with explicit Fortran_PREPROCESS
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !7008
| -rw-r--r-- | Source/cmCommonTargetGenerator.cxx | 7 | ||||
| -rw-r--r-- | Source/cmCommonTargetGenerator.h | 10 | ||||
| -rw-r--r-- | Source/cmNinjaTargetGenerator.cxx | 3 | ||||
| -rw-r--r-- | Tests/FortranOnly/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | Tests/FortranOnly/preprocess2.f | 4 |
5 files changed, 24 insertions, 6 deletions
diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx index 8d5ce7e..129ef4b 100644 --- a/Source/cmCommonTargetGenerator.cxx +++ b/Source/cmCommonTargetGenerator.cxx @@ -101,7 +101,8 @@ void cmCommonTargetGenerator::AppendFortranFormatFlags( } 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"); cmOutputConverter::FortranPreprocess preprocess = @@ -114,7 +115,9 @@ void cmCommonTargetGenerator::AppendFortranPreprocessFlags( const char* var = nullptr; switch (preprocess) { case cmOutputConverter::FortranPreprocess::Needed: - var = "CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON"; + if (requires_pp == PreprocessFlagsRequired::YES) { + var = "CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON"; + } break; case cmOutputConverter::FortranPreprocess::NotNeeded: var = "CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF"; diff --git a/Source/cmCommonTargetGenerator.h b/Source/cmCommonTargetGenerator.h index baa36c9..5aba1c6 100644 --- a/Source/cmCommonTargetGenerator.h +++ b/Source/cmCommonTargetGenerator.h @@ -46,8 +46,14 @@ protected: void AppendFortranFormatFlags(std::string& flags, cmSourceFile const& source); - void AppendFortranPreprocessFlags(std::string& flags, - cmSourceFile const& source); + enum class PreprocessFlagsRequired + { + 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, const std::string& config) = 0; diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 191b428..dd7d244 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -216,7 +216,8 @@ std::string cmNinjaTargetGenerator::ComputeFlagsForObject( // Add Fortran format flags. if (language == "Fortran") { this->AppendFortranFormatFlags(flags, *source); - this->AppendFortranPreprocessFlags(flags, *source); + this->AppendFortranPreprocessFlags(flags, *source, + PreprocessFlagsRequired::NO); } // Add source file specific flags. diff --git a/Tests/FortranOnly/CMakeLists.txt b/Tests/FortranOnly/CMakeLists.txt index ee47da4..b07c214 100644 --- a/Tests/FortranOnly/CMakeLists.txt +++ b/Tests/FortranOnly/CMakeLists.txt @@ -129,6 +129,12 @@ if(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON AND add_executable(preprocess_target preprocess2.f) 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 add_executable(preprocess_source preprocess3.f) set_property(SOURCE preprocess3.f PROPERTY Fortran_PREPROCESS ON) diff --git a/Tests/FortranOnly/preprocess2.f b/Tests/FortranOnly/preprocess2.f index 6595d62..3b332c4 100644 --- a/Tests/FortranOnly/preprocess2.f +++ b/Tests/FortranOnly/preprocess2.f @@ -1,4 +1,6 @@ #define int INTEGER + ! This single unmatched quote ' should not cause an error during compilation PROGRAM PREPRO - int f + int f = 1 + PRINT*, f END |
