Skip to content

Commit ee4d105

Browse files
authored
Only set Fortran arguments for Fortran compiler (#637)
1 parent 05a7d69 commit ee4d105

File tree

2 files changed

+58
-25
lines changed

2 files changed

+58
-25
lines changed

CMakeLists.txt

+7-25
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
cmake_minimum_required(VERSION 3.14.0)
2+
3+
# Include overwrites before setting up the project
4+
set(CMAKE_USER_MAKE_RULES_OVERRIDE ${CMAKE_CURRENT_SOURCE_DIR}/config/DefaultFlags.cmake)
5+
26
project(fortran_stdlib
37
LANGUAGES Fortran
48
DESCRIPTION "Community driven and agreed upon de facto standard library for Fortran"
@@ -22,31 +26,9 @@ include(${PROJECT_SOURCE_DIR}/cmake/stdlib.cmake)
2226
# --- CMake specific configuration and package data export
2327
add_subdirectory(config)
2428

25-
# --- compiler options
26-
if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
27-
if(CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 9.0)
28-
message(FATAL_ERROR "GCC Version 9 or newer required")
29-
endif()
30-
add_compile_options(-fimplicit-none)
31-
add_compile_options(-ffree-line-length-132)
32-
add_compile_options(-fno-range-check) # Needed for gfortran 9 and
33-
# earlier for hash functions
34-
add_compile_options(-Wall)
35-
add_compile_options(-Wextra)
36-
add_compile_options(-Wimplicit-procedure)
37-
# -pedantic-errors triggers a false positive for optional arguments of elemental functions,
38-
# see test_optval and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95446
39-
if(CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 11.0)
40-
add_compile_options(-pedantic-errors)
41-
endif()
42-
add_compile_options(-std=f2018)
43-
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
44-
if(WIN32)
45-
set(fortran_flags /stand:f18 /warn:declarations,general,usage,interfaces,unused)
46-
else()
47-
set(fortran_flags -stand f18 -warn declarations,general,usage,interfaces,unused)
48-
endif()
49-
add_compile_options("$<$<COMPILE_LANGUAGE:Fortran>:${fortran_flags}>")
29+
# --- compiler selection
30+
if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU AND CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 9.0)
31+
message(FATAL_ERROR "GCC Version 9 or newer required")
5032
endif()
5133

5234
# --- compiler feature checks

config/DefaultFlags.cmake

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
2+
set(
3+
CMAKE_Fortran_FLAGS_INIT
4+
"-fimplicit-none"
5+
"-ffree-line-length-132"
6+
"-fno-range-check"
7+
)
8+
set(
9+
CMAKE_Fortran_FLAGS_RELEASE_INIT
10+
)
11+
set(
12+
CMAKE_Fortran_FLAGS_DEBUG_INIT
13+
"-Wall"
14+
"-Wextra"
15+
"-Wimplicit-procedure"
16+
"-std=f2018"
17+
)
18+
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
19+
set(
20+
CMAKE_Fortran_FLAGS_INIT
21+
)
22+
set(
23+
CMAKE_Fortran_FLAGS_RELEASE_INIT
24+
)
25+
if(WIN32)
26+
set(
27+
CMAKE_Fortran_FLAGS_DEBUG_INIT
28+
"/stand:f18"
29+
"/warn:declarations,general,usage,interfaces,unused"
30+
)
31+
else()
32+
set(
33+
CMAKE_Fortran_FLAGS_DEBUG_INIT
34+
"-stand f18"
35+
"-warn declarations,general,usage,interfaces,unused"
36+
)
37+
endif()
38+
else()
39+
set(
40+
CMAKE_Fortran_FLAGS_INIT
41+
)
42+
set(
43+
CMAKE_Fortran_FLAGS_RELEASE_INIT
44+
)
45+
set(
46+
CMAKE_Fortran_FLAGS_DEBUG_INIT
47+
)
48+
endif()
49+
string(REPLACE ";" " " CMAKE_Fortran_FLAGS_INIT "${CMAKE_Fortran_FLAGS_INIT}")
50+
string(REPLACE ";" " " CMAKE_Fortran_FLAGS_RELEASE_INIT "${CMAKE_Fortran_FLAGS_RELEASE_INIT}")
51+
string(REPLACE ";" " " CMAKE_Fortran_FLAGS_DEBUG_INIT "${CMAKE_Fortran_FLAGS_DEBUG_INIT}")

0 commit comments

Comments
 (0)