Skip to content

Commit 9462db6

Browse files
committed
cmake best practices compiler flags
1 parent f586880 commit 9462db6

File tree

2 files changed

+14
-37
lines changed

2 files changed

+14
-37
lines changed

README.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,8 @@ meson build
4242
meson test -C build
4343
```
4444

45-
## Compilers
46-
47-
### Intel oneAPI
48-
4945
[Intel oneAPI](https://www.scivision.dev/intel-oneapi-fortran-install)
5046
has complete Fortran 2018 support.
51-
Use Intel compilers (oneAPI or Parallel Studio) by:
52-
53-
* MacOS or Linux:
54-
55-
```sh
56-
cmake --preset=intel
57-
```
58-
* Windows
59-
60-
```sh
61-
cmake --preset=intelwin
62-
```
6347

6448
## Programs
6549

@@ -94,7 +78,6 @@ Each directory has its own README and examples.
9478
* [netcdf4fortran](https://github.com/scivision/netcdf4fortran)
9579
* [sparse-fortran](https://github.com/scivision/sparse-fortran)
9680

97-
9881
## Resources
9982

10083
### Fortran standards

cmake/compilers.cmake

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,21 @@ include(${CMAKE_CURRENT_LIST_DIR}/f03utf8.cmake)
3030
# -- compiler feature checks BEFORE setting flags to avoid intermittant failures in general
3131

3232
if(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
33-
if(WIN32)
34-
add_compile_options(/QxHost)
35-
string(APPEND CMAKE_Fortran_FLAGS " /traceback /heap-arrays")
36-
string(APPEND CMAKE_Fortran_FLAGS_DEBUG " /stand:f18 /warn")
37-
string(APPEND CMAKE_Fortran_FLAGS_DEBUG " /debug /check:all")
38-
else()
39-
add_compile_options(-xHost)
40-
string(APPEND CMAKE_Fortran_FLAGS " -traceback -heap-arrays")
41-
string(APPEND CMAKE_Fortran_FLAGS_DEBUG " -stand f18 -warn")
42-
string(APPEND CMAKE_Fortran_FLAGS_DEBUG " -debug extended -check all")
43-
endif()
33+
add_compile_options(
34+
$<IF:$<BOOL:${WIN32}>,/QxHost,-xHost>
35+
"$<$<COMPILE_LANGUAGE:Fortran>:-traceback;-heap-arrays>"
36+
"$<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<CONFIG:Debug>>:-warn;-debug extended;-check all>"
37+
)
4438
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
45-
# add_compile_options(-mtune=native -Wall)
46-
# if(CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 8)
47-
# string(APPEND CMAKE_Fortran_FLAGS " -std=f2018")
48-
# endif()
49-
50-
string(APPEND CMAKE_Fortran_FLAGS " -fimplicit-none")
51-
# string(APPEND CMAKE_Fortran_FLAGS " -Wrealloc-lhs") # not -Wrealloc-lhs-all which warns on character
52-
string(APPEND CMAKE_Fortran_FLAGS " -Werror=array-bounds -fcheck=all")
39+
40+
add_compile_options(-mtune=native -Wall
41+
"$<$<COMPILE_LANGUAGE:Fortran>:-fimplicit-none;-Werror=array-bounds;-fcheck=all>"
42+
)
43+
44+
# "$<$<COMPILE_LANGAUGE:Fortran>:-Wrealloc-lhs>" # not -Wrealloc-lhs-all which warns on character
5345
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL NAG)
5446
# https://www.nag.co.uk/nagware/np/r70_doc/manual/compiler_2_4.html#OPTIONS
55-
string(APPEND CMAKE_Fortran_FLAGS " -f2018 -C -colour -gline -nan -info -u")
47+
add_compile_options(
48+
"$<$<COMPILE_LANGUAGE:Fortran>:-f2018;-C;-colour;-gline;-nan;-info;-u>"
49+
)
5650
endif()

0 commit comments

Comments
 (0)