diff options
author | Brad King <brad.king@kitware.com> | 2020-05-22 14:34:53 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2020-05-22 14:35:10 (GMT) |
commit | 62816ff88c6d1bd8d1c00de5ed448ee915d69e00 (patch) | |
tree | 6f1eb5d7c8b7deee02da84d309b446d5f6f38db5 /Tests | |
parent | 1b0049680b09872f01f714c8dcb1ed3c5c21da25 (diff) | |
parent | 3888de23daca814d66a40642d3e369a5c4747131 (diff) | |
download | CMake-62816ff88c6d1bd8d1c00de5ed448ee915d69e00.zip CMake-62816ff88c6d1bd8d1c00de5ed448ee915d69e00.tar.gz CMake-62816ff88c6d1bd8d1c00de5ed448ee915d69e00.tar.bz2 |
Merge topic 'fortran-preprocess-property'
3888de23da Ninja: Skip Fortran preprocessing if Fortran_PREPROCESS is OFF
66c4e87282 Ninja: Add helper functions to generate Fortran build
5cca1ec893 Ninja: Add helper functions to generate Fortran preprocess rule
b0a6161190 Fortran: Add Fortran_PREPROCESS property
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4659
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/FortranOnly/CMakeLists.txt | 43 | ||||
-rw-r--r-- | Tests/FortranOnly/no_preprocess_source_fpp.fpp | 3 | ||||
-rw-r--r-- | Tests/FortranOnly/no_preprocess_source_lower.f | 3 | ||||
-rw-r--r-- | Tests/FortranOnly/no_preprocess_source_upper.F | 3 | ||||
-rw-r--r-- | Tests/FortranOnly/no_preprocess_target_fpp.fpp | 3 | ||||
-rw-r--r-- | Tests/FortranOnly/no_preprocess_target_lower.f | 3 | ||||
-rw-r--r-- | Tests/FortranOnly/no_preprocess_target_upper.F | 3 | ||||
-rw-r--r-- | Tests/FortranOnly/preprocess2.f | 4 | ||||
-rw-r--r-- | Tests/FortranOnly/preprocess3.f | 4 |
9 files changed, 69 insertions, 0 deletions
diff --git a/Tests/FortranOnly/CMakeLists.txt b/Tests/FortranOnly/CMakeLists.txt index 4327c2f..d24df2d 100644 --- a/Tests/FortranOnly/CMakeLists.txt +++ b/Tests/FortranOnly/CMakeLists.txt @@ -116,3 +116,46 @@ if(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel") set_property(TARGET IntelIfDef PROPERTY Fortran_FORMAT FIXED) target_compile_definitions(IntelIfDef PRIVATE SOME_DEF) endif() + +# Skip these tests if compiler/version doesn't have preprocessing flags +if((CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" AND CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 4.4) + OR (CMAKE_Fortran_COMPILER_ID STREQUAL "XL" AND CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 15.1.6)) + set(test_pp_flags 0) +else() + set(test_pp_flags 1) +endif() + +if(test_pp_flags) + # Test that we can always preprocess a target + add_executable(preprocess_target preprocess2.f) + set_property(TARGET preprocess_target PROPERTY Fortran_PREPROCESS ON) + + # Test that we can preprocess a single source file + add_executable(preprocess_source preprocess3.f) + set_property(SOURCE preprocess3.f PROPERTY Fortran_PREPROCESS ON) +endif() + +# Test that neither the compiler nor CMake performs unnecessary preprocessing. +add_library(no_preprocess_target_lower STATIC no_preprocess_target_lower.f) +target_compile_options(no_preprocess_target_lower PRIVATE -DINTEGER=nonsense) +set_property(TARGET no_preprocess_target_lower PROPERTY Fortran_PREPROCESS OFF) +add_library(no_preprocess_source_lower STATIC no_preprocess_source_lower.f) +target_compile_options(no_preprocess_source_lower PRIVATE -DINTEGER=nonsense) +set_property(SOURCE no_preprocess_source_lower.f PROPERTY Fortran_PREPROCESS OFF) + +# Test that we can explicitly not preprocess a target or source. +# This will not work on certain compilers due to either missing a +# "don't preprocess" flag, or due to choice of file extension. +if(test_pp_flags AND NOT CMAKE_Fortran_COMPILER_ID MATCHES "(Flang|NAG|PGI|SunPro|XL)") + add_library(no_preprocess_target STATIC no_preprocess_target_upper.F) + target_compile_options(no_preprocess_target PRIVATE -DINTEGER=nonsense) + add_library(no_preprocess_source STATIC no_preprocess_source_upper.F) + target_compile_options(no_preprocess_source PRIVATE -DINTEGER=nonsense) + if(NOT CMAKE_Fortran_COMPILER_ID STREQUAL "Cray" + AND NOT "${CMAKE_Fortran_COMPILER_ID};${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "Intel;MSVC") + target_sources(no_preprocess_target PRIVATE no_preprocess_target_fpp.fpp) + target_sources(no_preprocess_source PRIVATE no_preprocess_source_fpp.fpp) + endif() + set_property(TARGET no_preprocess_target PROPERTY Fortran_PREPROCESS OFF) + set_property(SOURCE no_preprocess_source_upper.F no_preprocess_source_fpp.fpp PROPERTY Fortran_PREPROCESS OFF) +endif() diff --git a/Tests/FortranOnly/no_preprocess_source_fpp.fpp b/Tests/FortranOnly/no_preprocess_source_fpp.fpp new file mode 100644 index 0000000..8e48902 --- /dev/null +++ b/Tests/FortranOnly/no_preprocess_source_fpp.fpp @@ -0,0 +1,3 @@ + SUBROUTINE NOPREPROCESS_SOURCE_FPP + INTEGER F + END diff --git a/Tests/FortranOnly/no_preprocess_source_lower.f b/Tests/FortranOnly/no_preprocess_source_lower.f new file mode 100644 index 0000000..3b08782 --- /dev/null +++ b/Tests/FortranOnly/no_preprocess_source_lower.f @@ -0,0 +1,3 @@ + SUBROUTINE NOPREPROCESS_SOURCE_LOWER + INTEGER F + END diff --git a/Tests/FortranOnly/no_preprocess_source_upper.F b/Tests/FortranOnly/no_preprocess_source_upper.F new file mode 100644 index 0000000..02485c9 --- /dev/null +++ b/Tests/FortranOnly/no_preprocess_source_upper.F @@ -0,0 +1,3 @@ + SUBROUTINE NOPREPROCESS_SOURCE_UPPER + INTEGER F + END diff --git a/Tests/FortranOnly/no_preprocess_target_fpp.fpp b/Tests/FortranOnly/no_preprocess_target_fpp.fpp new file mode 100644 index 0000000..f9e6e3b --- /dev/null +++ b/Tests/FortranOnly/no_preprocess_target_fpp.fpp @@ -0,0 +1,3 @@ + SUBROUTINE NOPREPROCESS_TARGET_FPP + INTEGER F + END diff --git a/Tests/FortranOnly/no_preprocess_target_lower.f b/Tests/FortranOnly/no_preprocess_target_lower.f new file mode 100644 index 0000000..ea23a70 --- /dev/null +++ b/Tests/FortranOnly/no_preprocess_target_lower.f @@ -0,0 +1,3 @@ + SUBROUTINE NOPREPROCESS_TARGET_LOWER + INTEGER F + END diff --git a/Tests/FortranOnly/no_preprocess_target_upper.F b/Tests/FortranOnly/no_preprocess_target_upper.F new file mode 100644 index 0000000..34ee04d --- /dev/null +++ b/Tests/FortranOnly/no_preprocess_target_upper.F @@ -0,0 +1,3 @@ + SUBROUTINE NOPREPROCESS_TARGET_UPPER + INTEGER F + END diff --git a/Tests/FortranOnly/preprocess2.f b/Tests/FortranOnly/preprocess2.f new file mode 100644 index 0000000..6595d62 --- /dev/null +++ b/Tests/FortranOnly/preprocess2.f @@ -0,0 +1,4 @@ +#define int INTEGER + PROGRAM PREPRO + int f + END diff --git a/Tests/FortranOnly/preprocess3.f b/Tests/FortranOnly/preprocess3.f new file mode 100644 index 0000000..6595d62 --- /dev/null +++ b/Tests/FortranOnly/preprocess3.f @@ -0,0 +1,4 @@ +#define int INTEGER + PROGRAM PREPRO + int f + END |