-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathCMakeLists.txt
290 lines (256 loc) · 13 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
# --------------------------------------------------------------------------
# SmartPeak -- Fast and Accurate CE-, GC- and LC-MS(/MS) Data Processing
# --------------------------------------------------------------------------
# Copyright The SmartPeak Team -- Novo Nordisk Foundation
# Center for Biosustainability, Technical University of Denmark 2018-2022.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
# INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# --------------------------------------------------------------------------
# $Maintainer: Douglas McCloskey, Ahmed Khalil $
# $Authors: Douglas McCloskey $
# --------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.8.2 FATAL_ERROR)
#------------------------------------------------------------------------------
# Handle superbuild first
#------------------------------------------------------------------------------
option (USE_SUPERBUILD "Whether or not a superbuild should be invoked" ON)
if (USE_SUPERBUILD)
project ("SuperBuild" NONE)
include(external/plog.cmake)
include(external/imgui.cmake)
include(external/implot.cmake)
include(external/portablefiledialogs.cmake)
if (MSVC)
include(external/eigen.cmake)
include(external/openms.cmake)
endif()
return() # stop processing this file further
else()
project ("SmartPeak_host")
endif()
#------------------------------------------------------------------------------
# General CMake definitions & helper
#------------------------------------------------------------------------------
SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
# Set C++ version
add_compile_definitions(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
SET(CMAKE_CXX_STANDARD 17)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_EXTENSIONS OFF)
#------------------------------------------------------------------------------
## CMake sanity check: sometimes CMAKE_SIZEOF_VOID_P just vanishes when
## updating CMake.
if (NOT CMAKE_SIZEOF_VOID_P)
message(FATAL_ERROR "'CMAKE_SIZEOF_VOID_P' is undefined. Thus you should"
" delete CMakeFiles (the directory) and the"
" CMakeCache.txt and rerun CMake again! This is some"
" weird CMake bug that seems to appear when updating the"
" CMake version.")
endif()
#------------------------------------------------------------------------------
# Include the standard Dart testing module
#------------------------------------------------------------------------------
# for Nightly Build log and Valgrind for memcheck
option (BUILD_TESTS "Whether or not build unit tests" ON)
if(BUILD_TESTS)
include(CTest)
include(Dart)
endif()
#------------------------------------------------------------------------------
option(MT_ENABLE_TBB "Enable Intel TBB support" OFF)
option(MT_ENABLE_OPENMP "Enable OpenMP support" ON)
#------------------------------------------------------------------------------
# Extend module path with our modules
# (create an empty list if CMAKE_MODULE_PATH does not exist)
if(NOT CMAKE_MODULE_PATH)
set(CMAKE_MODULE_PATH)
endif()
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules")
## CMake looks for the NSIS script in the module path.
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Windows")
#------------------------------------------------------------------------------
# SmartPeak Version Information
#------------------------------------------------------------------------------
set(SMARTPEAK_PACKAGE_VERSION_MAJOR 1)
set(SMARTPEAK_PACKAGE_VERSION_MINOR 27)
set(SMARTPEAK_PACKAGE_VERSION_PATCH 0)
#------------------------------------------------------------------------------
# retrieve detailed informations on the working copy (git)
include(GetGitRevisionDescription)
option(GIT_TRACKING "Embedding of Git version control information into the SmartPeak library (and SmartPeakInfo tool). Note that if activated, every branch-switch or commit will trigger re-generation of the build system (MakeFiles, VS Solutions etc)." ON)
if (GIT_TRACKING)
## will configure an include file
git_short_info(SMARTPEAK_GIT_SHORT_REFSPEC SMARTPEAK_GIT_SHORT_SHA1 SMARTPEAK_GIT_LC_DATE)
endif()
message(STATUS "Building SmartPeak ${SMARTPEAK_PACKAGE_VERSION_MAJOR}.${SMARTPEAK_PACKAGE_VERSION_MINOR}.${SMARTPEAK_PACKAGE_VERSION_PATCH}")
if(NOT GIT_TRACKING)
set(SMARTPEAK_GIT_SHORT_SHA1 "disabled")
set(SMARTPEAK_GIT_SHORT_REFSPEC "disabled")
message(STATUS " [CMake is not tracking Git commits and branching. To enable use '-D GIT_TRACKING=ON'.]")
elseif(SMARTPEAK_GIT_SHORT_REFSPEC EQUAL "GIT-NOTFOUND" OR ${SMARTPEAK_GIT_SHORT_REFSPEC} EQUAL "HEAD-HASH-NOTFOUND")
set(SMARTPEAK_GIT_SHORT_SHA1 "exported")
set(SMARTPEAK_GIT_SHORT_REFSPEC "exported")
message(STATUS " [CMake is not tracking Git commits and branching. Git not found.]")
else()
# everything found, print some status information
message(STATUS " - Repository revision ${SMARTPEAK_GIT_SHORT_SHA1}")
message(STATUS " - Repository branch ${SMARTPEAK_GIT_SHORT_REFSPEC}")
message(STATUS " - Repository last change date ${SMARTPEAK_GIT_LC_DATE}")
message(STATUS " [CMake is tracking Git commits and branching. To disable use '-D GIT_TRACKING=OFF'.]")
endif()
#------------------------------------------------------------------------------
message(STATUS "Building SmartPeak ${SMARTPEAK_PACKAGE_VERSION_MAJOR}.${SMARTPEAK_PACKAGE_VERSION_MINOR}.${SMARTPEAK_PACKAGE_VERSION_PATCH}")
#------------------------------------------------------------------------------
# Unsupported systems
#------------------------------------------------------------------------------
if (MINGW OR MSYS)
message(FATAL_ERROR "MSYS and/or MinGW are not supported! Please use a Visual Studio environment! See Windows build instructions for further information!")
endif()
#------------------------------------------------------------------------------
# Multi-threading stuff (OpenMP, CUDA, TBB)
#------------------------------------------------------------------------------
include(external/multithreading.cmake)
if (EIGEN_USE_GPU)
find_package(CUDA REQUIRED)
if(CUDA_FOUND)
message(STATUS "Found CUDA Toolkit version ${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}" )
endif()
enable_language(CUDA)
endif()
#------------------------------------------------------------------------------
# Check architecture 32bit vs. 64bit
#------------------------------------------------------------------------------
if (CMAKE_SIZEOF_VOID_P MATCHES "8")
set(SMARTPEAK_64BIT_ARCHITECTURE 1 CACHE INTERNAL "Architecture-bits")
message(STATUS "Architecture: 64 bit")
else()
set(SMARTPEAK_64BIT_ARCHITECTURE 0 CACHE INTERNAL "Architecture-bits")
message(STATUS "Architecture: 32 bit")
endif()
#------------------------------------------------------------------------------
# Handle build type
#------------------------------------------------------------------------------
# Set default build type (if not set by user on command line)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
# Force build type into the cache (needs to be set beforehand)
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
if (MSVC)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W3 /Z7")
elseif (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -Wpedantic -Wconversion -g")
endif()
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
if (MSVC)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /W3")
elseif (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall -Wextra -Wpedantic -Wconversion")
endif()
endif()
# Windows/Linux specific issues
if (WIN32)
add_compile_definitions(NOMINMAX)
else()
# prevent error position independent code error with QT on Linux
add_compile_options(-fPIC)
endif()
#------------------------------------------------------------------------------
# Enable STL debug mode (GCC only)
#------------------------------------------------------------------------------
option(STL_DEBUG "[GCC only] Enable STL-DEBUG mode (very slow)." OFF)
if(STL_DEBUG)
include(cmake/stl_debug.cmake)
endif()
#------------------------------------------------------------------------------
# Enable AddressSanitizer
#------------------------------------------------------------------------------
option(ADDRESS_SANITIZER "[Clang/GCC only] Enable AddressSanitizer mode (quite slow)." OFF)
if(ADDRESS_SANITIZER)
include(cmake/AddressSanitizer.cmake)
endif()
#------------------------------------------------------------------------------
# Host directory for referencing from subprojects
set(SMARTPEAK_HOST_DIRECTORY "${PROJECT_SOURCE_DIR}")
set(SMARTPEAK_HOST_BINARY_DIRECTORY "${PROJECT_BINARY_DIR}")
#------------------------------------------------------------------------------
# CMake Utitlities
#------------------------------------------------------------------------------
# include some SmartPeak specific macros
include (${PROJECT_SOURCE_DIR}/cmake/build_system_macros.cmake)
# .. and some to ease the installation process
include (${PROJECT_SOURCE_DIR}/cmake/install_macros.cmake)
# .. and some to ease the installation process
include (${PROJECT_SOURCE_DIR}/cmake/add_library_macros.cmake)
# .. and some to ease the export process
include (${PROJECT_SOURCE_DIR}/cmake/export_macros.cmake)
#------------------------------------------------------------------------------
# Output directories
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${SMARTPEAK_HOST_BINARY_DIRECTORY}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${SMARTPEAK_HOST_BINARY_DIRECTORY}/bin")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${SMARTPEAK_HOST_BINARY_DIRECTORY}/lib")
set(SMARTPEAK_BINARY_DIR "${SMARTPEAK_HOST_BINARY_DIRECTORY}/bin")
set(SMARTPEAK_WIN32_DLL_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
#------------------------------------------------------------------------------
# define installation subdirectories to allow for custom installations
# note that all those directories are below CMAKE_INSTALL_PREFIX
set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
set(INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
set(INSTALL_DOC_DIR share/doc CACHE PATH "Installation directory for documentation")
set(INSTALL_SHARE_DIR share/SmartPeak CACHE PATH "Installation directory for shared data")
if(WIN32)
set(DEF_INSTALL_CMAKE_DIR CMake)
set(DEF_INSTALL_LIB_DIR bin)
else()
set(DEF_INSTALL_CMAKE_DIR lib/cmake/SmartPeak)
set(DEF_INSTALL_LIB_DIR lib)
endif()
set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
set(INSTALL_LIB_DIR ${DEF_INSTALL_LIB_DIR} CACHE PATH "Installation directory for libraries")
#------------------------------------------------------------------------------
# lib naming when building with msvc & convenience location of build.bat
if (MSVC)
## use SmartPeakd.dll in debug mode
SET(CMAKE_DEBUG_POSTFIX d)
## copy build.bat to root of binary dir to enable convenient invokation (instead of typing path to source dir all the time)
if(NOT ("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}"))
file(COPY "${PROJECT_SOURCE_DIR}/tools/build.bat" DESTINATION "${PROJECT_BINARY_DIR}")
endif()
endif()
#------------------------------------------------------------------------------
# The actual SmartPeak code (headers and source files)
#------------------------------------------------------------------------------
add_subdirectory(src)
#------------------------------------------------------------------------------
# Documentation
#------------------------------------------------------------------------------
option (BUILD_DOCS "Whether or not to build the documentation" OFF)
if(BUILD_DOCS)
add_subdirectory(docs)
endif()
#------------------------------------------------------------------------------
# Handle export of targets and install them
smartpeak_export_targets()
install_export_targets()
#------------------------------------------------------------------------------
# Installation and packaging:
#------------------------------------------------------------------------------
# packaging routines:
if(NOT "${PACKAGE_TYPE}" STREQUAL "none")
include(cmake/package_general.cmake)
include(CPack)
endif()