forked from CESM-Development/CMake_Fortran_utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Compilers.cmake
138 lines (117 loc) · 4.73 KB
/
Compilers.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# Flags for builds with different machines/compilers.
#
# This module is currently a catch-all for compiler-specific functionality
# needed by CESM. It defines OS and compiler CPP macros and CESM build
# types, as well as including the file containing CESM compiler flags, if
# necessary.
#
# There is also one function intended for CTest test writers, described
# below.
#
#==========================================================================
#
# define_Fortran_stop_failure
#
# Arguments:
# test_name - Name of a CTest test.
#
# Ensures that if the named test uses "STOP 1" to signal failure, that this
# is detected by CTest. Currently this is only necessary for NAG, which
# prints the stop code rather than using it as an error code.
#
#==========================================================================
#==========================================================================
# Copyright (c) 2013-2014, University Corporation for Atmospheric Research
#
# This software is distributed under a two-clause BSD license, with no
# warranties, express or implied. See the accompanying LICENSE file for
# details.
#==========================================================================
#=================================================
# Define OS and compiler macros.
#=================================================
# Define OS.
string(TOUPPER ${CMAKE_SYSTEM_NAME} os)
add_definitions(-D${os})
# Define CESM-compatible compiler names.
if(${CMAKE_Fortran_COMPILER_ID} STREQUAL NAG)
set(compiler_name nag)
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL GNU)
set(compiler_name gnu)
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL XL)
set(compiler_name ibm)
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL Intel)
set(compiler_name intel)
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL PGI)
set(compiler_name pgi)
endif()
# Define CPP macro for the compiler.
string(TOUPPER -DCPR${compiler_name} compiler_cppdef)
add_definitions(${compiler_cppdef})
#=================================================
# Utility functions.
#=================================================
# Add flags to space-separated list rather than normal CMake list.
function(add_flags list)
string(REPLACE ";" " " flags "${ARGN}")
set(${list} "${${list}} ${flags}" PARENT_SCOPE)
endfunction()
# Add configuration-specific preprocessor definitions.
function(add_config_definitions configuration)
get_directory_property(cppdefs COMPILE_DEFINITIONS_${configuration})
foreach(flag IN LISTS ARGN)
string(REPLACE "-D" "" def "${flag}")
list(APPEND cppdefs ${def})
endforeach()
set_directory_properties(PROPERTIES COMPILE_DEFINITIONS_${configuration}
"${cppdefs}")
endfunction()
#=================================================
# Build flags required to use pFUnit.
#=================================================
if(${CMAKE_Fortran_COMPILER_ID} STREQUAL Intel)
add_flags(CMAKE_Fortran_FLAGS -assume realloc_lhs)
endif()
#=================================================
# Add flags for debugging output.
#=================================================
# Define Fortran compiler flags.
# Add pretty output and extra warnings regardless of build type. However,
# don't set any options in the generic flags that would affect the
# generated binary, because we want to be able to get binaries that
# resemble what you get from the CESM flags.
if(${CMAKE_Fortran_COMPILER_ID} STREQUAL NAG)
add_flags(CMAKE_Fortran_FLAGS -strict95)
if(USE_COLOR)
add_flags(CMAKE_Fortran_FLAGS -colour)
endif()
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL GNU)
# Turn on warnings, but leave out uninitialized check as it was producing
# a lot of false positives.
add_flags(CMAKE_Fortran_FLAGS -Wall -Wextra -Wno-uninitialized)
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL XL)
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL Intel)
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL PGI)
endif()
# Define C flags, analogous to the above Fortran block.
if(CMAKE_C_COMPILER_LOADED)
if(${CMAKE_C_COMPILER_ID} STREQUAL GNU)
add_flags(CMAKE_C_FLAGS -Wall -Wextra -pedantic)
endif()
endif()
#=================================================
# Help CTest tests recognize when "stop X" is called with non-zero X.
#=================================================
# Detect "STOP" for CTest.
if(${CMAKE_Fortran_COMPILER_ID} STREQUAL NAG)
# NAG prints the stop code instead of yielding a non-zero return, so we
# have to use a regex to catch that.
function(define_Fortran_stop_failure test_name)
set_tests_properties(${test_name} PROPERTIES
FAIL_REGULAR_EXPRESSION "STOP: [1-9]")
endfunction(define_Fortran_stop_failure)
else()
# Usually, stop /= 0 is already detected with the return code.
function(define_Fortran_stop_failure test_name)
endfunction(define_Fortran_stop_failure)
endif()