-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
executable file
·452 lines (393 loc) · 13 KB
/
CMakeLists.txt
File metadata and controls
executable file
·452 lines (393 loc) · 13 KB
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
444
445
446
447
448
449
450
451
452
cmake_minimum_required(VERSION 3.24)
# Use Conan for dependency provision?
option(CONAN "Use conan to find dependencies" ON)
if(CONAN)
# Fetch and include conan_provider.cmake if it doesn't exist
if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/conan_provider.cmake")
message(STATUS "Downloading conan_provider.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/refs/heads/develop2/conan_provider.cmake"
"${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/conan_provider.cmake"
)
else()
if(MSVC_DEV)
message(
"Conan provider .cmake file already exists.
For MSVC developers, an existing conan_provider.cmake may interfere with CMake configuration for the project, when conan has not already successfully installed packages.
Try deleting this file and reconfiguring if problems are encountered."
)
endif(MSVC_DEV)
endif()
# Add local dirs to cmake Module search path
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PROJECT_TOP_LEVEL_INCLUDES "cmake/Modules/conan_provider.cmake")
endif(CONAN)
# Set up the project
project(Dissolve LANGUAGES CXX C)
# Add our custom module search path
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules")
set(DESCRIPTION "Dissolve")
set(AUTHOR "Team Dissolve")
set(VERSION_MAJOR "1")
set(VERSION_MINOR "9")
set(VERSION_PATCH "0")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Set policy for automatic linkage of Qt libs to project
cmake_policy(SET CMP0020 NEW)
# Request C++17 Standard Support (Required for std::optional and auto types in lambda parameters)
set(CMAKE_CXX_STANDARD 20)
# We are setting up a development environment in MSVC
option(MSVC_DEV "Configuration is for a Visual Studio 2022 dev environment" OFF)
# Install GSL (GNU Scientific Library) with Conan for Windows and Unix-like systems
option(CONAN_GSL "Use conan to find GSL" ON)
# Find core dependencies
set(CORE_LINK_LIBS "")
find_package(CLI11 REQUIRED)
include_directories(${CLI11_INCLUDE_DIRS})
find_package(toml11 REQUIRED)
include_directories(${toml11_INCLUDE_DIRS})
find_package(pugixml REQUIRED)
include_directories(${pugixml_INCLUDE_DIRS})
list(APPEND CORE_LINK_LIBS "pugixml::pugixml")
find_package(GSL REQUIRED)
set(GSL_LIBS GSL::gsl GSL::gslcblas)
list(APPEND CORE_LINK_LIBS ${GSL_LIBS})
# For the Antlr runtime we need to do a bit more work since the cmake lib descriptions that get generated by Conan / Nix / other are not
# very consistent with their variable naming...
set(antlr4-cppruntime_INCLUDE_DIRS "")
set(antlr4-cppruntime_LIBS "")
find_package(antlr4-runtime REQUIRED)
if(CONAN)
include_directories(${antlr4-runtime_INCLUDE_DIRS})
list(APPEND CORE_LINK_LIBS antlr4_shared)
else(CONAN)
if(NOT antlr4-cppruntime_INCLUDE_DIRS)
# nix
if(ANTLR4_INCLUDE_DIR)
set(antlr4-cppruntime_INCLUDE_DIRS ${ANTLR4_INCLUDE_DIR})
link_directories(${ANTLR4_LIB_DIR})
set(antlr4-cppruntime_LIBS "antlr4-runtime")
else(ANTLR4_INCLUDE_DIR)
message(ERROR "Failed to find Antlr4 cpp runtime.")
endif(ANTLR4_INCLUDE_DIR)
endif(NOT antlr4-cppruntime_INCLUDE_DIRS)
message(STATUS "Antlr4 cpp runtime includes: ${antlr4-cppruntime_INCLUDE_DIRS}")
message(STATUS "Antlr4 cpp runtime libs: ${antlr4-cppruntime_LIBS}")
include_directories(${antlr4-cppruntime_INCLUDE_DIRS})
list(APPEND CORE_LINK_LIBS ${antlr4-cppruntime_LIBS})
endif(CONAN)
# Find Antlr4 Java Binary
find_package(ANTLR REQUIRED)
# Catch defines
if(PARALLEL)
add_definitions("-DPARALLEL")
find_package(MPI REQUIRED)
include_directories(${MPI_INCLUDE_PATH})
list(APPEND CORE_LINK_LIBS ${MPI_LIBRARIES})
endif(PARALLEL)
# Build with threads
option(MULTI_THREADING "Enable threading using tbb" ON)
set(THREADING_LINK_LIBS "")
if(MULTI_THREADING)
add_definitions("-DMULTITHREADING")
find_package(TBB REQUIRED)
include_directories(${TBB_INCLUDE_DIRS})
include_directories(${DPL_INCLUDE_DIRS})
list(APPEND THREADING_LINK_LIBS "TBB::tbb")
if(CONAN)
find_package(ParallelSTL REQUIRED)
include_directories(${ParallelSTL_INCLUDE_DIRS})
list(APPEND THREADING_LINK_LIBS ${ParallelSTL_LINK_LIBS})
endif(CONAN)
message("Threading Link Libs: ${THREADING_LINK_LIBS}")
endif(MULTI_THREADING)
if(GUI)
find_package(Freetype REQUIRED)
find_package(FTGL REQUIRED)
list(APPEND CMAKE_PREFIX_PATH "${QT_BASE_DIR}")
find_package(OpenGL REQUIRED)
find_package(
Qt6
COMPONENTS Core
DBusTools
Gui
Widgets
OpenGL
OpenGLWidgets
Qml
QmlModels
QmlTools
Quick
Quick3D
3DCore
3DExtras
3DRender
3DExtras
QuickWidgets
QuickControls2
REQUIRED
)
# Make sure we enable automated handling of Qt files
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
# Compile QML to build subdirectory qml
set(QT_QML_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/qml)
# Disable Qt macros
add_definitions(-DQT_NO_KEYWORDS)
endif(GUI)
# Perform system-specific setup -- Windows
if(WIN32)
if(PARALLEL)
set(target_name Dissolve-MPI)
else(PARALLEL)
set(target_name Dissolve)
set(gui_target_name Dissolve-GUI)
set(qmlgui_target_name Dissolve-GUI-QML)
endif(PARALLEL)
# Adjust external include directories for GUI
if(GUI)
include_directories(${FTGL_INCLUDE_DIRS})
endif(GUI)
# Format requires on MSVC std:c++latest, so we have to ask for C++23, despite the fact it's part of the C++20 standard.
set(CMAKE_CXX_STANDARD 23)
# By default, Visual Studio lies about what C++ version it's using unless you pass it a flag to tell it not to lie. This breaks the
# TOML11 library, since it checks to C++ version to see if `std::result_of` has been deprecated.
add_definitions(/Zc:__cplusplus)
# Add defines for Windows systems - NOMINMAX to prevent conflicts with std::min() and std::max() - NOGDI to prevent conflicts arising from
# Windows defining ERROR as a global macro (used in ANTLR4)
add_definitions(-DNOMINMAX -DNOGDI)
# Needed for Qt 6.4
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-")
endif(WIN32)
# -- Unix
if(UNIX)
if(PARALLEL)
set(target_name dissolve-mpi)
else(PARALLEL)
set(target_name dissolve)
set(gui_target_name dissolve-gui)
set(qmlgui_target_name dissolve-gui-qml)
endif(PARALLEL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif(UNIX)
# -- OSX
if(APPLE)
list(APPEND CMAKE_BUILD_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
# Set some specific C++11 related options here (set_property below does not seem to persist)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
# Suppress warnings for undefined template vars
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-undefined-var-template")
if(PARALLEL)
set(target_name dissolve-mpi)
else(PARALLEL)
set(target_name dissolve)
set(gui_target_name dissolve-gui)
set(qmlgui_target_name dissolve-gui-qml)
endif(PARALLEL)
add_definitions(-D_MAC)
if(GUI)
# Find GLUT
find_package(GLUT REQUIRED)
# Adjust external include directories for GUI
include_directories(${FTGL_INCLUDE_DIRS})
include_directories(${FREETYPE_INCLUDE_DIRS})
endif(GUI)
endif(APPLE)
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
set(SRCS src/)
# Set bundle info
if(APPLE)
set(MACOSX_BUNDLE_ICON_FILE "Dissolve.icns")
set(MACOSX_BUNDLE_GUI_IDENTIFIER "Dissolve")
set(MACOSX_BUNDLE_LONG_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set(MACOSX_BUNDLE_BUNDLE_NAME "Dissolve")
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}")
set(MACOSX_BUNDLE_BUNDLE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set(MACOSX_BUNDLE_COPYRIGHT "${AUTHOR}")
endif(APPLE)
# Process CMakeLists in subdirs
set(MODULE_LINK_LIBS
""
CACHE INTERNAL ""
)
set(MODULEGUI_LINK_LIBS
""
CACHE INTERNAL ""
)
set(MODULENOGUI_LINK_LIBS
""
CACHE INTERNAL ""
)
set(FF_LINK_LIBS
""
CACHE INTERNAL ""
)
add_subdirectory(${SRCS})
# Add executable target(s)
add_executable(${target_name} MACOSX_BUNDLE ${SRCS}/main.cpp)
# Set project-local include directories for target
target_include_directories(
${target_name} PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_BINARY_DIR}/src ${FREETYPE_INCLUDE_DIRS} ${ANTLR4_INCLUDE_DIRS}
${ANTLR_OUTPUT_DIRS}
)
# Add GUI targets
if(GUI)
# Main Dissolve GUI
qt_add_executable(${gui_target_name} MACOSX_BUNDLE ${SRCS}/dissolve-gui.cpp)
# Set project-local include directories for target
target_include_directories(
${gui_target_name}
PRIVATE ${PROJECT_SOURCE_DIR}/src
${PROJECT_BINARY_DIR}/src
${CMAKE_BINARY_DIR}/src/gui/gui_autogen/include
${FREETYPE_INCLUDE_DIRS}
${Qt6Core_INCLUDE_DIRS}
${Qt6Gui_INCLUDE_DIRS}
${Qt6OpenGL_INCLUDE_DIRS}
${Qt6Widgets_INCLUDE_DIRS}
${Qt6OpenGL_INCLUDE_DIRS}
${Qt6OpenGLWidgets_INCLUDE_DIRS}
)
# Dissolve QML GUI
qt_add_executable(${qmlgui_target_name} MACOSX_BUNDLE ${SRCS}/dissolve-gui-qml.cpp)
set_source_files_properties(${SRCS}/gui-qml/qml/DissolveMain.qml PROPERTIES QT_RESOURCE_ALIAS qml/DissolveMain.qml)
qt_add_qml_module(
${qmlgui_target_name}
VERSION
0.1
URI
Dissolve
QML_FILES
${SRCS}/gui-qml/qml/DissolveMain.qml
)
# Set project-local include directories for target (we expect to need less of these dependencies over time)
target_include_directories(
${qmlgui_target_name} PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_BINARY_DIR}/src ${CMAKE_BINARY_DIR}/src/gui/gui_autogen/include
${Qt6Core_INCLUDE_DIRS} ${Qt6Gui_INCLUDE_DIRS}
)
if(APPLE)
# Don't link dead code on Apple
target_link_options(${qmlgui_target_name} PRIVATE "LINKER:-dead_strip")
endif(APPLE)
endif(GUI)
# Set basic link libs for executables
set(BASIC_LINK_LIBS
# Main libs
main
classes
kernels
potentials
module
moduleregistry
io
export
import
neta
analyser
generator
keywords
expression
items
base
math
data
sginfo
# Forcefields
ff
${FF_LINK_LIBS}
# Modules
${MODULE_LINK_LIBS}
)
# Set linker options for complete/no archive
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(WHOLE_ARCHIVE_FLAG "-Wl,-all_load")
else()
set(WHOLE_ARCHIVE_FLAG "-Wl,-whole-archive")
set(NO_WHOLE_ARCHIVE_FLAG "-Wl,-no-whole-archive")
endif()
# Enable build of test suite?
option(BUILD_TESTS "Build test suite" OFF)
if(BUILD_TESTS)
enable_testing()
add_subdirectory(examples)
add_subdirectory(tests)
endif(BUILD_TESTS)
if(BUILD_BENCHMARKS)
find_package(benchmark REQUIRED)
set(BENCHMARK_ENABLE_TESTING "OFF")
add_subdirectory(benchmark)
endif(BUILD_BENCHMARKS)
# Build CLI target executable
target_link_libraries(
${target_name}
PUBLIC ${WHOLE_ARCHIVE_FLAG} ${BASIC_LINK_LIBS} ${NO_WHOLE_ARCHIVE_FLAG}
PRIVATE # External libs
${CORE_LINK_LIBS} ${THREADING_LINK_LIBS}
)
# Build GUI target executables
if(GUI)
add_subdirectory(QuickPlot/src)
# Main Dissolve GUI
target_link_libraries(
${gui_target_name}
PUBLIC ${WHOLE_ARCHIVE_FLAG}
${BASIC_LINK_LIBS}
# Module gui libs
${MODULEGUI_LINK_LIBS}
moduleWidgetProducer
# Main gui libs
render
widgets
keywordWidgets
delegates
models
gui
${NO_WHOLE_ARCHIVE_FLAG}
PRIVATE # External libs
Qt6::Widgets
Qt6::Core
Qt6::Quick3D
OpenGL::GL
${GUI_LINK_LIBS}
${FREETYPE_LIBRARIES}
${FTGL_LIBRARIES}
${CORE_LINK_LIBS}
${THREADING_LINK_LIBS}
)
set_target_properties(${qmlgui_target_name} PROPERTIES QML_IMPORT_PATH ${QT_QML_OUTPUT_DIRECTORY})
# Link to models when developing QML Dissolve in Visual Studio
if(MSVC_DEV)
set(QML_GUI_LIBS models)
endif(MSVC_DEV)
# Main Dissolve GUI
target_link_libraries(
${qmlgui_target_name}
PUBLIC ${WHOLE_ARCHIVE_FLAG} ${BASIC_LINK_LIBS}
# Module gui libs
gui-qml ${QML_GUI_LIBS} ${NO_WHOLE_ARCHIVE_FLAG} QuickPlotplugin
PRIVATE # External libs
Qt6::Quick3D Qt6::Qml Qt6::Widgets ${CORE_LINK_LIBS} ${THREADING_LINK_LIBS}
)
qt_generate_deploy_qml_app_script(
TARGET
${gui_target_name}
FILENAME_VARIABLE
deploy_script
NO_UNSUPPORTED_PLATFORM_ERROR
MACOS_BUNDLE_POST_BUILD
NO_UNSUPPORTED_PLATFORM_ERROR
DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM
)
install(SCRIPT ${deploy_script})
endif(GUI)
# Install for MSVC
if(MSVC_DEV)
include(msvc-dissolve-dev)
setup_msvc()
endif(MSVC_DEV)