Skip to content

Commit 936eae6

Browse files
committed
Only set Fortran arguments for Fortran compiler
1 parent 05a7d69 commit 936eae6

File tree

2 files changed

+51
-25
lines changed

2 files changed

+51
-25
lines changed

CMakeLists.txt

Lines changed: 7 additions & 25 deletions
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

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

0 commit comments

Comments
 (0)