-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
200 lines (169 loc) · 6.41 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
# Minimum CMake version.
cmake_minimum_required (VERSION 2.8.12)
# Adjust CMake's module path.
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
# Options for building MTE. 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 (NOT CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX /usr/local)
endif()
# 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()
enable_language(C)
enable_language(CXX)
enable_language(Fortran)
# We declare the project here.
project (MTE)
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})")
if (BUILD_SHARED_LIBS)
message("-- MTE will be built as a shared library.")
else()
message("-- MTE will be built as a static library.")
endif()
# Version numbers.
set (MTE_MAJOR_VERSION 0)
set (MTE_MINOR_VERSION 1)
set (MTE_PATCH_VERSION 0)
set (MTE_VERSION "${MTE_MAJOR_VERSION}.${MTE_MINOR_VERSION}.${MTE_PATCH_VERSION}")
# General C compiler flags.
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -pedantic-errors -Wextra -Werror-implicit-function-declaration")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-sign-compare -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast")
if (BUILD_SHARED_LIBS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIC")
endif()
if (LINUX EQUAL 1)
# Counter some of GCC's more recent stinginess on Linux.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_POSIX_C_SOURCE=200809L")# -D_BSD_SOURCE")
endif()
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -pedantic-errors -Wextra -Werror-implicit-function-declaration -fno-builtin")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-sign-compare -Wno-unused-parameter -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -Wno-unused-function")
elseif (CMAKE_C_COMPILER_ID STREQUAL "Intel")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SYS_FLAGS}")
# Fortran compiler flags.
if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -W -Wall -std=gnu -pedantic -Wno-unused-variable -Wno-unused-parameter -DCPRGNU")
endif()
# Fortran compiler flags.
if (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -DCPRINTEL")
endif()
# Figure out the system type.
set(MTE_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(MTE_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)
# Check third-party library dependencies.
set(MTE_NEED_PETSC 0)
if (XSDK_WITH_NETCDF)
if (NOT TPL_NETCDF_LIBRARIES)
message(FATAL_ERROR "TPL_NETCDF_LIBRARIES option be set for netcdf support to be enabled.")
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 MTE_TPLS ${TPL_NETCDF_LIBRARIES})
list(APPEND MTE_INCLUDE_DIRS ${TPL_NETCDF_INCLUDE_DIRS})
set(MTE_HAVE_NETCDF 1)
else()
set(MTE_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(${MTE_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 mte.cmake
# file that contains all the vital information.
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Templates/mte.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/mte.cmake"
@ONLY
)
# Install miscellaneous build/test files.
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mte.cmake DESTINATION share/MTE)