Skip to content

Commit c082b7f

Browse files
committed
Extend fortran standard to other compilers
1 parent c38c1dd commit c082b7f

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

CMakeLists.txt

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,25 @@ option(FLIBCPP_USE_SWIG "Regenerate source files using SWIG" ${FLIBCPP_DEV})
2828
# FLAGS
2929
#---------------------------------------------------------------------------#
3030

31+
# Fortran standard
32+
set(FLIBCPP_FORTRAN_STD "03" CACHE STRING
33+
"Fortran standard for compiling generated code (options: 03/08/15/18)")
34+
if (FLIBCPP_FORTRAN_STD AND NOT FLIBCPP_FORTRAN_STD STREQUAL "none")
35+
if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
36+
set(_FLIBCPP_STD_FLAGS "-std=f20${FLIBCPP_FORTRAN_STD}")
37+
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
38+
set(_FLIBCPP_STD_FLAGS "-stand ${FLIBCPP_FORTRAN_STD}")
39+
else()
40+
message(WARNING "Fortran standard flags are not known for "
41+
"compilier '${CMAKE_Fortran_COMPILER_ID}': ignoring"
42+
"FLIBCPP_FORTRAN_STD=${FLIBCPP_FORTRAN_STD}. Configure with "
43+
"the FFLAGS environment variable or explicitly specify "
44+
"CMAKE_Fortran_FLAGS")
45+
set(_FLIBCPP_STD_FLAGS "none" CACHE FORCE STRING "")
46+
endif()
47+
endif()
48+
49+
# Build type
3150
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
3251
if (FLIBCPP_DEV)
3352
set(_CMAKE_BUILD_TYPE "Debug")
@@ -38,9 +57,6 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
3857
set(CMAKE_BUILD_TYPE "${_CMAKE_BUILD_TYPE}" CACHE STRING "Build type" FORCE)
3958
endif()
4059

41-
set(FLIBCPP_FORTRAN_STD "f2003" CACHE STRING
42-
"Fortran standard for compiling generated code")
43-
4460
#---------------------------------------------------------------------------#
4561
# MODULES TO LOAD
4662
#---------------------------------------------------------------------------#
@@ -100,7 +116,6 @@ else()
100116
endif()
101117
endif()
102118

103-
104119
set(FLIBCPP_VERSION_CPP "${CMAKE_CURRENT_BINARY_DIR}/flibcpp_version.cpp")
105120
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/flibcpp_version.cpp.in"
106121
"${FLIBCPP_VERSION_CPP}" @ONLY)
@@ -166,11 +181,9 @@ function(flibcpp_add_module name)
166181
PRIVATE
167182
cxx_std_11
168183
)
169-
170-
if (FLIBCPP_FORTRAN_STD AND CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
171-
# Compile Fortran code with given standard
184+
if (_FLIBCPP_STD_FLAGS)
172185
target_compile_options(${name}
173-
PUBLIC $<$<COMPILE_LANGUAGE:Fortran>:-std=${FLIBCPP_FORTRAN_STD}>
186+
PUBLIC $<$<COMPILE_LANGUAGE:Fortran>:${_FLIBCPP_STD_FLAGS}>
174187
)
175188
endif()
176189

0 commit comments

Comments
 (0)