forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
443 lines (382 loc) · 14.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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# CMake version check.
cmake_minimum_required(VERSION 3.16)
# Define the project name.
project(Mantid)
# Policy settings
if(POLICY CMP0022)
cmake_policy(SET CMP0022 NEW)
endif()
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
# System package target is important for the windows builds as it allows us to package only the dlls and exes and
# exclude libs. Defaults to empty for other platforms.
set(SYSTEM_PACKAGE_TARGET "")
# Add the path to our custom 'find' modules
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/buildconfig/CMake")
# Send libraries to common place, reference in several places so must be at top level
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
option(ENABLE_MANTIDQT "Enable Qt5-based components" ON)
option(ENABLE_WORKBENCH "Enable Qt5-based gui" ON)
set(MANTID_FRAMEWORK_LIB
"BUILD"
CACHE STRING "Mantid framework build options, valid options are (BUILD, SYSTEM).
If system is specificed a valid mantid framework installation must be present on the system, e.g from conda"
)
set_property(CACHE MANTID_FRAMEWORK_LIB PROPERTY STRINGS "BUILD" "SYSTEM")
# set this for compatability, as previously if enable_workbench was off we didn't build the qt element we can override
# this behavior on the command line.
if(NOT ENABLE_WORKBENCH)
set(_mantidqt_option "OFF")
else()
set(_mantidqt_option "BUILD")
endif()
set(MANTID_QT_LIB
${_mantidqt_option}
CACHE STRING "Mantid qt build options, valid options are (OFF, BUILD, SYSTEM).
If system is specificed a valid mantid qt installation must be present on the system, e.g. from conda"
)
set_property(CACHE MANTID_QT_LIB PROPERTY STRINGS "OFF" "BUILD" "SYSTEM")
if(NOT
(ENABLE_WORKBENCH
OR MANTID_QT_LIB STREQUAL "BUILD"
OR MANTID_FRAMEWORK_LIB STREQUAL "BUILD")
)
message(FATAL_ERROR "Must select atleast one component to build")
endif()
# Create two internal BUILD_* variables. With these, we can do consistent checks throughout, e.g: if(BUILD_MANTIDQT OR
# ENABLE_WORKBENCH) .... endif() to check if we are building the mantidqt libs or the workbench application
if(MANTID_QT_LIB STREQUAL "BUILD")
set(BUILD_MANTIDQT ON)
endif()
if(MANTID_FRAMEWORK_LIB STREQUAL "BUILD")
set(BUILD_MANTIDFRAMEWORK ON)
endif()
set(CPACK_INSTALL_CMAKE_PROJECTS "${CMAKE_BINARY_DIR}" "Mantid" "ALL" "/")
# Conda build variables
set(CONDA_ENV
FALSE
CACHE BOOL "If True then we are building in a conda environment.
This predominately changes the operation of some the finders FindXXX.cmake
On windows it also prevents the use of the 3rdparty dependency directory"
)
set(CONDA_BUILD
FALSE
CACHE
BOOL
"If True then we are using conda-build to build and package mantid.
This stops a few things from occuring:
- A bundle is no longer generated on OSX
- Linux custom handling on the install is ommitted
- Prevents site-package manipulation by the installer"
)
# Ensure that if we are running any sanitizers the compiler options are known in sub targets
include(Sanitizers)
# Quick exit if we only want data targets
if(DATA_TARGETS_ONLY)
include(SetupDataTargets)
# System test config files
add_subdirectory(Testing/SystemTests/scripts)
return()
endif()
# Packaging configuration
set(CPACK_PACKAGE_SUFFIX
"unstable"
CACHE STRING "suffix used to determine the deployment type"
)
set_property(CACHE CPACK_PACKAGE_SUFFIX PROPERTY STRINGS nightly unstable "")
# empty string and release are treated as the same thing
if(CPACK_PACKAGE_SUFFIX)
# Camelcase version of suffix for Windows/Mac
string(TOUPPER ${CPACK_PACKAGE_SUFFIX} CPACK_PACKAGE_SUFFIX_CAMELCASE)
string(SUBSTRING ${CPACK_PACKAGE_SUFFIX_CAMELCASE} 0 1 CPACK_PACKAGE_SUFFIX_CAMELCASE)
string(SUBSTRING ${CPACK_PACKAGE_SUFFIX} 1 -1 _tmp_suffix_remainder)
string(CONCAT CPACK_PACKAGE_SUFFIX_CAMELCASE ${CPACK_PACKAGE_SUFFIX_CAMELCASE} ${_tmp_suffix_remainder})
endif()
# Set package name here
set(CPACK_PACKAGE_NAME "mantid${CPACK_PACKAGE_SUFFIX}")
# Bootstrap any dependencies
include(Bootstrap)
if(MSVC)
include(MSVCSetup)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
include(DarwinSetup)
endif()
# Cross-platform setup
include(CommonSetup)
if(BUILD_MANTIDFRAMEWORK)
include(Eigen)
endif()
include(Span)
# Find OpenGL
if(ENABLE_OPENGL)
# Use legacy libGL library
set(OpenGL_GL_PREFERENCE LEGACY)
find_package(OpenGL REQUIRED)
if(NOT OPENGL_FOUND)
message(FATAL_ERROR "OpenGL was not found.")
endif()
endif()
# We probably don't want this to run on every build.
option(COVERAGE "Generate coverage data" OFF)
if(COVERAGE)
include(Coverage)
coverage_turn_on()
endif()
if(ENABLE_WORKBENCH OR BUILD_MANTIDQT)
find_package(
Qt5
COMPONENTS Core Gui Widgets OpenGL Test
REQUIRED
)
if(Qt5_FOUND)
message(STATUS "Found Qt ${Qt5_VERSION}: ${Qt5_DIR}")
endif()
if(BUILD_MANTIDQT)
find_package(QScintillaQt5 REQUIRED)
endif()
find_package(PyQt5 REQUIRED)
find_package(SIP REQUIRED)
separate_arguments(PYQT5_SIP_FLAGS)
endif()
# Now add in all the components
# Flag that this is a full build, i.e not framework only
set(FULL_PACKAGE_BUILD 1)
# Set the path to the built docs directory here so that it can be used in the Kernel project for populating the
# properties file
set(DOCS_BUILDDIR ${CMAKE_BINARY_DIR}/docs)
# Framework Build options
option(CXXTEST_ADD_PERFORMANCE "Switch to add performance tests to the list of tests run by ctest?")
include(TargetFunctions)
if(MANTID_FRAMEWORK_LIB STREQUAL "SYSTEM")
if(BUILD_MANTIDQT)
find_package(MantidFramework REQUIRED)
endif()
else()
add_subdirectory(Framework)
endif()
set(CORE_MANTIDLIBS
Mantid::Kernel
Mantid::HistogramData
Mantid::Indexing
Mantid::Beamline
Mantid::Geometry
Mantid::API
Mantid::Types
)
if(UNIX)
# Experimental feature. Unix only at this point.
option(UNITY_BUILD "Switch for utilising unity builds. Faster builds for selected components.")
endif(UNIX)
if(MSVC)
add_definitions(-DQWT_DLL)
endif()
add_custom_target(AllTests)
if(BUILD_MANTIDFRAMEWORK)
add_dependencies(AllTests FrameworkTests)
endif()
if(BUILD_MANTIDQT OR ENABLE_WORKBENCH)
add_custom_target(GUITests)
add_dependencies(check GUITests)
# Collect all tests together
add_dependencies(AllTests GUITests)
add_subdirectory(qt)
endif()
if(BUILD_MANTIDFRAMEWORK)
add_subdirectory(scripts)
endif()
# Docs requirements
option(ENABLE_DOCS "Enable Building user and developer documentation" ON)
if(ENABLE_DOCS)
find_package(Sphinx REQUIRED)
# run python to see if the theme is installed
execute_process(
COMMAND ${Python_EXECUTABLE} -c "import sphinx_bootstrap_theme"
OUTPUT_VARIABLE SPHINX_BOOTSTRAP_THEME_OUT
ERROR_VARIABLE SPHINX_BOOTSTRAP_THEME_ERR
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE
)
if(SPHINX_BOOTSTRAP_THEME_ERR)
message(ERROR " Did not find sphinx_bootstrap_theme")
message(STATUS "${Python_EXECUTABLE} -c \"import sphinx_bootstrap_theme\"")
message(STATUS "${SPHINX_BOOTSTRAP_THEME_ERR}")
message(FATAL_ERROR " Install instructions at https://pypi.python.org/pypi/sphinx-bootstrap-theme/")
endif()
add_subdirectory(dev-docs)
add_subdirectory(docs)
endif()
# System test data target
add_subdirectory(Testing/SystemTests/scripts)
if(COVERAGE)
get_property(ALL_SRCS GLOBAL PROPERTY COVERAGE_SRCS)
set(SRCS_FILE "")
foreach(SRC ${ALL_SRCS})
set(SRCS_FILE "${SRCS_FILE}\n${SRC}")
endforeach()
# remove initial \n
string(SUBSTRING ${SRCS_FILE} 1 -1 SRCS_FILE)
set(SRCS_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/sources.txt")
file(WRITE ${SRCS_FILENAME} ${SRCS_FILE})
coverage_setup(${SRCS_FILENAME} OFF "${CMAKE_SOURCE_DIR}/buildconfig/CMake")
endif()
# Installation settings
# Install the files (.desktop and icon) to create a menu items
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND NOT CONDA_BUILD)
function(uppercase_first_letter output_var input)
string(LENGTH ${input} _inputlen)
string(TOUPPER ${input} _allupper)
string(SUBSTRING ${_allupper} 0 1 _first)
string(SUBSTRING ${input} 1 ${_inputlen} _rest)
set(${output_var}
${_first}${_rest}
PARENT_SCOPE
)
endfunction()
function(install_desktop_files filename app_name exec_cmd icon_file icon_install_file)
set(DESKTOP_NAME ${app_name})
set(DESKTOP_EXEC_CMD ${exec_cmd})
get_filename_component(DESKTOP_ICON ${icon_install_file} NAME_WE)
set(_output_file ${CMAKE_CURRENT_BINARY_DIR}/${filename}.install)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/installers/LinuxInstaller/launcher-template.desktop.in ${_output_file} @ONLY
)
install(
FILES ${_output_file}
DESTINATION /usr/share/applications
RENAME ${filename}
)
install(
FILES ${icon_file}
DESTINATION /usr/share/pixmaps
RENAME ${icon_install_file}
)
endfunction()
set(_icon_suffix)
if(CPACK_PACKAGE_SUFFIX)
if(${CPACK_PACKAGE_SUFFIX} STREQUAL "nightly" OR ${CPACK_PACKAGE_SUFFIX} STREQUAL "unstable")
set(_icon_suffix ${CPACK_PACKAGE_SUFFIX})
endif()
endif()
set(IMAGES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/images)
set(_app_name_suffix)
if(CPACK_PACKAGE_SUFFIX)
uppercase_first_letter(_app_name_suffix ${CPACK_PACKAGE_SUFFIX})
endif()
if(ENABLE_WORKBENCH)
set(_icon_filename ${IMAGES_DIR}/mantid_workbench)
if(_icon_suffix)
set(_icon_filename ${_icon_filename}${_icon_suffix})
endif()
install_desktop_files(
mantidworkbench${CPACK_PACKAGE_SUFFIX}.desktop "Mantid Workbench ${_app_name_suffix}"
${CMAKE_INSTALL_PREFIX}/bin/mantidworkbench ${_icon_filename}.png mantid_workbench${CPACK_PACKAGE_SUFFIX}.png
)
endif()
endif()
# THIS MUST BE THE LAST SUB_DIRECTORY ADDED. See Framework/PostInstall/CMakeLists for an explanation
add_subdirectory(Framework/PostInstall)
# Conda
option(ENABLE_CONDA "Switch to enable conda package generation")
if(ENABLE_CONDA)
include(conda)
endif(ENABLE_CONDA)
# CPack settings
# Keep this in a defaulted-to-off option
option(ENABLE_CPACK "Switch to enable CPack package generation")
if(ENABLE_CPACK)
include(CPackCommon)
# Mac package settings
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/installers/WinInstaller/License.txt)
if(CMAKE_HOST_WIN32)
include(WindowsNSIS)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
include(CPackLinuxSetup)
# rhel requirements - only used if package requested is rpm
set(CPACK_RPM_PACKAGE_REQUIRES
"boost169-date-time,"
"boost169-regex,"
"boost169-serialization,"
"boost169-filesystem,"
"boost169-system,"
"nexus >= 4.3.1,gsl,glibc,muParser,tbb,librdkafka,"
"OCE-draw,OCE-foundation,OCE-modeling,OCE-ocaf,OCE-visualization,"
"poco-crypto,poco-data,poco-mysql,poco-sqlite,poco-odbc,poco-util,poco-xml,poco-zip,poco-net,poco-netssl,poco-foundation,"
"hdf,hdf5,jsoncpp >= 0.7.0"
)
if(ENABLE_WORKBENCH)
set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES},qt5-qtbase,qscintilla-qt5")
endif()
# python requirements
set(CPACK_RPM_PACKAGE_REQUIRES
"${CPACK_RPM_PACKAGE_REQUIRES}," "boost169-python3,"
"python36-numpy,python36-scipy,python36-h5py,python36-PyCifRW,"
"python36-six,python36-PyYAML,python36-requests,python36-toml," "python36-ipython,python36-ipython-notebook"
)
if(ENABLE_WORKBENCH)
set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES},python36-qt5,python36-QtPy,"
"python36-matplotlib-qt5,python36-psutil,python36-ipython-gui"
)
endif()
string(REPLACE ";" "," CPACK_RPM_PACKAGE_REQUIRES ${CPACK_RPM_PACKAGE_REQUIRES}) # fix up the fact that it was made
# as an array
string(REPLACE ",," "," CPACK_RPM_PACKAGE_REQUIRES ${CPACK_RPM_PACKAGE_REQUIRES})
# ubuntu requirements - only used if package requested is deb
set(CPACK_DEBIAN_PACKAGE_DEPENDS
"libboost-date-time${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION},"
"libboost-regex${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION},"
"libboost-python${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION},"
"libboost-serialization${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION},"
"libboost-filesystem${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION},"
"libnexus0v5 (>= 4.3),"
"libjsoncpp1 (>=0.7.0),"
"libmuparser2v5,"
"libtbb2,"
"librdkafka1,librdkafka++1,"
"libpocofoundation${POCO_SOLIB_VERSION},libpocoutil${POCO_SOLIB_VERSION},libpoconet${POCO_SOLIB_VERSION},libpoconetssl${POCO_SOLIB_VERSION},libpococrypto${POCO_SOLIB_VERSION},libpocoxml${POCO_SOLIB_VERSION}"
)
if("${UNIX_CODENAME}" STREQUAL "bionic")
set(CPACK_DEBIAN_PACKAGE_DEPENDS
"${CPACK_DEBIAN_PACKAGE_DEPENDS},libgsl23," "liboce-foundation11,liboce-modeling11," "libqscintilla2-qt4-13,"
"jupyter-notebook," "libhdf5-cpp-100"
)
if(ENABLE_WORKBENCH)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqscintilla2-qt5-13")
endif()
elseif("${UNIX_DIST}" MATCHES "Ubuntu")
message(WARNING "Unsupported Debian-like OS: ${UNIX_CODENAME}. Packaging is unlikely to work correctly.")
endif()
# python requirements
set(CPACK_DEBIAN_PACKAGE_DEPENDS
"${CPACK_DEBIAN_PACKAGE_DEPENDS},python3-h5py,"
"python3-numpy,"
"python3-requests,"
"python3-sip,"
"python3-six,"
"python3-matplotlib,"
"python3-qtpy,"
"python3-scipy,"
"python3-toml,"
"python3-pycifrw (>= 4.2.1),"
"python3-yaml,"
"ipython3-qtconsole"
) # transitional package for bionic
if(ENABLE_WORKBENCH)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},python3-pyqt5,python3-psutil")
endif()
# parse list to string required for deb package
string(REPLACE ";" "," CPACK_DEBIAN_PACKAGE_DEPENDS ${CPACK_DEBIAN_PACKAGE_DEPENDS}) # fix up the fact that it was
# made as an array
string(REPLACE ",," "," CPACK_DEBIAN_PACKAGE_DEPENDS ${CPACK_DEBIAN_PACKAGE_DEPENDS})
endif()
# soft requirement of jemalloc if selected
if(USE_JEMALLOC)
message(STATUS "Adding jemalloc to the package requirements")
set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, jemalloc >= 3.0")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libjemalloc1 (>= 3.0)")
endif()
# run cpack configuration
include(CPack)
# let people know what is coming out the other end - must be after cpack generates value for rpm
message(STATUS "CPACK_PACKAGE_FILE_NAME = ${CPACK_PACKAGE_FILE_NAME}")
endif()