-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
297 lines (242 loc) · 12.2 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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# =============================================================================
# CADET - The Chromatography Analysis and Design Toolkit
#
# Copyright © 2008-2015: Eric von Lieres¹, Joel Andersson¹,
# Andreas Puettmann¹, Sebastian Schnittert¹,
# Samuel Leweke¹
#
# ¹ Forschungszentrum Juelich GmbH, IBG-1, Juelich, Germany.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the GNU Public License v3.0 (or, at
# your option, any later version) which accompanies this distribution, and
# is available at http://www.gnu.org/licenses/gpl.html
# =============================================================================
# Require a fairly new cmake version
cmake_minimum_required (VERSION 2.6)
# Prohibit in-source build
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message (FATAL_ERROR "In-source build prohibited.")
endif ()
# Set module path in order to use custom CMake modules
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
find_package(Git)
# Write the current version number to variable and file
if (GIT_FOUND)
if (EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(COMMAND ${GIT_EXECUTABLE} describe --abbrev=0 HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE CADET_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
# In case of missing tags, default to versions.txt file
if (NOT "${CADET_VERSION}" STREQUAL "")
message(STATUS "Get version from git")
# Remove first character ("v")
string(LENGTH "${CADET_VERSION}" CADET_VERSION_STRLEN)
math(EXPR CADET_VERSION_STRLEN "${CADET_VERSION_STRLEN}-1")
string(SUBSTRING "${CADET_VERSION}" 1 ${CADET_VERSION_STRLEN} CADET_VERSION)
endif ()
endif ()
endif ()
if ("${CADET_VERSION}" STREQUAL "")
message(STATUS "Get version from file")
file(STRINGS "${CMAKE_SOURCE_DIR}/version.txt" CADET_VERSION)
endif ()
message(STATUS "CADET version is ${CADET_VERSION}")
# Get current commit hash from git
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
if (NOT DEFINED GIT_SHA1)
set(GIT_SHA1 "NO-COMMIT-HASH")
set(GIT_REFSPEC "NO-REFSPEC")
endif()
message(STATUS "Current git HEAD: ${GIT_REFSPEC} SHA1 ${GIT_SHA1}")
# Names of the executables
set (CADET_NAME "cadet")
set (LIBCADET_NAME "libcadet")
set (CADET_CS_NAME "cadet-cs")
set (CADET_CS_MICRO_NAME "cadet-cs_micro")
set (CADET_MI_NAME "cadet-mi")
set (CONVERTER_NAME "converter")
set (H5TOXML_NAME "h5toxml")
set (XMLTOH5_NAME "xmltoh5")
set (BENCHMARK_NAME "benchmarks")
set (SCL_NAME "createSCL")
set (VAR_SCL_NAME "var_createSCL")
set (LWE_NAME "createLWE")
set (VAR_LWE_NAME "var_createLWE")
set (C14_NAME "createC14")
set (EXTL_NAME "createEXTL")
set (TESTS_NAME "tests")
set (RESULTCOMP_NAME "rescomp")
# Names of the projects
set (CADET_PRJ "prj_${CADET_NAME}")
set (LIBCADET_PRJ "prj_${LIBCADET_NAME}")
set (CADET_CS_PRJ "prj_${CADET_CS_NAME}")
set (CADET_MI_PRJ "prj_${CADET_MI_NAME}")
set (CONVERTER_PRJ "prj_${CONVERTER_NAME}")
set (BENCHMARK_PRJ "prj_${BENCHMARK_NAME}")
set (TESTS_PRJ "prj_${TESTS_NAME}")
# Name of the current project
project (${CADET_PRJ} CXX)
string (TOUPPER CADET_NAME CADET_NAME_UP)
# Set some variables with info on the CADET project
set (PACKAGE_VERSION "${CADET_VERSION}")
set (PACKAGE_BUGREPORT "cadet@fz-juelich.de")
set (PACKAGE_NAME "${CADET_NAME_UP}")
set (PACKAGE_STRING "${CADET_NAME_UP} ${PACKAGE_VERSION}")
set (PACKAGE_TARNAME "${CADET_NAME}")
# ------------------------------------------------------------------------------------------------------------------------
# Other configuration options
# ------------------------------------------------------------------------------------------------------------------------
# Option that allows users to build release or debug version
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE "release" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif ()
# Set default compiler compiler flags
if (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") OR (CXX_COMPILER_NAME STREQUAL "icpc") OR (CXX_COMPILER_NAME STREQUAL "icc"))
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -xHOST -DNDEBUG -ipo -ip" CACHE STRING "Default flags for optimized release builds" FORCE)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -march=native" CACHE STRING "Default flags for optimized release builds" FORCE)
elseif (CMAKE_COMPILER_IS_GNUCXX OR CXX_COMPILER_NAME STREQUAL "g++" OR CXX_COMPILER_NAME STREQUAL "c++" OR CXX_COMPILER_NAME STREQUAL "g++.exe")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -march=native" CACHE STRING "Default flags for optimized release builds" FORCE)
elseif (CXX_COMPILER_NAME STREQUAL "cl")
endif ()
option (BENCHMARK_MODE "In benchmark mode logging framework is disabled, only timing is printed" OFF)
if (BENCHMARK_MODE)
add_definitions(-DBENCHMARK_MODE)
endif ()
# Determine default value for publishing the git branch in the binaries
if ( GIT_REFSPEC STREQUAL "refs/heads/master" )
# Don't publish if we are on the master branch
set (PUBLISH_BRANCH_INFO_DEFAULT OFF)
else ()
# Publish if we are on any other branch
set (PUBLISH_BRANCH_INFO_DEFAULT ON)
endif ()
option (PUBLISH_BRANCH_INFO "Publish the git branch info in the binaries" PUBLISH_BRANCH_INFO_DEFAULT)
if (PUBLISH_BRANCH_INFO)
add_definitions(-DCADET_PUBLISH_BRANCH_INFO)
endif ()
# ------------------------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------------------
# Which modules to build?
# ------------------------------------------------------------------------------------------------------------------------
# CADET-CS module
if (IS_DIRECTORY "${PROJECT_SOURCE_DIR}/src/cadet-cs")
option (BUILD_CADET_CS "Build the CADET-CS binary" ON)
else ()
set (BUILD_CADET_CS OFF)
endif ()
# CADET-MI module
if (IS_DIRECTORY "${PROJECT_SOURCE_DIR}/src/cadet-mi")
option (BUILD_CADET_MI "Build the matlab interface tools" ON)
else ()
set (BUILD_CADET_MI OFF)
endif ()
# CONVERTER module
if (IS_DIRECTORY "${PROJECT_SOURCE_DIR}/src/common/convert")
option (BUILD_CONVERTER "Build the HDF5 and XML converter" ON)
else ()
set (BUILD_CONVERTER OFF)
endif ()
# BENCHMARK module
if (IS_DIRECTORY "${PROJECT_SOURCE_DIR}/src/common/benchmark")
option (BUILD_BENCHMARK "Build the benchmark case creation tools" ON)
else ()
set (BUILD_BENCHMARK OFF)
endif ()
# TEST module
if (IS_DIRECTORY "${PROJECT_SOURCE_DIR}/test")
option (BUILD_TESTS "Build tests" ON)
else ()
set (BUILD_TESTS OFF)
endif ()
# ------------------------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------------------
# Add selected modules to the build system and add the targets to the list of all targets
# ------------------------------------------------------------------------------------------------------------------------
# Shared components
add_subdirectory (src/libcadet)
# Add LIBCADET targets to the list of all targets
set (CADET_TARGETS ${LIBCADET_TARGETS})
# CADET-CS module
if (BUILD_CADET_CS)
add_subdirectory (src/cadet-cs)
# Add CADET-CS target
list (APPEND CADET_TARGETS ${CADET_CS_NAME})
list (APPEND CADET_TARGETS ${CADET_CS_MICRO_NAME})
endif ()
# CADET-MI module
if (BUILD_CADET_MI)
add_subdirectory (src/cadet-mi)
# Add CADET-MI target
endif ()
# CONVERTER module
if (BUILD_CONVERTER)
add_subdirectory (src/common/convert)
# Add CONVERTER target
list (APPEND CADET_TARGETS ${H5TOXML_NAME} ${XMLTOH5_NAME})
endif ()
# BENCHMARK module
if (BUILD_BENCHMARK)
add_subdirectory (src/common/benchmark)
# Add BENCHMARK target
list (APPEND CADET_TARGETS ${SCL_NAME} ${LWE_NAME})
endif ()
# TESTS module
if (BUILD_TESTS)
add_subdirectory (test)
# Add TESTS target
list (APPEND CADET_TARGETS ${RESULTCOMP_NAME})
endif ()
# ------------------------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------------------
# Set properties, definitions, install target etc.
# ------------------------------------------------------------------------------------------------------------------------
# Depending on the used compiler, we enable warnings and OpenMP support: -fopenmp -Wall -Wvla
# Disable line-wrapping in gcc/gxx to support eclipse CDT error parsing: -fmessage-length=0
# Enable C++11 - Standard compiler support: -std=c++0x
get_filename_component (CXX_COMPILER_NAME ${CMAKE_CXX_COMPILER} NAME)
message (STATUS "C++ compiler name: ${CXX_COMPILER_NAME}")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
foreach (_TARGET ${CADET_TARGETS})
if (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") OR (CXX_COMPILER_NAME STREQUAL "icpc") OR (CXX_COMPILER_NAME STREQUAL "icc"))
set_target_properties (${_TARGET} PROPERTIES COMPILE_FLAGS "-w2 -std=c++0x -mkl -fno-rtti" LINK_FLAGS "-mkl")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set_target_properties (${_TARGET} PROPERTIES COMPILE_FLAGS "-Wall -Wvla -std=c++0x -fno-rtti" LINK_FLAGS "")
elseif (CMAKE_COMPILER_IS_GNUCXX OR CXX_COMPILER_NAME STREQUAL "g++" OR CXX_COMPILER_NAME STREQUAL "c++" OR CXX_COMPILER_NAME STREQUAL "g++.exe")
set_target_properties (${_TARGET} PROPERTIES COMPILE_FLAGS "-Wall -Wvla -std=c++0x -fmessage-length=0 -fno-rtti" LINK_FLAGS "")
elseif (CXX_COMPILER_NAME STREQUAL "cl")
set_target_properties (${_TARGET} PROPERTIES COMPILE_FLAGS "")
endif ()
endforeach ()
else()
foreach (_TARGET ${CADET_TARGETS})
if (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") OR (CXX_COMPILER_NAME STREQUAL "icpc") OR (CXX_COMPILER_NAME STREQUAL "icc"))
set_target_properties (${_TARGET} PROPERTIES COMPILE_FLAGS "-openmp -w2 -std=c++0x -mkl -fno-rtti" LINK_FLAGS "-mkl -openmp")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set_target_properties (${_TARGET} PROPERTIES COMPILE_FLAGS "-Wall -Wvla -std=c++0x -fno-rtti" LINK_FLAGS "")
elseif (CMAKE_COMPILER_IS_GNUCXX OR CXX_COMPILER_NAME STREQUAL "g++" OR CXX_COMPILER_NAME STREQUAL "c++" OR CXX_COMPILER_NAME STREQUAL "g++.exe")
set_target_properties (${_TARGET} PROPERTIES COMPILE_FLAGS "-fopenmp -Wall -Wvla -std=c++0x -fmessage-length=0 -fno-rtti" LINK_FLAGS "-fopenmp")
elseif (CXX_COMPILER_NAME STREQUAL "cl")
set_target_properties (${_TARGET} PROPERTIES COMPILE_FLAGS "/openmp")
endif ()
endforeach ()
endif()
# ------------------------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------------------
# Set installation related stuff
# ------------------------------------------------------------------------------------------------------------------------
# Set install directory to current directory
#set (CMAKE_INSTALL_PREFIX "$ENV{HOME}/opt/cadet" CACHE
# STRING "Install path prefix, prepended onto install directories." FORCE)
# ------------------------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------------------
# Misc stuff
# ------------------------------------------------------------------------------------------------------------------------
# Make HDF5_DIR variable invisible
mark_as_advanced(FORCE HDF5_DIR)
# ------------------------------------------------------------------------------------------------------------------------