-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
208 lines (176 loc) · 6.99 KB
/
CMakeLists.txt
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# ------------------------------------------------------------------------ #
# DOCUMENTATION:
# ------------------------------------------------------------------------ #
#
# Command line options:
# MPI=YES ! defaults to NO
# MAX_RANK=<max array rank for generated code>
# ! defaults to 5 or
# ! ${PFUNIT_MAX_ARRAY_RANK}
#
# Usage:
# cmake -DMPI=YES <path to source>
#
# ------------------------------------------------------------------------ #
INCLUDE(CMakeForceCompiler)
cmake_minimum_required(VERSION 3.0)
cmake_policy(SET CMP0048 NEW)
project (pFUnit
VERSION 3.1.1
LANGUAGES Fortran)
#enable_language (Fortran)
# MESSAGE(ENV{PFUNIT}:"$ENV{PFUNIT}")
# set (ENV_PFUNIT "$ENV{PFUNIT}")
# MESSAGE(OK:"${ENV_PFUNIT}")
# OPTION(INSTALL_PATH "Use PFUNIT for development" "$ENV{PFUNIT}")
# OPTION(INSTALL_PATH "Use PFUNIT for development" "${ENV_PFUNIT}")
OPTION(INSTALL_PATH "Use PFUNIT for development" OFF)
IF(NOT INSTALL_PATH)
IF(DEFINED ENV{PFUNIT})
set (INSTALL_PATH "$ENV{PFUNIT}")
ELSE()
MESSAGE("** WARNING: Install path not found! Please set PFUNIT or use -DINSTALL_PATH=...")
ENDIF()
ENDIF()
IF(NOT DEFINED ENV{PFUNIT})
MESSAGE("++ Remember to set the environment variable PFUNIT to the install directory!")
MESSAGE("++ Example: export PFUNIT=${INSTALL_PATH}")
ENDIF()
IF( NOT $ENV{PFUNIT} STREQUAL INSTALL_PATH )
MESSAGE("** WARNING: Environment variable PFUNIT not equal to INSTALL_PATH.")
MESSAGE("** Found: PFUNIT=$ENV{PFUNIT}")
ENDIF()
MESSAGE("-- Installing to INSTALL_PATH: ${INSTALL_PATH}")
OPTION(MAX_RANK "Maximum array rank for generated code." NO)
IF(NOT MAX_RANK)
# Remove PFUNIT_MAX_RANK in version 4.
IF(DEFINED ENV{PFUNIT_MAX_RANK})
SET (MAX_RANK "$ENV{PFUNIT_MAX_RANK}")
# Promote following to primary in version 4.
ELSEIF(DEFINED ENV{PFUNIT_MAX_ARRAY_RANK})
SET (MAX_RANK "$ENV{PFUNIT_MAX_ARRAY_RANK}")
ELSE()
SET (MAX_RANK 5)
ENDIF()
ENDIF()
OPTION(MPI "Use MPI for parallel runs" NO)
OPTION(FIND_MPI "Attempt to automatically find MPI information" YES)
OPTION(MPI_USE_MPIEXEC "Use CMake's FindMPI to find mpiexec" NO)
OPTION(OPENMP "Use OPENMP for parallel runs" NO)
# The following sets robust to "ON".
OPTION(ROBUST "Build robust test runner" YES)
# If the user specifies this on the command line (or equivalently, in the
# CMake cache), we take them at their word and do not attempt any kind of
# autodetection.
set(OPENMP_FLAGS "OPENMP_FLAGS-NOTFOUND"
CACHE STRING "OpenMP flags for the Fortran compiler.")
if (MPI)
add_definitions(-DUSE_MPI)
if (FIND_MPI)
find_package(MPI REQUIRED)
add_definitions(${MPI_Fortran_COMPILE_FLAGS})
include_directories(${MPI_Fortran_INCLUDE_PATH})
endif()
message( STATUS "MPI enabled")
endif()
# 2014-0807 MLR MAX_RANK needed for code generation, not here.
#if (MAX_RANK)
# add_definitions(-DMAX_RANK=${MAX_RANK})
#endif()
if (ROBUST)
add_definitions(-DBUILD_ROBUST)
endif()
if (${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel")
if (UNIX)
execute_process (COMMAND ifort --version
OUTPUT_VARIABLE INTEL_COMPILER_VERSION)
string (REGEX MATCH "([0-9]+)"
NUM_VERSION ${INTEL_COMPILER_VERSION})
if ("${NUM_VERSION}" STREQUAL "13")
add_definitions(-DINTEL_13)
endif ()
if ("${NUM_VERSION}" STREQUAL "16")
add_definitions(-DINTEL_16)
endif ()
endif ()
#Use ifort
#There seems to be no easy way to determine the compiler version on Windows
#since it isn't necessary defined in the PATH. As a workaround, assume version
#different to 13 if exectuing ifort doesn't give any results
if(NOT "${INTEL_COMPILER_VERSION}" STREQUAL "")
string (REGEX MATCH "([0-9]+)"
NUM_VERSION ${INTEL_COMPILER_VERSION})
if("${NUM_VERSION}" STREQUAL "13")
add_definitions(-DINTEL_13)
endif()
if("${NUM_VERSION}" STREQUAL "16")
add_definitions(-DINTEL_16)
endif()
endif()
add_definitions(-DIntel)
if (WIN32)
set(CMAKE_Fortran_FLAGS
"${CMAKE_Fortran_FLAGS_DEBUG} -Od -check:uninit -check:bounds -traceback -assume:realloc_lhs ${CMAKE_Fortran_FLAGS}"
)
else (WIN32)
set(CMAKE_Fortran_FLAGS
"${CMAKE_Fortran_FLAGS_DEBUG} -O0 -check uninit -check bounds -check pointers -check stack -traceback -assume realloc_lhs ${CMAKE_Fortran_FLAGS}"
)
endif (WIN32)
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL GNU)
# Use Gfortran
add_definitions(-DGNU)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_DEBUG} -O0 -fbounds-check")
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL NAG)
# use nagfor
add_definitions(-DNAG)
# Strong checking (-C=all breaks 6.0, but later releases will include it.
# set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_DEBUG} -O0 -f2003 -w=uda -gline -fpp -C=all -fpp")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_DEBUG} -O0 -f2003 -w=uda -gline -fpp -C=present -fpp")
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL XL)
# Use XLF.
add_definitions(-DIBM)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_DEBUG} -O0 -WF,-qfpp -C")
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL PGI)
# Use PGI.
add_definitions(-DPGI)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_DEBUG} -O0 -g -traceback -Mallocatable=03 -Mbounds -Mchkfpstk -Mchkstk")
else()
message( FATAL_ERROR "Unrecognized compiler. Please use ifort, gfortran, gfortran-mp-4.8, PGI, or nagfor" )
endif()
# Fortran OpenMP support is not yet integrated into the CMake distribution.
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/include/cmake/Modules/")
if (OPENMP)
# find_package(OpenMP_Fortran REQUIRED)
# if(OPENMP_FORTRAN_FOUND)
# set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}")
# set(CMAKE_Fortran_LINKER_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}")
# message( STATUS "OpenMP enabled")
# endif()
if (OPENMP_FLAGS)
set(OpenMP_Fortran_FLAGS "${OPENMP_FLAGS}")
else()
find_package(OpenMP_Fortran REQUIRED)
endif()
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}")
set(CMAKE_Fortran_LINKER_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}")
message( STATUS "OpenMP enabled")
endif()
set(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS "")
set(CMAKE_SKIP_RPATH ON)
add_subdirectory (source)
add_subdirectory (tests)
add_subdirectory (include)
add_subdirectory (bin)
# Packaging
include (cmake/packaging.cmake)
# Create the pFUnitConfig.cmake and pFUnitConfigVersion files
configure_file(cmake/pFUnitConfig.cmake.in
"${PROJECT_BINARY_DIR}/pFUnitConfig.cmake" @ONLY)
configure_file(cmake/pFUnitConfigVersion.cmake.in
"${PROJECT_BINARY_DIR}/pFUnitConfigVersion.cmake" @ONLY)
# Install the pFUnitConfig.cmake and pFUnitConfigVersion.cmake
install(FILES
"${PROJECT_BINARY_DIR}/pFUnitConfig.cmake"
"${PROJECT_BINARY_DIR}/pFUnitConfigVersion.cmake"
DESTINATION . )