forked from MattClarkson/CMakeCatchTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
388 lines (311 loc) · 15.8 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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
#/*============================================================================
#
# MYPROJECT: A software package for whatever.
#
# Copyright (c) University College London (UCL). All rights reserved.
#
# This software is distributed WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE.
#
# See LICENSE.txt in the top level directory for details.
#
#============================================================================*/
######################################################################
# Set the minimum CMake version.
######################################################################
set(MYPROJECT_CMAKE_MINIMUM_REQUIRED_VERSION 3.5)
cmake_minimum_required(VERSION ${MYPROJECT_CMAKE_MINIMUM_REQUIRED_VERSION})
###################################################################################
# Set some CMake Policies.
# See http://cmake.org/cmake/help/cmake-2-8-docs.html#section_Policies for details.
###################################################################################
set(project_policies )
foreach(policy ${project_policies})
if(POLICY ${policy})
cmake_policy(SET ${policy} NEW)
endif()
endforeach()
###############################################################################
# Setup project name, and version. Version number gets baked into package name.
###############################################################################
if (BUILD_SUPERBUILD)
project(MYPROJECT-SuperBuild)
set(MYPROJECT_SOURCE_DIR ${PROJECT_SOURCE_DIR})
set(MYPROJECT_BINARY_DIR ${PROJECT_BINARY_DIR})
else()
project(MYPROJECT VERSION 0.2.2)
endif()
######################################################################
# Setup the path to load CMake macros, and extra CMake files.
# This means cmake can 'see' or 'use' files in the CMake folder.
######################################################################
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake)
######################################################################
# Include extra CMake stuff for configuring this project.
######################################################################
include(mitkMacroEmptyExternalProject)
include(mitkFunctionCheckCompilerFlags)
include(mitkFunctionGetGccVersion)
include(mpMacroInstallCommandLineApp)
include(mpMacroInstallHeaders)
include(mpMacroInstallLibrary)
include(mpMacroCreateGuiApplication)
######################################################################
# Set main build options.
######################################################################
option(BUILD_TESTING "Build Unit tests." ON)
option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
mark_as_advanced(BUILD_SHARED_LIBS)
option(BUILD_SUPERBUILD "Build MYPROJECT and the projects it depends on via SuperBuild.cmake." ON)
mark_as_advanced(BUILD_SUPERBUILD)
option(MYPROJECT_USE_OPENMP "Use OpenMP." OFF)
mark_as_advanced(MYPROJECT_USE_OPENMP)
option(MYPROJECT_USE_CUDA "Use CUDA." OFF)
mark_as_advanced(MYPROJECT_USE_CUDA)
option(MYPROJECT_DELAYLOAD_CUDA "(Windows only) If enabled the CUDA DLLs will be a soft delay-load dependency and MYPROJECT can run without them." OFF)
mark_as_advanced(MYPROJECT_DELAYLOAD_CUDA)
set(MYPROJECT_CUDA_ARCH_BIN "" CACHE STRING "CUDA compute capability to build for - user must specify it.") # See: https://en.wikipedia.org/wiki/CUDA
mark_as_advanced(MYPROJECT_CUDA_ARCH_BIN)
option(MYPROJECT_USE_MPI "Use MPI." OFF)
mark_as_advanced(MYPROJECT_USE_MPI)
######################################################################
# Setup Testing (dashboards etc.).
######################################################################
include(mpSetupTesting)
######################################################################
# Define variables that we carry through to sub-directories.
######################################################################
set(_known_apps "") # Temp variable.
set(MYPROJECT_BOOST_LIBS "") # List of required Boost libraries.
set(QT5_LINK_LIBRARIES) # List of required Qt libraries.
set(BUILDING_GUIS OFF) # Whether or not any GUI projects are on.
set(ALL_THIRD_PARTY_LIBRARIES) # List of all 3rd party libraries to link to.
set(ADDITIONAL_SEARCH_PATHS "") # List of all folders to search for .dlls when packaging, and setting up Visual Studio paths.
if(WIN32)
list(APPEND ADDITIONAL_SEARCH_PATHS "${CMAKE_BINARY_DIR}/bin/${VS_BUILD_TYPE}")
endif()
#######################################################################
# Add some third party packages. Note: Ordering is very important.
# Also, if you don't want one, you can just search for the package name
# (e.g. VTK) in this file, and remove all those lines you don't want.
#######################################################################
include(mpAddgflags)
include(mpAddglog)
include(mpAddEigen)
include(mpAddFLANN)
include(mpAddVTK)
include(mpAddArrayFire)
include(mpAddOpenCV)
include(mpAddBoost)
include(mpAddPythonBindings)
include(mpAddPCL)
include(mpAddUnityWrapper)
######################################################################
# Add our Gui projects. If you don't want Gui stuff, remove this line.
######################################################################
include(mpAddGuiProjects)
######################################################################
# Make sure at this point in this file, VTK is the correct version.
######################################################################
include(mpSetupVTKBackend)
##############################################################################
# Further variables for the external project names and locations are defined
# in the external project CMake files under CMake/ExternalProjects.
##############################################################################
set(NIFTK_EP_TARBALL_LOCATION "http://cmic.cs.ucl.ac.uk/platform/dependencies")
######################################################################
# MYPROJECT uses KWStyle for checking the coding style.
######################################################################
include(${CMAKE_SOURCE_DIR}/Utilities/KWStyle/MYPROJECTKWStyle.cmake)
######################################################################
# MYPROJECT uses CppCheck for static analysis.
######################################################################
include(${CMAKE_SOURCE_DIR}/Utilities/CppCheck/MYPROJECTCppCheck.cmake)
######################################################################
# MYPROJECT uses Doxygen for documentation generation.
######################################################################
include(mpAddDocs)
######################################################################
# Setting supported build types. Should ONLY be Release or Debug.
######################################################################
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Valid options are Release or Debug" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release" "Debug")
endif()
if (NOT (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "Debug"))
message(FATAL_ERROR "Build type \"${CMAKE_BUILD_TYPE}\" is not supported.")
endif()
if(WIN32)
# Restrict the generated configuration to be what we configured above.
# No point creating project files for build types that will not compile.
# Note: it's set to FORCE so that both CMAKE_BUILD_TYPE and CMAKE_CONFIGURATION_TYPES match up.
set(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE} CACHE STRING "Build configurations to generate." FORCE)
mark_as_advanced(CMAKE_CONFIGURATION_TYPES)
endif()
######################################################################
# Check for Qt early, as VTK may need it in SuperBuild.
######################################################################
include(mpIncludeQt)
######################################################################
# Choose C++ standard. Currently 11, as we try to support VS2013.
######################################################################
set(MYPROJECT_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS 0)
set(CMAKE_CXX_STANDARD ${MYPROJECT_CXX_STANDARD})
set(CMAKE_CXX_STANDARD_REQUIRED 1)
if(CMAKE_COMPILER_IS_GNUCXX)
mitkFunctionGetGccVersion(${CMAKE_CXX_COMPILER} GCC_VERSION)
else()
set(GCC_VERSION 0)
endif()
# This is necessary to avoid problems with compile feature checks.
# CMAKE_CXX_STANDARD seems to only set the -std=c++11 flag for targets.
# However, compile flag checks also need to be done with -std=c++11.
# The MYPROJECT_CXX11_FLAG variable is also used for external projects
# build during the MYPROJECT super-build.
mitkFunctionCheckCompilerFlags("-std=c++11" MYPROJECT_CXX11_FLAG)
if(NOT MYPROJECT_CXX11_FLAG)
# Older gcc compilers use -std=c++0x
mitkFunctionCheckCompilerFlags("-std=c++0x" MYPROJECT_CXX11_FLAG)
endif()
######################################################################
# Force MSVC runtime. Depends on BUILD_SHARED_LIBS.
######################################################################
include(mpSetupMSVCRuntime)
######################################################################
# Try finding CUDA/OpenMP/OpenMPI before SuperBuild, so that variables
# are more likely to be set consistently throughout all dependencies.
######################################################################
include(mpIncludeCUDA)
include(mpIncludeOpenMP)
include(mpIncludeMPI)
######################################################################
# Make sure Git is available, as SuperBuild may need to do updates.
######################################################################
find_package(Git REQUIRED)
if (WIN32)
set(GITCOMMAND ${GIT_EXECUTABLE})
endif()
######################################################################
# Now, if required, do the SuperBuild
# If we are doing SuperBuild
# We configure up to this point (see the return() statement below)
# and then we call SuperBuild.cmake, which builds all the
# dependencies as CMake ExternalProjects, and then also builds
# MYPROJECT as an ExternalProject. However instead of downloading
# a tar file, you set the SOURCE_DIR to be THIS project, and force
# the BUILD_SUPERBUILD flag to be off (to avoid infinite loop).
#
# If we are NOT doing superbuild, then the next statement has no
# effect, and the build goes on the same as before.
######################################################################
if(BUILD_SUPERBUILD)
include("CMake/SuperBuild.cmake")
return()
endif(BUILD_SUPERBUILD)
######################################################################
# End of SuperBuild. Print out where the source and binary folders
# are, just to make it really explicit... well, explicit to the user
# that bothers to read these messages! :-)
######################################################################
message("CMAKE_SOURCE_DIR=${CMAKE_SOURCE_DIR}")
message("CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}")
######################################################################
# Additionally add the build folder, now we are building main project.
######################################################################
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
######################################################################
# Copy some reference files to output.
######################################################################
configure_file(${CMAKE_SOURCE_DIR}/Documentation/License.dox ${CMAKE_BINARY_DIR}/Doxygen/License.dox)
configure_file(${CMAKE_SOURCE_DIR}/LICENSE.txt ${CMAKE_BINARY_DIR}/LICENSE.txt @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/LICENSE.txt DESTINATION . COMPONENT CONFIG)
configure_file(${CMAKE_SOURCE_DIR}/README.md ${CMAKE_BINARY_DIR}/README.md @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/README.txt ${CMAKE_BINARY_DIR}/README.txt @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/README.txt DESTINATION . COMPONENT CONFIG)
configure_file(${CMAKE_SOURCE_DIR}/INSTALLATION.txt ${CMAKE_BINARY_DIR}/INSTALLATION.txt @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/MyProjectConfigure.h.in ${CMAKE_BINARY_DIR}/MyProjectConfigure.h @ONLY)
######################################################################
# Organise module/plugin/etc projects better within the IDE.
######################################################################
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
######################################################################
# Add Optional Requirements
######################################################################
if(WIN32)
set(_library_sub_dir "bin")
else()
set(_library_sub_dir "lib")
endif()
# These are dependent on ordering
include(mpIncludegflags)
include(mpIncludeglog)
include(mpIncludeEigen)
include(mpIncludeBoost)
include(mpIncludePythonBindings)
include(mpIncludeArrayFire)
include(mpIncludeOpenCV)
include(mpIncludeVTK)
include(mpIncludePCL)
######################################################################
# This must come after all the external packages that need
# their documentation bundling in with this packages documentation.
######################################################################
include(mpIncludeDocs)
######################################################################
# Compilation specific stuff, like flags etc.
######################################################################
if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOMINMAX /W2")
set(CMAKE_CXX_WARNING_LEVEL 2)
endif(WIN32)
if(WIN32 AND NOT BUILD_SHARED_LIBS)
add_definitions(-DMYPROJECT_STATIC)
endif()
######################################################################
# A few shortcuts for lists of libraries.
######################################################################
set(MYPROJECT_LIBRARIES myproject)
set(ALL_LIBRARIES ${MYPROJECT_LIBRARIES} ${ALL_THIRD_PARTY_LIBRARIES} ${QT5_LINK_LIBRARIES})
######################################################################
# Set up a few paths.
######################################################################
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(MYPROJECT_INSTALL_LIB_DIR lib)
set(MYPROJECT_INSTALL_INC_DIR include)
set(MYPROJECT_INSTALL_BIN_DIR bin)
foreach(type LIBRARY RUNTIME ARCHIVE)
if(NOT MYPROJECT_PYTHON_OUTPUT_DIRECTORY STREQUAL "" AND ${type} STREQUAL "LIBRARY")
set(CMAKE_${type}_OUTPUT_DIRECTORY $<1:${MYPROJECT_PYTHON_OUTPUT_DIRECTORY}> CACHE INTERNAL "Output dir for Python module.")
else()
set(CMAKE_${type}_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} CACHE INTERNAL "Single output directory for building all libraries.")
endif()
mark_as_advanced(CMAKE_${type}_OUTPUT_DIRECTORY)
endforeach()
include_directories(${CMAKE_SOURCE_DIR}/Code/Lib)
include_directories(${CMAKE_BINARY_DIR})
######################################################################
# Add our main code folders. This is where all our functionality is.
######################################################################
add_subdirectory(Code)
add_subdirectory(Documentation)
if(BUILD_TESTING)
set(TEMP_DIR ${CMAKE_BINARY_DIR}/Testing/Temporary)
include_directories(${CMAKE_SOURCE_DIR}/Testing/)
add_subdirectory(Testing)
endif()
###############################################################################################
# The next call generates CMake code to enable external projects to correctly use MYPROJECT.
###############################################################################################
include(mpSetupExternalConfig)
######################################################################
# Packaging code. Read the README.md.
######################################################################
include(mpSetupPackaging)
######################################################################
# If we are under Windows, create batch files which correctly
# set up the environment for Visual Studio. These are only used to
# start VS when developing. Not used in the final installation package.
######################################################################
include(mpSetupVisualStudioPaths)