From 1e519df0259677df67b5e7d21e1f189d655ddbd3 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Thu, 15 Oct 2020 08:46:03 -0400 Subject: CheckSource{Runs,Compiles}: Fix default Fortran source extension In commit 357e2ef429 (CheckSoureRuns: Add a unified way to check if a source runs, 2020-09-14, v3.19.0-rc1~118^2), the default Fortran source file extension was accidentally changed from `.F90` to `.F`. Fix that. In commit 10ae907de0 (CheckSoureCompiles: Add a unified way to check if a source compiles, 2020-09-14, v3.19.0-rc1~118^2~1), the default Fortran source extension was correctly preserved as `.F`, but `.F90` is a better default both for consistency and modern usage. Use that for direct calls to the `check_source_compiles` macro. Update our original `check_fortran_source_compiles` implementation to use `.F` by default as it did before. Fixes: #21307 --- Modules/CheckFortranSourceCompiles.cmake | 4 +++- Modules/CheckFortranSourceRuns.cmake | 4 +++- Modules/CheckSourceCompiles.cmake | 9 ++++++--- Modules/CheckSourceRuns.cmake | 11 +++++++---- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Modules/CheckFortranSourceCompiles.cmake b/Modules/CheckFortranSourceCompiles.cmake index 2bcc343..169b829 100644 --- a/Modules/CheckFortranSourceCompiles.cmake +++ b/Modules/CheckFortranSourceCompiles.cmake @@ -90,5 +90,7 @@ include_guard(GLOBAL) include(CheckSourceCompiles) macro(CHECK_Fortran_SOURCE_COMPILES SOURCE VAR) - check_source_compiles(Fortran "${SOURCE}" ${VAR} ${ARGN}) + # Pass the SRC_EXT we used by default historically. + # A user-provided SRC_EXT argument in ARGN will override ours. + check_source_compiles(Fortran "${SOURCE}" ${VAR} SRC_EXT "F" ${ARGN}) endmacro() diff --git a/Modules/CheckFortranSourceRuns.cmake b/Modules/CheckFortranSourceRuns.cmake index 29f4a98..5276709 100644 --- a/Modules/CheckFortranSourceRuns.cmake +++ b/Modules/CheckFortranSourceRuns.cmake @@ -86,5 +86,7 @@ include_guard(GLOBAL) include(CheckSourceRuns) macro(CHECK_Fortran_SOURCE_RUNS SOURCE VAR) - check_source_runs(Fortran "${SOURCE}" ${VAR} ${ARGN}) + # Pass the SRC_EXT we used by default historically. + # A user-provided SRC_EXT argument in ARGN will override ours. + check_source_runs(Fortran "${SOURCE}" ${VAR} SRC_EXT "F90" ${ARGN}) endmacro() diff --git a/Modules/CheckSourceCompiles.cmake b/Modules/CheckSourceCompiles.cmake index 08fc153..4ed9a5c 100644 --- a/Modules/CheckSourceCompiles.cmake +++ b/Modules/CheckSourceCompiles.cmake @@ -94,7 +94,7 @@ function(CHECK_SOURCE_COMPILES _lang _source _var) set(_lang_ext "cu") elseif(_lang STREQUAL Fortran) set(_lang_textual "Fortran") - set(_lang_ext "F") + set(_lang_ext "F90") elseif(_lang STREQUAL ISPC) set(_lang_textual "ISPC") set(_lang_ext "ispc") @@ -121,8 +121,11 @@ function(CHECK_SOURCE_COMPILES _lang _source _var) foreach(arg ${ARGN}) if("${arg}" MATCHES "^(FAIL_REGEX|SRC_EXT)$") set(_key "${arg}") - elseif(_key) - list(APPEND _${_key} "${arg}") + elseif(_key STREQUAL "FAIL_REGEX") + list(APPEND _FAIL_REGEX "${arg}") + elseif(_key STREQUAL "SRC_EXT") + set(_SRC_EXT "${arg}") + set(_key "") else() message(FATAL_ERROR "Unknown argument:\n ${arg}\n") endif() diff --git a/Modules/CheckSourceRuns.cmake b/Modules/CheckSourceRuns.cmake index 20f3e1e..033793d 100644 --- a/Modules/CheckSourceRuns.cmake +++ b/Modules/CheckSourceRuns.cmake @@ -92,7 +92,7 @@ function(CHECK_SOURCE_RUNS _lang _source _var) set(_lang_ext "cu") elseif(_lang STREQUAL Fortran) set(_lang_textual "Fortran") - set(_lang_ext "F") + set(_lang_ext "F90") elseif(_lang STREQUAL OBJC) set(_lang_textual "Objective-C") set(_lang_ext "m") @@ -114,10 +114,13 @@ function(CHECK_SOURCE_RUNS _lang _source _var) set(_SRC_EXT) set(_key) foreach(arg ${ARGN}) - if("${arg}" MATCHES "^(SRC_EXT)$") + if("${arg}" MATCHES "^(FAIL_REGEX|SRC_EXT)$") set(_key "${arg}") - elseif(_key) - list(APPEND _${_key} "${arg}") + elseif(_key STREQUAL "FAIL_REGEX") + list(APPEND _FAIL_REGEX "${arg}") + elseif(_key STREQUAL "SRC_EXT") + set(_SRC_EXT "${arg}") + set(_key "") else() message(FATAL_ERROR "Unknown argument:\n ${arg}\n") endif() -- cgit v0.12 From c4c636cef59edabdbfe278ea037ac06ca7d09d35 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 15 Oct 2020 09:40:20 -0400 Subject: Tests: Add cases for CheckSource{Compiles,Runs} bad arguments --- Tests/RunCMake/CheckSourceCompiles/RunCMakeTest.cmake | 1 + Tests/RunCMake/CheckSourceCompiles/UnknownArgument-result.txt | 1 + Tests/RunCMake/CheckSourceCompiles/UnknownArgument-stderr.txt | 9 +++++++++ Tests/RunCMake/CheckSourceCompiles/UnknownArgument.cmake | 5 +++++ Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake | 1 + Tests/RunCMake/CheckSourceRuns/UnknownArgument-result.txt | 1 + Tests/RunCMake/CheckSourceRuns/UnknownArgument-stderr.txt | 9 +++++++++ Tests/RunCMake/CheckSourceRuns/UnknownArgument.cmake | 5 +++++ 8 files changed, 32 insertions(+) create mode 100644 Tests/RunCMake/CheckSourceCompiles/UnknownArgument-result.txt create mode 100644 Tests/RunCMake/CheckSourceCompiles/UnknownArgument-stderr.txt create mode 100644 Tests/RunCMake/CheckSourceCompiles/UnknownArgument.cmake create mode 100644 Tests/RunCMake/CheckSourceRuns/UnknownArgument-result.txt create mode 100644 Tests/RunCMake/CheckSourceRuns/UnknownArgument-stderr.txt create mode 100644 Tests/RunCMake/CheckSourceRuns/UnknownArgument.cmake diff --git a/Tests/RunCMake/CheckSourceCompiles/RunCMakeTest.cmake b/Tests/RunCMake/CheckSourceCompiles/RunCMakeTest.cmake index 22cb466..6e9088f 100644 --- a/Tests/RunCMake/CheckSourceCompiles/RunCMakeTest.cmake +++ b/Tests/RunCMake/CheckSourceCompiles/RunCMakeTest.cmake @@ -2,6 +2,7 @@ include(RunCMake) run_cmake(NotEnabledLanguage) run_cmake(NonExistentLanguage) +run_cmake(UnknownArgument) run_cmake(CheckCSourceCompiles) run_cmake(CheckCXXSourceCompiles) diff --git a/Tests/RunCMake/CheckSourceCompiles/UnknownArgument-result.txt b/Tests/RunCMake/CheckSourceCompiles/UnknownArgument-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CheckSourceCompiles/UnknownArgument-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CheckSourceCompiles/UnknownArgument-stderr.txt b/Tests/RunCMake/CheckSourceCompiles/UnknownArgument-stderr.txt new file mode 100644 index 0000000..eed581a --- /dev/null +++ b/Tests/RunCMake/CheckSourceCompiles/UnknownArgument-stderr.txt @@ -0,0 +1,9 @@ +^CMake Error at [^ +]*/Modules/CheckSourceCompiles.cmake:[0-9]+ \(message\): + Unknown argument: + + BAD + +Call Stack \(most recent call first\): + UnknownArgument.cmake:[0-9]+ \(check_source_compiles\) + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/CheckSourceCompiles/UnknownArgument.cmake b/Tests/RunCMake/CheckSourceCompiles/UnknownArgument.cmake new file mode 100644 index 0000000..3b861da --- /dev/null +++ b/Tests/RunCMake/CheckSourceCompiles/UnknownArgument.cmake @@ -0,0 +1,5 @@ + +enable_language (C) +include(CheckSourceCompiles) + +check_source_compiles(C "int main() {return 0;}" SHOULD_BUILD SRC_EXT C BAD) diff --git a/Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake b/Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake index b27b08d..c99ac8b 100644 --- a/Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake +++ b/Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake @@ -2,6 +2,7 @@ include(RunCMake) run_cmake(NotEnabledLanguage) run_cmake(NonExistentLanguage) +run_cmake(UnknownArgument) run_cmake(CheckCSourceRuns) run_cmake(CheckCXXSourceRuns) diff --git a/Tests/RunCMake/CheckSourceRuns/UnknownArgument-result.txt b/Tests/RunCMake/CheckSourceRuns/UnknownArgument-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CheckSourceRuns/UnknownArgument-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CheckSourceRuns/UnknownArgument-stderr.txt b/Tests/RunCMake/CheckSourceRuns/UnknownArgument-stderr.txt new file mode 100644 index 0000000..8ae1ea1 --- /dev/null +++ b/Tests/RunCMake/CheckSourceRuns/UnknownArgument-stderr.txt @@ -0,0 +1,9 @@ +^CMake Error at [^ +]*/Modules/CheckSourceRuns.cmake:[0-9]+ \(message\): + Unknown argument: + + BAD + +Call Stack \(most recent call first\): + UnknownArgument.cmake:[0-9]+ \(check_source_runs\) + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/CheckSourceRuns/UnknownArgument.cmake b/Tests/RunCMake/CheckSourceRuns/UnknownArgument.cmake new file mode 100644 index 0000000..6e50fa7 --- /dev/null +++ b/Tests/RunCMake/CheckSourceRuns/UnknownArgument.cmake @@ -0,0 +1,5 @@ + +enable_language (C) +include(CheckSourceRuns) + +check_source_runs(C "int main() {return 0;}" SHOULD_BUILD SRC_EXT C BAD) -- cgit v0.12