-
Notifications
You must be signed in to change notification settings - Fork 18
/
CMakeLists.txt
220 lines (185 loc) · 6.64 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
# Minimum CMake version, determined by hdf5.
cmake_minimum_required (VERSION 3.1)
# Version numbers.
set (BETR_MAJOR_VERSION 0)
set (BETR_MINOR_VERSION 1)
set (BETR_PATCH_VERSION 0)
set (BETR_VERSION "${BETR_MAJOR_VERSION}.${BETR_MINOR_VERSION}.${BETR_PATCH_VERSION}")
# Adjust CMake's module path.
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
# Options for building BeTR. These come from the xSDK compliance rules.
option(USE_XSDK_DEFAULTS "Set to use xSDK defaults for options [ON]." ON)
option(CMAKE_INSTALL_PREFIX "Sets installation prefix [/usr/local].")
option(XSDK_ENABLE_DEBUG "Enables Debug mode builds [OFF]." OFF)
option(BUILD_SHARED_LIBS "Builds shared libraries [ON]." ON)
option(XSDK_WITH_NETCDF "Enables support for netcdf [OFF]." ON)
option(TPL_NETCDF_LIBRARIES "List of absolute paths to netcdf link libraries [].")
option(TPL_NETCDF_INCLUDE_DIRS "List of absolute paths to netcdf include directories [].")
# For now, we disable shared libs on Macs.
if (APPLE)
set(BUILD_SHARED_LIBS OFF)
endif()
if (BUILD_SHARED_LIBS)
message("-- BeTR will be built as a shared library.")
else()
message("-- BeTR will be built as a static library.")
endif()
if (NOT CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX /usr/local)
endif()
# set the number of cores to something reasonable so we don't over
# subscribe a laptop or exceed hpc login node restrictions. could
# switch to something more sophisticated like polymec if necessary.
set(NUMBER_OF_CORES 4)
math(EXPR NUM_BUILD_THREADS "${NUMBER_OF_CORES} + 1")
include(set_up_platform)
include(set_up_compilers)
# Make sure compilers are set. This must be done before enabling languages.
if (NOT CMAKE_C_COMPILER)
if (NOT $ENV{CC} STREQUAL "")
set(CMAKE_C_COMPILER $ENV{CC})
else()
set(CMAKE_C_COMPILER cc)
endif()
endif()
if (NOT CMAKE_C_FLAGS)
set(CMAKE_C_FLAGS $ENV{CFLAGS})
endif()
if (NOT CMAKE_CXX_COMPILER)
if (NOT $ENV{CXX} STREQUAL "")
set(CMAKE_CXX_COMPILER $ENV{CXX})
else()
set(CMAKE_CXX_COMPILER c++)
endif()
endif()
if (NOT CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS $ENV{CXX_FLAGS})
endif()
if (NOT CMAKE_Fortran_COMPILER)
if (NOT $ENV{FC} STREQUAL "")
set(CMAKE_Fortran_COMPILER $ENV{FC})
else()
set(CMAKE_Fortran_COMPILER gfortran)
endif()
endif()
if (NOT CMAKE_Fortran_FLAGS)
set(CMAKE_Fortran_FLAGS $ENV{FCFLAGS})
endif()
set_up_platform()
enable_language(C)
enable_language(CXX)
enable_language(Fortran)
# We declare the project here.
project (betr)
message("-- C compiler is ${CMAKE_C_COMPILER} (${CMAKE_C_COMPILER_ID})")
message("-- CXX compiler is ${CMAKE_CXX_COMPILER} (${CMAKE_CXX_COMPILER_ID})")
message("-- Fortran compiler is ${CMAKE_Fortran_COMPILER} (${CMAKE_Fortran_COMPILER_ID})")
set_up_compilers()
if (BGC)
set (BETR_BGC 1)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -DBETR_BGC")
else()
set (BETR_BGC 0)
endif()
if (SBETR)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -DSBETR")
endif()
# Figure out the system type.
set(BETR_HAVE_BOOL 1) # All reasonable C99 compilers have this now.
if (APPLE EQUAL 1)
set(SYS_FLAGS "-DAPPLE=1")
set(DYLIB_SUFFIX "dylib")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Accelerate")
else ()
if (LINUX EQUAL 1)
set(SYS_FLAGS "-DLINUX=1")
set(DYLIB_SUFFIX "so")
else()
if (WIN32 EQUAL 1)
set(BETR_HAVE_BOOL 0) # MS doesn't have reasonable C compilers.
set(SYS_FLAGS "-DWINDOWS=1")
set(DYLIB_SUFFIX "dll")
endif()
endif ()
endif ()
# Here we make sure CMake-installed binaries use the correct runpath, and
# that the path is not stripped during installation.
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# Basic libraries to be linked in.
set(BETR_LIBRARIES m)
if (${NEED_LAPACK})
# NEED_LAPACK is set by set_up_platform()
include(FindBLAS)
include(FindLAPACK)
find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)
if (${LAPACK_LIBRARY_DIR})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${LAPACK_LIBRARY_DIR}")
endif()
if (${BLAS_LIBRARY_DIR})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${BLAS_LIBRARY_DIR}")
endif()
set(BETR_LIBRARIES ${BETR_LIBRARIES};${LAPACK_LIBRARIES};${BLAS_LIBRARIES})
endif()
set(BETR_NEED_PETSC 0)
#if (XSDK_WITH_NETCDF AND MACHINE MATCHES "supported")
if ((TPL_NETCDF_LIBRARIES MATCHES "lib") AND (TPL_NETCDF_INCLUDE_DIRS MATCHES "include"))
# message(FATAL_ERROR "TPL_NETCDF_LIBRARIES option be set for netcdf support to be enabled.")
# message("TPL_NETCDF_LIBRARIES option be set for netcdf support to be enabled.")
message("BETR has netcdf support from the system")
message("TPL_NETCDF_LIBRARIES ${TPL_NETCDF_LIBRARIES}")
message("TPL_NETCDF_INCLUDE_DIRS ${TPL_NETCDF_INCLUDE_DIRS}")
list(APPEND BETR_TPLS ${TPL_NETCDF_LIBRARIES})
list(APPEND BETR_INCLUDE_DIRS ${TPL_NETCDF_INCLUDE_DIRS})
set(BETR_HAVE_NETCDF 1)
else()
message("BETR does not have netcdf support from the system")
set(BETR_HAVE_NETCDF 0)
endif()
#X# foreach(lib ${TPL_NETCDF_LIBRARIES})
#X# if (NOT EXISTS ${lib})
#X# message(FATAL_ERROR "netcdf library not found: ${lib}")
#X# endif()
#X# endforeach()
# if (NOT TPL_NETCDF_INCLUDE_DIRS)
# message(FATAL_ERROR "TPL_NETCDF_INCLUDE_DIRS option be set for netcdf support to be enabled.")
# endif()
#X# foreach(dir ${TPL_NETCDF_INCLUDE_DIRS})
#X# if (NOT EXISTS ${dir})
#X# message(FATAL_ERROR "netcdf include directory not found: ${dir}")
#X# endif()
#X# endforeach()
# message("-- Enabled support for netcdf.")
# list(APPEND BETR_TPLS ${TPL_NETCDF_LIBRARIES})
# list(APPEND BETR_INCLUDE_DIRS ${TPL_NETCDF_INCLUDE_DIRS})
# set(BETR_HAVE_NETCDF 1)
#else()
# set(BETR_HAVE_NETCDF 0)
#endif()
# Other third-party libraries.
add_subdirectory(3rd-party)
# Include the binary directory in the header file search path,
# since it's where we place the third-party libraries.
include_directories("${PROJECT_BINARY_DIR}")
include_directories("${PROJECT_BINARY_DIR}/include")
link_directories("${PROJECT_BINARY_DIR}/lib")
include_directories(${BETR_INCDIRS})
# Unit testing.
enable_testing()
# Source code itself.
include_directories("${PROJECT_SOURCE_DIR}")
add_subdirectory(src)
# Drivers for benchmarks.
#X#add_subdirectory(drivers)
# Benchmarks.
#X#add_subdirectory(benchmarks)
# Now that we have gathered all our libraries, generate an betr.cmake
# file that contains all the vital information.
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Templates/betr.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/betr.cmake"
@ONLY
)
# Install miscellaneous build/test files.
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/betr.cmake DESTINATION share/betr)