CheckFortranSourceCompiles: Add support for custom source extension
Fortran compilers interpret the source extension to decide whether to preprocess and what language level to use by default.
This commit is contained in:
parent
86d2e4276d
commit
4d3874d5ad
|
@ -0,0 +1,6 @@
|
||||||
|
CheckFortranSourceCompiles-custom-ext
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
* The :module:`CheckFortranSourceCompiles` module macro
|
||||||
|
``CHECK_Fortran_SOURCE_COMPILES`` gained a ``SRC_EXT`` option
|
||||||
|
to specify a custom test Fortran source file extension.
|
|
@ -4,7 +4,8 @@
|
||||||
#
|
#
|
||||||
# Check if given Fortran source compiles and links into an executable::
|
# Check if given Fortran source compiles and links into an executable::
|
||||||
#
|
#
|
||||||
# CHECK_Fortran_SOURCE_COMPILES(<code> <var> [FAIL_REGEX <fail-regex>])
|
# CHECK_Fortran_SOURCE_COMPILES(<code> <var> [FAIL_REGEX <fail-regex>]
|
||||||
|
# [SRC_EXT <ext>])
|
||||||
#
|
#
|
||||||
# The arguments are:
|
# The arguments are:
|
||||||
#
|
#
|
||||||
|
@ -15,6 +16,8 @@
|
||||||
# Will be created as an internal cache variable.
|
# Will be created as an internal cache variable.
|
||||||
# ``FAIL_REGEX <fail-regex>``
|
# ``FAIL_REGEX <fail-regex>``
|
||||||
# Fail if test output matches this regex.
|
# Fail if test output matches this regex.
|
||||||
|
# ``SRC_EXT <ext>``
|
||||||
|
# Use source extension ``.<ext>`` instead of the default ``.F``.
|
||||||
#
|
#
|
||||||
# The following variables may be set before calling this macro to modify
|
# The following variables may be set before calling this macro to modify
|
||||||
# the way the check is run::
|
# the way the check is run::
|
||||||
|
@ -43,9 +46,10 @@
|
||||||
macro(CHECK_Fortran_SOURCE_COMPILES SOURCE VAR)
|
macro(CHECK_Fortran_SOURCE_COMPILES SOURCE VAR)
|
||||||
if(NOT DEFINED "${VAR}")
|
if(NOT DEFINED "${VAR}")
|
||||||
set(_FAIL_REGEX)
|
set(_FAIL_REGEX)
|
||||||
|
set(_SRC_EXT)
|
||||||
set(_key)
|
set(_key)
|
||||||
foreach(arg ${ARGN})
|
foreach(arg ${ARGN})
|
||||||
if("${arg}" MATCHES "^(FAIL_REGEX)$")
|
if("${arg}" MATCHES "^(FAIL_REGEX|SRC_EXT)$")
|
||||||
set(_key "${arg}")
|
set(_key "${arg}")
|
||||||
elseif(_key)
|
elseif(_key)
|
||||||
list(APPEND _${_key} "${arg}")
|
list(APPEND _${_key} "${arg}")
|
||||||
|
@ -53,6 +57,9 @@ macro(CHECK_Fortran_SOURCE_COMPILES SOURCE VAR)
|
||||||
message(FATAL_ERROR "Unknown argument:\n ${arg}\n")
|
message(FATAL_ERROR "Unknown argument:\n ${arg}\n")
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
if(NOT _SRC_EXT)
|
||||||
|
set(_SRC_EXT F)
|
||||||
|
endif()
|
||||||
set(MACRO_CHECK_FUNCTION_DEFINITIONS
|
set(MACRO_CHECK_FUNCTION_DEFINITIONS
|
||||||
"-D${VAR} ${CMAKE_REQUIRED_FLAGS}")
|
"-D${VAR} ${CMAKE_REQUIRED_FLAGS}")
|
||||||
if(CMAKE_REQUIRED_LIBRARIES)
|
if(CMAKE_REQUIRED_LIBRARIES)
|
||||||
|
@ -67,7 +74,7 @@ macro(CHECK_Fortran_SOURCE_COMPILES SOURCE VAR)
|
||||||
else()
|
else()
|
||||||
set(CHECK_Fortran_SOURCE_COMPILES_ADD_INCLUDES)
|
set(CHECK_Fortran_SOURCE_COMPILES_ADD_INCLUDES)
|
||||||
endif()
|
endif()
|
||||||
file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.F"
|
file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.${_SRC_EXT}"
|
||||||
"${SOURCE}\n")
|
"${SOURCE}\n")
|
||||||
|
|
||||||
if(NOT CMAKE_REQUIRED_QUIET)
|
if(NOT CMAKE_REQUIRED_QUIET)
|
||||||
|
@ -75,7 +82,7 @@ macro(CHECK_Fortran_SOURCE_COMPILES SOURCE VAR)
|
||||||
endif()
|
endif()
|
||||||
try_compile(${VAR}
|
try_compile(${VAR}
|
||||||
${CMAKE_BINARY_DIR}
|
${CMAKE_BINARY_DIR}
|
||||||
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.F
|
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.${_SRC_EXT}
|
||||||
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
|
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
|
||||||
${CHECK_Fortran_SOURCE_COMPILES_ADD_LIBRARIES}
|
${CHECK_Fortran_SOURCE_COMPILES_ADD_LIBRARIES}
|
||||||
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
|
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
|
||||||
|
|
Loading…
Reference in New Issue