-
Notifications
You must be signed in to change notification settings - Fork 14
/
CMakeLists.txt
249 lines (209 loc) · 8.14 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
###-------------------------------------------------------------------------###
cmake_minimum_required(VERSION 3.1) #... Specify the minimum version for CMake
###-------------------------------------------------------------------------###
if(NOT WIN32)
string(ASCII 27 Esc)
set(ColourReset "${Esc}[m")
set(ColourBold "${Esc}[1m")
set(Red "${Esc}[31m")
set(Green "${Esc}[32m")
set(Yellow "${Esc}[33m")
set(Blue "${Esc}[34m")
set(Magenta "${Esc}[35m")
set(Cyan "${Esc}[36m")
set(White "${Esc}[37m")
set(BoldRed "${Esc}[1;31m")
set(BoldGreen "${Esc}[1;32m")
set(BoldYellow "${Esc}[1;33m")
set(BoldBlue "${Esc}[1;34m")
set(BoldMagenta "${Esc}[1;35m")
set(BoldCyan "${Esc}[1;36m")
set(BoldWhite "${Esc}[1;37m")
endif()
###-------------------------------------------------------------------------###
set(COMPILE_LANGUAGE Fortran)
###-------------------------------------------------------------------------###
set(PROJECT_NAME Grid2Grid) #... Project Name
set(PROJECT_COMPILE_PATH ${CMAKE_HOME_DIRECTORY}) #... COMPILE_PATH
project(${PROJECT_NAME} ${COMPILE_LANGUAGE}) # PROJECT NAME
###-------------------------------------------------------------------------###
include(Grid2GridOptions.cmake)
#... Fortran Compiler
if (NOT DEFINED CMAKE_Fortran_COMPILER)
set(CMAKE_Fortran_COMPILER gfortran)
# set(CMAKE_Fortran_COMPILER ifort)
endif()
###-------------------------------------------------------------------------###
## GIT
# Get the current working branch
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND git log -1 --format=%H
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
add_definitions("-D__GIT_BRANCH__=\"${GIT_BRANCH}\"")
add_definitions("-D__GIT_COMMIT_HASH__=\"${GIT_COMMIT_HASH}\"")
###-------------------------------------------------------------------------###
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_COMPILE_PATH}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_COMPILE_PATH}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_COMPILE_PATH})
set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_COMPILE_PATH}/lib)
if ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "Intel")
if (WIN32)
set(CMAKE_Fortran_FLAGS "-fpp -traceback -heap-arrays /Qmkl:sequential")
set(CMAKE_Fortran_FLAGS_RELEASE "/O3 /QxHOST -traceback -heap-arrays")
else()
set(CMAKE_Fortran_FLAGS "-cpp -ipo -fPIC -O2 -xHOST -ipo -ip -traceback -check uninit -check bounds -heap-arrays -mkl=sequential")
endif()
add_definitions(-D_INTEL_FORTRAN_COMPILE_RULE_)
elseif("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
set(CMAKE_Fortran_FLAGS "-cpp -fPIC -O2 -march=corei7 -msse2 -funroll-loops -fno-protect-parens -ffast-math -fbounds-check")
add_definitions(-D_GNU_FORTRAN_COMPILE_RULE_)
endif()
option(BUILD_OF_LIB "Build <libGrid2Grid.so> in $FOAM_USER_LIBBIN" OFF)
set(GRID2GRID_LIB_OUT ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
if (BUILD_OF_LIB)
if (NOT "$ENV{FOAM_USER_LIBBIN}" STREQUAL "")
set(GRID2GRID_LIB_OUT $ENV{FOAM_USER_LIBBIN})
else()
message("${BoldRed} ")
message(" [ERROR] Not in OpenFOAM Environment... ")
message("${ColourReset} ${Green}")
message(" Wrong $FOAM_USER_LIBBIN path")
message("")
message(" $FOAM_USER_LIBBIN : " $ENV{FOAM_USER_LIBBIN})
message("${ColourReset} ")
message( FATAL_ERROR )
endif()
endif()
message("${Yellow}")
message(" GRID2GRID LIBRARY OUT PATH ")
message("${Green}")
message(" - GRID2GRID_LIB_OUT : " ${GRID2GRID_LIB_OUT})
message("${ColourReset}")
###-------------------------------------------------------------------------###
if ( NOT HDF5_LIB_PATH )
#... HDF5 library path ( /usr/local/lib/hdf5 is generated by soft link )
set(HDF5_LIB_PATH /usr/local/lib/hdf5/build/bin)
endif()
#... HDF5 library header file path
set(HDF5_INC_PATH ${HDF5_LIB_PATH}/static)
#... HDF5 LIBRARY FLAG (DO NOT CHANGE ORDER !)
set(HDF5_LIB_NAME
libhdf5_fortran.a
libhdf5_f90cstub.a
libhdf5.a
libszip.a
libz.a
)
if ( NOT USE_MKL)
if ( NOT FFTW3_LIB_PATH )
#...FFTW library path ( /usr/local/lib/libfftw3.a is generated by soft link )
set(FFTW3_LIB_PATH /usr/local/lib)
endif()
if (WIN32)
find_library(FFTW_LIB_FLAG NAMES fftw3.lib PATHS ${FFTW3_LIB_PATH} ${LIBRARY_DIRS})
else()
find_library(FFTW_LIB_FLAG NAMES libfftw3.a PATHS ${FFTW3_LIB_PATH} ${LIBRARY_DIRS})
endif()
if ("${FFTW_LIB_FLAG}" STREQUAL "FFTW_LIB_FLAG-NOTFOUND")
if (WIN32)
message("${BoldRed} [ERROR] library: fftw3.lib not found.")
else()
message("${BoldRed} [ERROR] library: libfftw3.a not found.")
endif()
message("${ColourReset} ${Green}")
message(" Wrong FFTW3 library path")
message("")
message(" FFTW3_LIB_PATH : " ${FFTW3_LIB_PATH})
message("${ColourReset} ")
message( FATAL_ERROR )
endif()
#... FFTW LIBRARY FLAG
get_filename_component(FFTW3_LIB_PATH ${FFTW_LIB_FLAG} PATH)
if (WIN32)
message("${Yellow} Found fftw3.lib:")
else()
message("${Yellow} Found libfftw3.a:")
endif()
message("")
message("${Green} - FFTW_LIB_FLAG : ${FFTW_LIB_FLAG}")
message("${Green} - FFTW3_LIB_PATH : ${FFTW3_LIB_PATH}")
endif()
###-------------------------------------------------------------------------###
### Check Library ###
###-------------------------------------------------------------------------###
set(HDF_LIBRARY "OFF" CACHE STRING "OFF")
message("${Yellow}")
message(" GRID2GRID EXTERNAL LIBRARY PATH ")
message("${Green}")
if (HDF_LIBRARY MATCHES "ON")
message(" - HDF5_LIB_PATH : " ${HDF5_LIB_PATH})
message(" - HDF5_INC_PATH : " ${HDF5_INC_PATH})
endif()
if ( NOT USE_MKL)
message(" - FFTW3_LIB_PATH : " ${FFTW3_LIB_PATH})
endif()
message("${ColourReset}")
if (HDF_LIBRARY MATCHES "ON")
#... Check HDF5 library existence and add library to HDF5_LIB_FLAG
foreach(LIB ${HDF5_LIB_NAME})
find_library(LIBEXIST NAMES ${LIB} PATHS ${HDF5_LIB_PATH})
if (NOT LIBEXIST)
message("${BoldYellow} [WARNING] library: " ${LIB} " not found. ${ColourReset}")
set(HDF_LIBRARY "OFF")
set(HDF5_INC_PATH "")
endif()
set(HDF5_LIB_FLAG ${HDF5_LIB_FLAG} ${HDF5_LIB_PATH}/${LIB})
endforeach()
message("${ColourReset}")
set(HDF5_LIB_FLAG ${HDF5_LIB_FLAG} -ldl -pthread)
add_definitions(-DENABLE_HDF5=${HDF_LIBRARY})
else()
set(HDF5_INC_PATH "")
endif()
message("${Green}")
message(" HDF LIBRARY STATUS : " ${HDF_LIBRARY})
message("${ColourReset}")
###-------------------------------------------------------------------------###
if ( NOT USE_MKL)
if (WIN32)
find_library(LIBEXIST NAMES fftw3.lib PATHS ${FFTW3_LIB_PATH})
else()
find_library(LIBEXIST NAMES libfftw3.a PATHS ${FFTW3_LIB_PATH})
endif()
if (NOT LIBEXIST)
message("${BoldRed} ")
if (WIN32)
message(" [ERROR] library: fftw3.lib not found.")
else()
message(" [ERROR] library: libfftw3.a not found.")
endif()
message("${ColourReset} ${Green}")
message(" Wrong FFTW3 library path")
message("")
message(" FFTW3_LIB_PATH : " ${FFTW3_LIB_PATH})
message("${ColourReset} ")
message( FATAL_ERROR )
endif()
#... FFTW LIBRARY FLAG
if (WIN32)
set(FFTW_LIB_FLAG ${FFTW3_LIB_PATH}/fftw3.lib )
else()
set(FFTW_LIB_FLAG ${FFTW3_LIB_PATH}/libfftw3.a )
endif()
endif()
###-------------------------------------------------------------------------###
#... -fPIC is needed to generate shared library
# set(CMAKE_Fortran_FLAGS "-fPIC")
add_subdirectory(src/libBspline)
add_subdirectory(src/libFyMc)
add_subdirectory(src/libGrid2Grid)