Skip to content

Commit

Permalink
Only set Fortran arguments for Fortran compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
awvwgk committed Mar 18, 2022
1 parent 05a7d69 commit 936eae6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 25 deletions.
32 changes: 7 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
cmake_minimum_required(VERSION 3.14.0)

# Include overwrites before setting up the project
set(CMAKE_USER_MAKE_RULES_OVERRIDE ${CMAKE_CURRENT_SOURCE_DIR}/config/DefaultFlags.cmake)

project(fortran_stdlib
LANGUAGES Fortran
DESCRIPTION "Community driven and agreed upon de facto standard library for Fortran"
Expand All @@ -22,31 +26,9 @@ include(${PROJECT_SOURCE_DIR}/cmake/stdlib.cmake)
# --- CMake specific configuration and package data export
add_subdirectory(config)

# --- compiler options
if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
if(CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 9.0)
message(FATAL_ERROR "GCC Version 9 or newer required")
endif()
add_compile_options(-fimplicit-none)
add_compile_options(-ffree-line-length-132)
add_compile_options(-fno-range-check) # Needed for gfortran 9 and
# earlier for hash functions
add_compile_options(-Wall)
add_compile_options(-Wextra)
add_compile_options(-Wimplicit-procedure)
# -pedantic-errors triggers a false positive for optional arguments of elemental functions,
# see test_optval and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95446
if(CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 11.0)
add_compile_options(-pedantic-errors)
endif()
add_compile_options(-std=f2018)
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
if(WIN32)
set(fortran_flags /stand:f18 /warn:declarations,general,usage,interfaces,unused)
else()
set(fortran_flags -stand f18 -warn declarations,general,usage,interfaces,unused)
endif()
add_compile_options("$<$<COMPILE_LANGUAGE:Fortran>:${fortran_flags}>")
# --- compiler selection
if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU AND CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 9.0)
message(FATAL_ERROR "GCC Version 9 or newer required")
endif()

# --- compiler feature checks
Expand Down
44 changes: 44 additions & 0 deletions config/DefaultFlags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
set(
CMAKE_Fortran_FLAGS_RELEASE_INIT
)
set(
CMAKE_Fortran_FLAGS_DEBUG_INIT
"-fimplicit-none"
"-ffree-line-length-132"
"-fno-range-check"
"-Wall"
"-Wextra"
"-Wimplicit-procedure"
"-std=f2018"
)
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
if(WIN32)
set(
CMAKE_Fortran_FLAGS_RELEASE_INIT
)
set(
CMAKE_Fortran_FLAGS_DEBUG_INIT
"/stand:f18"
"/warn:declarations,general,usage,interfaces,unused"
)
else()
set(
CMAKE_Fortran_FLAGS_RELEASE_INIT
)
set(
CMAKE_Fortran_FLAGS_DEBUG_INIT
"-stand f18"
"-warn declarations,general,usage,interfaces,unused"
)
endif()
else()
set(
CMAKE_Fortran_FLAGS_RELEASE_INIT
)
set(
CMAKE_Fortran_FLAGS_DEBUG_INIT
)
endif()
string(REPLACE ";" " " CMAKE_Fortran_FLAGS_RELEASE_INIT "${CMAKE_Fortran_FLAGS_RELEASE_INIT}")
string(REPLACE ";" " " CMAKE_Fortran_FLAGS_DEBUG_INIT "${CMAKE_Fortran_FLAGS_DEBUG_INIT}")

0 comments on commit 936eae6

Please sign in to comment.