forked from opencor/opencor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
1720 lines (1314 loc) · 58.3 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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
cmake_minimum_required(VERSION 3.22)
# Make sure that we are using the compilers we support
# Note #1: indeed, if other compilers are installed on a developer's machine
# then CMake may prefer them over the ones we support since it searches
# for a compiler in a very specific order (see
# https://cmake.org/pipermail/cmake/2013-March/053819.html)...
# Note #2: yes, this needs to be done before defining our project...
if(WIN32)
find_program(C_COMPILER cl)
find_program(CXX_COMPILER cl)
else()
find_program(C_COMPILER gcc)
find_program(CXX_COMPILER g++)
endif()
set(ENV{CC} ${C_COMPILER})
set(ENV{CXX} ${CXX_COMPILER})
# Project definition
project(OpenCOR)
# Set the new policies that affect our build.
foreach(NEW_POLICY CMP0135)
if(POLICY ${NEW_POLICY})
cmake_policy(SET ${NEW_POLICY} NEW)
endif()
endforeach()
# Our options
option(ENABLE_CLANG_TIDY "Enable the use of Clang-Tidy" OFF)
option(ENABLE_SAMPLE_PLUGINS "Enable the sample plugins to be built" OFF)
option(ENABLE_TEST_PLUGINS "Enable the test plugins to be built" OFF)
option(ENABLE_TESTS "Enable the tests to be built" OFF)
if(NOT WIN32 AND NOT APPLE)
option(USE_PREBUILT_ICU_PACKAGE "Use the pre-built version of the ICU package" ON)
option(USE_PREBUILT_MESA_PACKAGE "Use the pre-built version of the Mesa package" ON)
endif()
option(USE_PREBUILT_QTWEBKIT_PACKAGE "Use the pre-built version of the QtWebKit package" ON)
option(USE_PREBUILT_BIOSIGNALML_PACKAGE "Use the pre-built version of the BioSignalML package" ON)
option(USE_PREBUILT_CELLMLAPI_PACKAGE "Use the pre-built version of the CellML API package" ON)
option(USE_PREBUILT_LIBGIT2_PACKAGE "Use the pre-built version of the libgit2 package" ON)
option(USE_PREBUILT_LIBNUML_PACKAGE "Use the pre-built version of the libNuML package" ON)
option(USE_PREBUILT_LIBSBML_PACKAGE "Use the pre-built version of the libSBML package" ON)
option(USE_PREBUILT_LIBSEDML_PACKAGE "Use the pre-built version of the libSEDML package" ON)
option(USE_PREBUILT_LIBXDIFF_PACKAGE "Use the pre-built version of the LibXDiff package" ON)
option(USE_PREBUILT_LLVMCLANG_PACKAGE "Use the pre-built version of the LLVMClang package" ON)
option(USE_PREBUILT_OAUTH_PACKAGE "Use the pre-built version of the OAuth package" ON)
option(USE_PREBUILT_OPENSSL_PACKAGE "Use the pre-built version of the OpenSSL package" ON)
option(USE_PREBUILT_PYTHON_PACKAGE "Use the pre-built version of the Python package" ON)
option(USE_PREBUILT_PYTHON_PACKAGES_PACKAGE "Use the pre-built version of various Python packages" ON)
option(USE_PREBUILT_PYTHONQT_PACKAGE "Use the pre-built version of the PythonQt package" ON)
option(USE_PREBUILT_QSCINTILLA_PACKAGE "Use the pre-built version of the QScintilla package" ON)
option(USE_PREBUILT_QWT_PACKAGE "Use the pre-built version of the Qwt package" ON)
option(USE_PREBUILT_SUNDIALS_PACKAGE "Use the pre-built version of the SUNDIALS package" ON)
option(USE_PREBUILT_ZLIB_PACKAGE "Use the pre-built version of the zlib package" ON)
if(ENABLE_TEST_PLUGINS)
option(USE_PREBUILT_ZINC_PACKAGE "Use the pre-built version of the Zinc package" ON)
endif()
# Make sure that we are using the compiler we support
if(WIN32)
string(REPLACE "." ";"
CMAKE_C_COMPILER_VERSION_LIST "${CMAKE_C_COMPILER_VERSION}")
string(REPLACE "." ";"
CMAKE_CXX_COMPILER_VERSION_LIST "${CMAKE_CXX_COMPILER_VERSION}")
list(GET CMAKE_C_COMPILER_VERSION_LIST 0 CMAKE_C_COMPILER_VERSION_MAJOR)
list(GET CMAKE_C_COMPILER_VERSION_LIST 1 CMAKE_C_COMPILER_VERSION_MINOR)
list(GET CMAKE_CXX_COMPILER_VERSION_LIST 0 CMAKE_CXX_COMPILER_VERSION_MAJOR)
list(GET CMAKE_CXX_COMPILER_VERSION_LIST 1 CMAKE_CXX_COMPILER_VERSION_MINOR)
if( NOT( "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC"
AND "${CMAKE_C_COMPILER_VERSION_MAJOR}" STREQUAL "19"
AND "${CMAKE_C_COMPILER_VERSION_MINOR}" STREQUAL "29")
OR NOT( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC"
AND "${CMAKE_CXX_COMPILER_VERSION_MAJOR}" STREQUAL "19"
AND "${CMAKE_CXX_COMPILER_VERSION_MINOR}" STREQUAL "29"))
message(FATAL_ERROR "${CMAKE_PROJECT_NAME} can only be built using MSVC 2019 on Windows...")
endif()
elseif(APPLE)
if( NOT( "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang"
OR "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
AND NOT( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang"
OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang"))
message(FATAL_ERROR "${CMAKE_PROJECT_NAME} can only be built using (Apple) Clang on macOS...")
endif()
else()
if( NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU"
AND NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
message(FATAL_ERROR "${CMAKE_PROJECT_NAME} can only be built using GCC/G++ on Linux...")
endif()
endif()
# Use the C++14 standard
set(CMAKE_CXX_STANDARD 14)
# Determine the effective build directory
set(PROJECT_BUILD_DIR ${CMAKE_BINARY_DIR})
if(APPLE AND "${CMAKE_GENERATOR}" STREQUAL "Xcode")
# With Xcode, we have a configuration directory, but it messes up our build
# system, so ask for all the binaries to be generated in our build folder
set(XCODE TRUE)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BUILD_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BUILD_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BUILD_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BUILD_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BUILD_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BUILD_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BUILD_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BUILD_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BUILD_DIR})
else()
# Check whether there is a configuration directory (the case with MSVC) and,
# if so, make use of it
set(XCODE FALSE)
if(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".")
set(PROJECT_BUILD_DIR ${PROJECT_BUILD_DIR}/${CMAKE_CFG_INTDIR})
endif()
endif()
# Make sure that we are building OpenCOR on a supported architecture
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
message(FATAL_ERROR "${CMAKE_PROJECT_NAME} can only be built in 64-bit mode...")
endif()
# By default, we are building a release version of OpenCOR, unless we are
# explicitly asked for a debug version
if( "${CMAKE_BUILD_TYPE}" STREQUAL ""
OR "${CMAKE_BUILD_TYPE}" STREQUAL "Release")
set(BUILD_INFORMATION "Building a release version of ${CMAKE_PROJECT_NAME}")
set(RELEASE_MODE TRUE)
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(BUILD_INFORMATION "Building a debug version of ${CMAKE_PROJECT_NAME}")
set(RELEASE_MODE FALSE)
else()
message(FATAL_ERROR "${CMAKE_PROJECT_NAME} can only be built in Release or Debug mode...")
endif()
# Try to build our silent program
set(SILENTRUN ${PROJECT_BUILD_DIR}/silentrun${CMAKE_EXECUTABLE_SUFFIX})
try_compile(SILENTRUN_EXE ${PROJECT_BUILD_DIR} ${CMAKE_SOURCE_DIR}/cmake/silentrun.c
COPY_FILE ${SILENTRUN})
if(NOT SILENTRUN_EXE)
message(FATAL_ERROR "silentrun could not be built...")
endif()
# Try to build our runpath2rpath program, if we are on Linux
if(NOT WIN32 AND NOT APPLE)
set(RUNPATH2RPATH ${PROJECT_BUILD_DIR}/runpath2rpath)
try_compile(RUNPATH2RPATH_EXE ${PROJECT_BUILD_DIR} ${CMAKE_SOURCE_DIR}/cmake/runpath2rpath.c
COPY_FILE ${RUNPATH2RPATH})
if(NOT RUNPATH2RPATH_EXE)
message(FATAL_ERROR "runpath2rpath could not be built...")
endif()
endif()
# Look and get ready for Clang-Tidy
# Note: we don't want Clang-Tidy to analyse files in our build directory.
# Indeed, some files generated by Qt may result in Clang-Tidy warnings
# that have nothing to do with OpenCOR. We therefore ignore them by
# creating a special .clang-tidy file in our build directory. That file
# disables all checks but one, which is necessary for Clang-Tidy to work.
# That check is for boost-use-to-string, which is as if we didn't have
# any checks since we don't use Boost ...
if(ENABLE_CLANG_TIDY)
find_program(CLANG_TIDY clang-tidy)
if(CLANG_TIDY)
file(WRITE "${PROJECT_BUILD_DIR}/.clang-tidy"
"---
Checks: >-
-*,
boost-use-to-string
...
")
else()
message(FATAL_ERROR "Clang-Tidy could not be found...")
endif()
endif()
# Use buildcache as a launcher or clcache/ccache as a backup
find_program(BUILDCACHE buildcache)
if(BUILDCACHE)
set(CMAKE_C_COMPILER_LAUNCHER ${BUILDCACHE})
set(CMAKE_CXX_COMPILER_LAUNCHER ${BUILDCACHE})
set(COMPILER_LAUNCHER_NAME buildcache)
else()
if(WIN32)
find_program(CLCACHE clcache)
if(CLCACHE)
set(CLCACHEWRAPPER ${CMAKE_BINARY_DIR}/clcachewrapper)
try_compile(CLCACHEWRAPPER_EXE ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/clcachewrapper.c
COPY_FILE ${CLCACHEWRAPPER})
if(CLCACHEWRAPPER_EXE)
set(CMAKE_C_COMPILER_LAUNCHER ${CLCACHEWRAPPER})
set(CMAKE_CXX_COMPILER_LAUNCHER ${CLCACHEWRAPPER})
set(COMPILER_LAUNCHER_NAME clcache)
endif()
endif()
else()
find_program(CCACHE ccache)
if(CCACHE)
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE})
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE})
set(COMPILER_LAUNCHER_NAME ccache)
endif()
endif()
endif()
# Keep track of some basic information about Qt, after making sure that we have
# the version of Qt that we need
find_package(Qt5Core REQUIRED)
set(QT_VERSION ${Qt5Core_VERSION})
set(QT_VERSION_MAJOR ${Qt5Core_VERSION_MAJOR})
set(QT_VERSION_MINOR ${Qt5Core_VERSION_MINOR})
set(REQUIRED_QT_LTS_VERSION_MAJOR 5)
set(REQUIRED_QT_LTS_VERSION_MINOR 12)
if( NOT ${QT_VERSION_MAJOR} EQUAL ${REQUIRED_QT_LTS_VERSION_MAJOR}
OR NOT ${QT_VERSION_MINOR} EQUAL ${REQUIRED_QT_LTS_VERSION_MINOR})
message(FATAL_ERROR "${CMAKE_PROJECT_NAME} can only be built using Qt ${REQUIRED_QT_LTS_VERSION_MAJOR}.${REQUIRED_QT_LTS_VERSION_MINOR}.x LTS (you are using Qt ${QT_VERSION})...")
endif()
set(QT_DIR ${_qt5Core_install_prefix})
set(QT_BINARIES_DIR ${QT_DIR}/bin)
set(QT_LIBRARIES_DIR ${QT_DIR}/lib)
set(QT_PLUGINS_DIR ${QT_DIR}/plugins)
get_target_property(QMAKE ${Qt5Core_QMAKE_EXECUTABLE} IMPORTED_LOCATION)
if(APPLE)
# Account for the fact that QMake (from Qt 5.12) doesn't work with Xcode 15
# Note: see https://bugreports.qt.io/browse/QTBUG-117225...
set(QMAKE_COMMAND ${QMAKE} -Wnone -early "QMAKE_DEFAULT_LIBDIRS=$(xcrun -show-sdk-path)/usr/lib")
else()
set(QMAKE_COMMAND ${QMAKE} -Wnone)
endif()
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Find out, on Linux, whether we are using a RHEL-based distribution
# Note: this is needed for our Python bindings...
if(NOT WIN32 AND NOT APPLE)
cmake_host_system_information(RESULT DISTRIB_INFO QUERY DISTRIB_INFO)
set(RHEL_LINUX_DISTRIBS centos fedora rhel rocky)
if(DISTRIB_INFO_ID IN_LIST RHEL_LINUX_DISTRIBS)
set(RHEL_LINUX_DISTRIB ON)
endif()
endif()
# Determine our platform directory
if(WIN32)
set(PLATFORM windows)
if(RELEASE_MODE)
set(TARGET_PLATFORM ${PLATFORM}.release)
else()
set(TARGET_PLATFORM ${PLATFORM}.debug)
endif()
else()
if(APPLE)
set(PLATFORM macos)
else()
set(PLATFORM linux)
endif()
set(TARGET_PLATFORM ${PLATFORM})
endif()
# Location of our distribution files
set(DISTRIB_DIR ${CMAKE_SOURCE_DIR}/distrib)
set(PLATFORM_DISTRIB_DIR ${DISTRIB_DIR}/${PLATFORM})
# Default location of external binaries and packages
if(WIN32)
if(RELEASE_MODE)
set(EXTERNAL_PACKAGE_DIR ext/release)
else()
set(EXTERNAL_PACKAGE_DIR ext/debug)
endif()
set(DEST_EXTERNAL_LIBRARIES_DIR bin)
else()
set(EXTERNAL_PACKAGE_DIR ext)
if(APPLE)
set(DEST_EXTERNAL_LIBRARIES_DIR ${CMAKE_PROJECT_NAME}.app/Contents/Frameworks)
else()
set(DEST_EXTERNAL_LIBRARIES_DIR lib)
endif()
endif()
set(FULL_DEST_EXTERNAL_LIBRARIES_DIR ${PROJECT_BUILD_DIR}/${DEST_EXTERNAL_LIBRARIES_DIR})
if(NOT EXISTS ${FULL_DEST_EXTERNAL_LIBRARIES_DIR})
file(MAKE_DIRECTORY ${FULL_DEST_EXTERNAL_LIBRARIES_DIR})
endif()
# Some in-house CMake macros
include(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
# Add support for external projects
include(ExternalProject)
# On macOS, make sure that we support version 10.14 and later, unless a specific
# deployment target has been specified, and also make sure that we target x86_64
if(APPLE)
if("${CMAKE_OSX_DEPLOYMENT_TARGET}" STREQUAL "")
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.14)
endif()
set(BUILD_INFORMATION "${BUILD_INFORMATION} for macOS ${CMAKE_OSX_DEPLOYMENT_TARGET} and later")
set(CMAKE_OSX_ARCHITECTURES x86_64)
endif()
# A few constants to help us with building an external project
# Note: the idea is to ensure that we compile external projects using the exact
# same compilers than the ones we want to use in the first place (i.e.
# C_COMPILER and CXX_COMPILER), as well as take advantage of ccache, if
# available, and ensure that RPATH is properly handled on macOS...
set(CMAKE_ARGS
-DCMAKE_C_COMPILER=${C_COMPILER}
-DCMAKE_CXX_COMPILER=${CXX_COMPILER}
)
if(CMAKE_C_COMPILER_LAUNCHER AND CMAKE_CXX_COMPILER_LAUNCHER)
list(APPEND CMAKE_ARGS
-DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}
-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
)
endif()
if(APPLE)
list(APPEND CMAKE_ARGS
-DCMAKE_MACOSX_RPATH=ON
-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
)
endif()
if(WIN32)
set(MAKE_NMAKE_COMMAND nmake)
set(MAKE_JOM_COMMAND jom)
else()
set(MAKE_NMAKE_COMMAND make)
set(MAKE_JOM_COMMAND ${MAKE_NMAKE_COMMAND})
include(ProcessorCount)
ProcessorCount(PROCESSOR_COUNT)
if(NOT PROCESSOR_COUNT EQUAL 0)
set(MAKE_NMAKE_COMMAND ${MAKE_NMAKE_COMMAND} -j ${PROCESSOR_COUNT})
set(MAKE_JOM_COMMAND ${MAKE_JOM_COMMAND} -j ${PROCESSOR_COUNT})
endif()
endif()
# A couple of variables to make it easier to specify library names with a
# version (e.g., to be able to reference libz.so.1 and libz.1.dylib, we would
# use libz${PRE}.1${POST})
if(APPLE)
set(CMAKE_SHARED_LIBRARY_SUFFIX_POST ${CMAKE_SHARED_LIBRARY_SUFFIX})
elseif(NOT WIN32)
set(CMAKE_SHARED_LIBRARY_SUFFIX_PRE ${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()
# Debug tag for a Windows debug build
if(WIN32 AND NOT RELEASE_MODE)
set(DEBUG_TAG d)
endif()
# On Windows, specify the version of ICU that we are using while on Linux, add
# our copy of the ICU and Mesa libraries
# Note #1: on Linux, ICU is needed so that our external projects that need ICU
# (e.g. QtWebKit) can rely on the ICU version that we want to use...
# Note #2: on Linux, Mesa is needed so that we can run OpenCOR on machines that
# don't have 'proper' OpenGL support (e.g. on a Linux virtual machine
# in VirtualBox)...
if(WIN32)
set(ICU_VERSION 57)
elseif(NOT APPLE)
add_subdirectory(src/3rdparty/linux/icu)
add_subdirectory(src/3rdparty/linux/mesa)
endif()
# Retrieve or build our copy of QtWebKit
add_subdirectory(src/3rdparty/QtWebKit)
# Required Qt modules
if(ENABLE_TESTS)
set(TEST Test)
endif()
set(REQUIRED_QT_MODULES
Network
${TEST}
Widgets
)
if(USE_PREBUILT_QTWEBKIT_PACKAGE)
set(WEBKIT WebKit)
set(WEBKITWIDGETS WebKitWidgets)
if(WIN32)
list(APPEND REQUIRED_QT_MODULES ${WEBKIT})
endif()
endif()
foreach(REQUIRED_QT_MODULE ${REQUIRED_QT_MODULES})
find_package(Qt5${REQUIRED_QT_MODULE} REQUIRED)
endforeach()
# Common Qt libraries
set(QT_LIBRARIES
Core
Gui
Help
Multimedia
MultimediaWidgets
Network
OpenGL
Positioning
PrintSupport
Qml
Quick
Sensors
Sql
Svg
${TEST}
WebChannel
${WEBKIT}
${WEBKITWIDGETS}
Widgets
Xml
XmlPatterns
)
# On macOS, keep track of the Qt libraries against which we need to link and
# make sure that we always use their release version
# Note: indeed, from Qt 5.12.5, to build a debug version of a Qt-based
# application implies using the debug version of the Qt libraries, which
# we don't want to do (since it would require us to generate both a
# release and a debug version of our Qt-based third-party libraries)...
if(APPLE)
if(ENABLE_TESTS)
set(TEST Test)
endif()
set(MACOS_QT_LIBRARIES
${QT_LIBRARIES}
Concurrent
DBus
MacExtras
)
foreach(QT_LIBRARY ${MACOS_QT_LIBRARIES})
find_package(Qt5${QT_LIBRARY} REQUIRED)
get_target_property(QT_RELEASE_LIBRARY Qt5::${QT_LIBRARY} IMPORTED_LOCATION_RELEASE)
set_target_properties(Qt5::${QT_LIBRARY} PROPERTIES "IMPORTED_LOCATION_DEBUG" "${QT_RELEASE_LIBRARY}")
endforeach()
endif()
# Some general build settings
# Note: we force the overriding of CMAKE_CXX_FLAGS_RELEASE and
# CMAKE_CXX_FLAGS_DEBUG, so that we can really use the compilation flags
# we want, as opposed to CMake forcing us to use the ones it wants...
set(CMAKE_CXX_FLAGS_RELEASE "" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG "" CACHE STRING "" FORCE)
if(WIN32)
set(CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /WX /GR /EHsc")
# Note: MSVC has a /Wall flag, but it results in MSVC being very pedantic,
# so instead we use what MSVC recommends for production code, which is
# /W3 and which is also what CMake uses by default...
set(LINK_FLAGS_PROPERTIES "/STACK:10000000")
else()
set(CMAKE_CXX_FLAGS "-Wall -W -Werror")
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
set(LINK_FLAGS_PROPERTIES "-stdlib=libc++")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -no-pie")
# Note: needed so that the OpenCOR binary doesn't get considered as a
# shared library file on Ubuntu when using Nautilus (see
# https://stackoverflow.com/a/45332687)...
endif()
endif()
# On macOS, we want to be able to access Cocoa
if(APPLE)
set(LINK_FLAGS_PROPERTIES "${LINK_FLAGS_PROPERTIES} -framework AppKit")
endif()
# Some build settings that depend on whether we want a release or a debug
# version of OpenCOR
if(RELEASE_MODE)
# Default release compiler and linker settings
if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DNDEBUG /MD /O2 /Ob2")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -ffast-math")
endif()
if(NOT WIN32 AND NOT APPLE)
set(LINK_FLAGS_PROPERTIES "${LINK_FLAGS_PROPERTIES} -Wl,-s")
# Note #1: -Wl,-s strips all the symbols, thus reducing the final size
# of OpenCOR or one of its shared libraries...
# Note #2: the above linking option has become obsolete on macOS...
endif()
# Make sure that debugging is disabled in Qt
add_compile_definitions(QT_NO_DEBUG)
else()
# Default debug compiler and linker settings
if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_DEBUG /MDd /Z7 /Ob0 /Od /RTC1")
set(LINK_FLAGS_PROPERTIES "${LINK_FLAGS_PROPERTIES} /DEBUG")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
endif()
# Make sure that debugging is enabled in Qt
add_compile_definitions(QT_DEBUG)
endif()
# Ask for Qt deprecated uses to be reported
add_compile_definitions(QT_DEPRECATED_WARNINGS)
# Make sure that Unicode is defined
# Note: at least needed for QtSingleApplication on Windows...
add_compile_definitions(UNICODE)
# Destination of our plugins so that we don't have to deploy OpenCOR on Windows
# and Linux before being able to test it
if(APPLE)
set(DEST_PLUGINS_DIR ${PROJECT_BUILD_DIR}/${CMAKE_PROJECT_NAME}.app/Contents/PlugIns/${CMAKE_PROJECT_NAME})
else()
set(DEST_PLUGINS_DIR ${PROJECT_BUILD_DIR}/plugins/${CMAKE_PROJECT_NAME})
endif()
# Set the RPATH (and RPATH link, if needed) information on Linux and macOS
if(APPLE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR TRUE)
set(CMAKE_INSTALL_RPATH "@executable_path/../Frameworks;@executable_path/../PlugIns/${CMAKE_PROJECT_NAME}")
elseif(NOT WIN32)
set(CMAKE_SKIP_RPATH TRUE)
set(LINK_RPATH_FLAG "-Wl,-rpath,'$ORIGIN/../lib'")
if(NOT RELEASE_MODE)
set(LINK_RPATH_FLAG "${LINK_RPATH_FLAG} -Wl,-rpath,'$ORIGIN/lib'")
# Note: this makes it possible to run a debug version of OpenCOR from
# within Qt Creator...
endif()
set(LINK_FLAGS_PROPERTIES "${LINK_FLAGS_PROPERTIES} -Wl,-rpath-link,${QT_LIBRARIES_DIR} ${LINK_RPATH_FLAG}")
endif()
# Show what we are about to build
if(COMPILER_LAUNCHER_NAME)
set(LAUNCHER_INFORMATION " (and ${COMPILER_LAUNCHER_NAME})")
endif()
message("${BUILD_INFORMATION} using Qt ${QT_VERSION} LTS${LAUNCHER_INFORMATION}...")
# Keep track of our source and build directories (needed to run our tests)
set(SOURCE_DIRECTORY_FILENAME ${PROJECT_BUILD_DIR}/sourcedirectory.txt)
set(BUILD_DIRECTORY_FILENAME ${PROJECT_BUILD_DIR}/builddirectory.txt)
file(WRITE ${SOURCE_DIRECTORY_FILENAME} "${CMAKE_SOURCE_DIR}")
file(WRITE ${BUILD_DIRECTORY_FILENAME} "${PROJECT_BUILD_DIR}")
track_files(
${SOURCE_DIRECTORY_FILENAME}
${BUILD_DIRECTORY_FILENAME}
)
# Version/snapshot of OpenCOR
if("${PROJECT_VERSION}" STREQUAL "")
set(SNAPSHOT ON)
endif()
string(TIMESTAMP DATE "%Y-%m-%d")
if(SNAPSHOT)
set(VERSION ${DATE})
else()
set(VERSION ${PROJECT_VERSION})
endif()
set(VERSION_DATE_FILENAME ${PROJECT_BUILD_DIR}/versiondate.txt)
file(WRITE ${VERSION_DATE_FILENAME} "${VERSION}\n${DATE}\n")
track_files(${VERSION_DATE_FILENAME})
# Configure our QRC files
set(COMMON_QRC_FILENAME ${PROJECT_BUILD_DIR}/res/common.qrc)
set(I18N_QRC_FILENAME ${PROJECT_BUILD_DIR}/res/i18n.qrc)
configure_file(${CMAKE_SOURCE_DIR}/res/common.qrc.in ${COMMON_QRC_FILENAME})
configure_file(${CMAKE_SOURCE_DIR}/res/i18n.qrc.in ${I18N_QRC_FILENAME})
# Files that make up the GUI version of OpenCOR
set(SOURCES
src/checkforupdatesdialog.cpp
src/main.cpp
src/mainwindow.cpp
src/pluginsdialog.cpp
src/preferencesdialog.cpp
src/splashscreenwindow.cpp
src/misc/cliapplication.cpp
src/misc/cliutils.cpp
src/misc/guiapplication.cpp
src/misc/guiutils.cpp
src/plugins/cliinterface.cpp
src/plugins/coreinterface.cpp
src/plugins/datastoreinterface.cpp
src/plugins/filehandlinginterface.cpp
src/plugins/filetypeinterface.cpp
src/plugins/guiinterface.cpp
src/plugins/i18ninterface.cpp
src/plugins/plugin.cpp
src/plugins/plugininfo.cpp
src/plugins/plugininterface.cpp
src/plugins/pluginmanager.cpp
src/plugins/preferencesinterface.cpp
src/plugins/pythoninterface.cpp
src/plugins/solverinterface.cpp
src/plugins/viewinterface.cpp
src/plugins/windowinterface.cpp
)
set(UIS
src/checkforupdatesdialog.ui
src/mainwindow.ui
src/pluginsdialog.ui
src/preferencesdialog.ui
src/splashscreenwindow.ui
)
set(RESOURCES
${COMMON_QRC_FILENAME}
${I18N_QRC_FILENAME}
res/translations.qrc
res/ui.qrc
)
# Files that make up the CLI version of OpenCOR (Windows specific)
if(WIN32)
set(WINDOWS_CLI_SOURCES
src/misc/cliapplication.cpp
src/misc/cliutils.cpp
src/plugins/cliinterface.cpp
src/plugins/coreinterface.cpp
src/plugins/datastoreinterface.cpp
src/plugins/filehandlinginterface.cpp
src/plugins/filetypeinterface.cpp
src/plugins/plugin.cpp
src/plugins/plugininfo.cpp
src/plugins/plugininterface.cpp
src/plugins/pluginmanager.cpp
src/plugins/pythoninterface.cpp
src/plugins/solverinterface.cpp
src/windows/main.cpp
)
set(WINDOWS_CLI_RESOURCES
${COMMON_QRC_FILENAME}
)
endif()
# Various include directories
# Note #1: access to the Core plugin's source folder is needed so that we can
# build OpenCOR on its own, i.e. without any plugins (due to the global
# CLI/GUI utilities needing access to some features that are in common
# with the Core CLI/GUI utilities)...
# Note #2: we want everybody to be able to access diff-match-patch...
include_directories(
src
src/3rdparty/diff_match_patch/src
src/misc
src/plugins
src/plugins/miscellaneous/Core/src
)
# Update the translation (.ts) files and generate the language (.qm) files
# that will later be embedded in the OpenCOR executable as resources
update_language_files(${CMAKE_PROJECT_NAME} ${SOURCES} ${UIS})
# Third-party library that must be directly embedded in the GUI version of
# OpenCOR
include(${CMAKE_SOURCE_DIR}/src/3rdparty/QtSingleApplication/QtSingleApplication.cmake)
# Set the application icon, but only for Windows and macOS, since in the case of
# Linux, it's done through the use of app_icon (see res/ui.qrc) when we register
# our URL scheme (see MainWindow::registerOpencorUrlScheme())
# Note: on Windows, we set a bit more than just the application icon. We also
# set its product name, version, copyright, etc.
set(PROJECT_DESCRIPTION "A cross-platform modelling environment")
if(SNAPSHOT)
set(FILE_VERSION 0)
set(PRODUCT_VERSION "Snapshot ${VERSION}")
else()
string(REPLACE "." ","
FILE_VERSION "${VERSION}")
set(PRODUCT_VERSION "Version ${VERSION}")
endif()
string(TIMESTAMP YEAR "%Y")
if(WIN32)
set(RC_FILENAME ${PROJECT_BUILD_DIR}/${CMAKE_PROJECT_NAME}.rc)
configure_file(${CMAKE_SOURCE_DIR}/res/${CMAKE_PROJECT_NAME}.rc.in ${RC_FILENAME})
list(APPEND SOURCES ${RC_FILENAME})
elseif(APPLE)
set(ICNS_FILENAME ${CMAKE_PROJECT_NAME}.icns)
set(MACOSX_BUNDLE_ICON_FILE ${ICNS_FILENAME})
set_source_files_properties(res/${ICNS_FILENAME} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
list(APPEND SOURCES res/${ICNS_FILENAME})
endif()
# Check whether tests are required and, if so, 'reset' our list of tests and set
# the destination tests directory and build our main test program
if(ENABLE_TESTS)
# 'Reset' our list of tests
set(TESTS_LIST_FILENAME ${PROJECT_BUILD_DIR}/tests.txt)
file(WRITE ${TESTS_LIST_FILENAME})
track_files(${TESTS_LIST_FILENAME})
# Destination tests directory
# Note: DEST_TESTS_DIR isn't only used here, but also in our add_plugin()
# macro...
if(APPLE)
set(DEST_TESTS_DIR ${PROJECT_BUILD_DIR}/${CMAKE_PROJECT_NAME}.app/Contents/MacOS)
else()
set(DEST_TESTS_DIR ${PROJECT_BUILD_DIR}/bin)
endif()
# Build our main test program
set(RUNTESTS_NAME runtests)
set(TESTS_QRC_FILENAME ${PROJECT_BUILD_DIR}/src/tests/res/tests.qrc)
configure_file(${CMAKE_SOURCE_DIR}/src/tests/res/tests.qrc.in ${TESTS_QRC_FILENAME})
add_executable(${RUNTESTS_NAME}
src/tests/src/main.cpp
src/tests/src/testsutils.cpp
${TESTS_QRC_FILENAME}
)
set_target_properties(${RUNTESTS_NAME} PROPERTIES
OUTPUT_NAME ${RUNTESTS_NAME}
LINK_FLAGS "${LINK_FLAGS_PROPERTIES}"
)
configure_clang_and_clang_tidy(${RUNTESTS_NAME})
target_link_libraries(${RUNTESTS_NAME}
Qt5::Core
Qt5::Network
)
# Copy our main test program to our tests directory
set(MAIN_TEST_FILENAME ${RUNTESTS_NAME}${CMAKE_EXECUTABLE_SUFFIX})
add_custom_command(TARGET ${RUNTESTS_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BUILD_DIR}/${MAIN_TEST_FILENAME}
${DEST_TESTS_DIR}/${MAIN_TEST_FILENAME})
# Clean up our test program, if we are on macOS, our make sure that it uses
# RPATH rather than RUNPATH on Linux
if(APPLE)
strip_file(${RUNTESTS_NAME} ${DEST_TESTS_DIR}/${MAIN_TEST_FILENAME})
elseif(NOT WIN32)
runpath2rpath(${RUNTESTS_NAME} ${DEST_TESTS_DIR}/${MAIN_TEST_FILENAME})
endif()
endif()
# Specify a target to help us build certain plugins (e.g. our Python plugin)
set(PROJECT_BUILD_TARGET ${PROJECT_NAME}Build)
add_custom_target(${PROJECT_BUILD_TARGET} ALL)
# Specify a target to help us take advantage of our documentation (e.g. by the
# Help window plugin)
set(DOCUMENTATION_BUILD_TARGET DocumentationBuild)
add_custom_target(${DOCUMENTATION_BUILD_TARGET} ALL)
# Check whether we have everything to build our documentation
find_package(Python COMPONENTS Interpreter)
find_program(SPHINX_EXECUTABLE NAMES sphinx-build sphinx-build2)
check_python_package(sphinx-copybutton PYTHON_SPHINX_COPY_BUTTON_AVAILABLE)
check_python_package(sphinx-inline-tabs PYTHON_SPHINX_INLINE_TABS_AVAILABLE)
if(SPHINX_EXECUTABLE AND PYTHON_SPHINX_COPY_BUTTON_AVAILABLE AND PYTHON_SPHINX_INLINE_TABS_AVAILABLE)
set(CAN_GENERATE_DOCUMENTATION TRUE)
else()
message(WARNING "No documentation is to be generated...")
endif()
# Build our plugins
# Note #1: hard dependencies (i.e. OpenSSL and zlib) must be listed before any
# other plugins, and zlib before OpenSSL since the latter needs the
# former...
# Note #2: Python third-party plugins must be built in order, after zlib and
# OpenSSL, and before any other plugins...
# Note #3: soft dependencies are determined automatically, so other plugins can
# be listed in any order...
if(USE_PREBUILT_QTWEBKIT_PACKAGE)
# Determine the location of the MSVC runtime libraries
if(WIN32)
if(EXISTS "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community")
set(MSVC_EDITION Community)
else()
set(MSVC_EDITION Enterprise)
endif()
if(RELEASE_MODE)
set(MSVC_DIR "C:/Program Files (x86)/Microsoft Visual Studio/2019/${MSVC_EDITION}/VC/Redist/MSVC/14.29.30133/x64/Microsoft.VC142.CRT")
else()
set(MSVC_DIR "C:/Program Files (x86)/Microsoft Visual Studio/2019/${MSVC_EDITION}/VC/Redist/MSVC/14.29.30133/debug_nonredist/x64/Microsoft.VC142.DebugCRT")
endif()
endif()
# We are using the prebuilt version of our QtWebKit package, so build
# whatever we can depending on whether we are using the prebuilt version of
# our Python package
set(PLUGINS
thirdParty/OpenSSL
thirdParty/zlib
thirdParty/Python
)
if(USE_PREBUILT_PYTHON_PACKAGE)
# We are using the prebuilt version of our Python package, so build all
# our plugins
# Note: on Windows, it's technically very difficult, if not impossible,
# to get a debug version of our PythonConsole window, so we skip
# it in that case (see
# https://github.com/opencor/opencor/issues/1255#issuecomment-550605710)...
if(CAN_GENERATE_DOCUMENTATION)
set(MISCELLANEOUS_HELPWINDOW miscellaneous/HelpWindow)
endif()
if(RELEASE_MODE OR NOT WIN32)
set(MISCELLANEOUS_PYTHONCONSOLEWINDOW miscellaneous/PythonConsoleWindow)
endif()
list(APPEND PLUGINS
thirdParty/libSBML
thirdParty/PythonPackages
thirdParty/PythonQt
dataStore/BioSignalMLDataStore
dataStore/CSVDataStore
dataStore/DataStore
editing/CellMLAnnotationView
editing/CellMLEditingView
editing/CellMLTextView
editing/EditingView
editing/RawCellMLView
editing/RawSEDMLView
editing/RawTextView
editing/SEDMLEditingView
miscellaneous/Compiler
miscellaneous/Core
${MISCELLANEOUS_HELPWINDOW}
miscellaneous/JupyterKernel
${MISCELLANEOUS_PYTHONCONSOLEWINDOW}
miscellaneous/PythonShell
miscellaneous/WebBrowserWindow
organisation/FileBrowserWindow
organisation/FileOrganiserWindow
organisation/PMRWindow
organisation/PMRWorkspacesWindow
simulation/SimulationExperimentView
solver/CVODESolver