forked from SixTrack/SixTrack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
1636 lines (1385 loc) · 56.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
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
#
# SixTrack CMake Build File
# ===========================
# Making use of https://cmake.org/Wiki/CMakeForFortranExample
# and the file created for building Merlin.
#
###################################################################################################
# General configuration
###################################################################################################
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
# Force an out of source build to stop clutter
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(STATUS "SixTrack requires an out-of-source build.")
message(STATUS "Please remove these files from ${CMAKE_BINARY_DIR} first:")
message(STATUS " CMakeCache.txt")
message(STATUS " CMakeFiles")
message(STATUS "Once these files are removed, create a separate directory and run CMake from there")
message(FATAL_ERROR "In-source build detected")
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel" FORCE)
endif()
if(NOT CMAKE_GENERATOR)
set(CMAKE_GENERATOR "Unix Makefiles")
endif()
# Extract SixTrack version info
file(READ ${CMAKE_SOURCE_DIR}/source/version.f90 IFILE)
string(REGEX MATCH ".*version = \"([0-9.]+)\"" VERSION_TMP ${IFILE})
set(STRING_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH ".*numvers = ([0-9]+)" VERSION_TMP ${IFILE})
set(NUM_VERSION "${CMAKE_MATCH_1}")
# Set the project
project(SixTrack VERSION ${STRING_VERSION})
enable_language(Fortran)
# Get the current git commit hash
find_package(Git)
if(GIT_FOUND)
execute_process(COMMAND git log -n1 --pretty=format:%H WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE GIT_REVISION)
string(STRIP ${GIT_REVISION} GIT_REVISION)
string(SUBSTRING ${GIT_REVISION} 0 7 GIT_BUILD)
set(GIT_BUILD "-${GIT_BUILD}")
else()
set(GIT_REVISION "Unknown")
set(GIT_BUILD "")
endif()
# Print some build info
message(STATUS "SixTrack Version: ${${PROJECT_NAME}_VERSION}")
message(STATUS "Version Major: ${${PROJECT_NAME}_VERSION_MAJOR}")
message(STATUS "Version Minor: ${${PROJECT_NAME}_VERSION_MINOR}")
message(STATUS "Version Patch: ${${PROJECT_NAME}_VERSION_PATCH}")
message(STATUS "Numeric Version: ${NUM_VERSION}")
message(STATUS "Git Revision: ${GIT_REVISION}")
message(STATUS "System Name: ${CMAKE_SYSTEM_NAME}")
message(STATUS "System Processor: ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "CMake Generator: ${CMAKE_GENERATOR}")
message(STATUS "CMake Source: ${CMAKE_SOURCE_DIR}")
message(STATUS "CMake Binary: ${CMAKE_BINARY_DIR}")
message(STATUS "Project Source: ${PROJECT_SOURCE_DIR}")
message(STATUS "Project Binary: ${PROJECT_BINARY_DIR}")
###################################################################################################
# SixTrack configuration options
###################################################################################################
# Default ON
option(CRLIBM "Use correctly rounded libmath instead of system libmath" ON)
option(SIXDA "Build differential algebra version (NOT dynamic aperture!)" ON)
option(NAFF "Link to external NAFFlib for FMA" ON)
option(DISTLIB "Link to external DISTlib for the beam distribution" ON)
option(HASHLIB "Build the md5 hash library" ON)
option(ZLIB "Build and link zlib. Needed for BOINC and ZIPF block" ON)
# Default OFF
option(CERNLIB "Link to external CERNLIB library for PAW plots. Otherwise use internally defined dummy functions from deck plotdumy" OFF)
option(BOINC "BOINC distributed computing support" OFF)
option(CR "Checkpoint/restarting" OFF)
option(BEAMGAS "Beam-gas scattering" OFF)
option(HDF5 "Adds support for the HDF5 block which enables writing output to a single HDF5 file." OFF)
option(FIO "Use FortranIO from Fortran2003 to correctly round ASCII input/output" OFF)
option(MERLINSCATTER "Interaction physics for collimation from Merlin" OFF)
option(G4COLLIMATION "Interaction physics for collimation from Geant4" OFF)
option(FLUKA "Couple to FLUKA for beam collimation" OFF)
option(PYTHIA "Link with Pythia8 for SCATTER module" OFF)
option(ROOT "Link to the root libraries" OFF)
# Build Options
option(32BIT "Create a 32bit binary" OFF)
option(64BIT "Create a 64bit binary" ON)
option(STATIC "Create a statically linked binary" ON)
option(NATIVE "Enable optimisations for the current machine" OFF)
option(AVX "Enable use of the Advanced Vector Extensions (AVX) instruction set - Sandy Bridge and later" OFF)
option(AVX2 "Enable use of the Advanced Vector Extensions 2 (AVX2) instruction set - Haswell and later" OFF)
option(AVX512 "Enable use of the Advanced Vector Extensions 512 (AVX512) instruction set" OFF)
option(AVX512_SKYLAKE "Enable use of the Advanced Vector Extensions 512 (AVX512) instruction set targeting Skylake" OFF)
option(LTO "Enable link time optimisations" OFF)
OPTION(PREFETCH "Enables the -fprefetch-loop-arrays compiler flag for gcc" OFF)
# Float Precision (Default: 64BITM)
option(32BITM "Floats are 32bit (single precision)" OFF)
option(64BITM "Floats are 64bit (double precision)" ON)
option(128BITM "Floats are 128bit (quad precision)" OFF)
# Rounding (Default: ROUND_NEAR)
option(ROUND_NEAR "Always round to the nearest number after floating point operations" ON)
option(ROUND_UP "Always round up after floating point operations" OFF)
option(ROUND_DOWN "Always round down after floating point operations" OFF)
option(ROUND_ZERO "Always round towards zero after floating point operations" OFF)
# Testing and Debug Options
option(BUILD_TESTING "Enable the test suite" OFF)
option(COVERAGE "Enable build flags for testing code coverage with gcov (only works with GNU compilers)" OFF)
option(GPROF "Enable build flags for code profiling with gprof (only works with GNU compilers)" OFF)
option(WARN "Enable build flags for additional compiler warnings" OFF)
option(INITNAN "Enable build flags for initialising reals to signaling NaN" OFF)
option(DEBUG "Debugging output" OFF)
option(NOSYMLINK "Don't use symlinks for test inputs and canonicals" OFF)
option(MEMUSAGE "Writes PID and actual memory usage to sim_meta.dat (GNU/UNIX only)" OFF)
set(BOINC_DIR ${CMAKE_SOURCE_DIR}/lib/boinc CACHE PATH "Path to the boinc build folder")
set(PYTHIA_DIR ${CMAKE_SOURCE_DIR}/lib/pythia CACHE PATH "Path to the Pythia build folder")
###################################################################################################
# Sixtrack binary name construction
###################################################################################################
# FFLAGS depend on the compiler
get_filename_component(Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME)
# Remove .exe from compiler name on Windows
string(REPLACE ".exe" "" Fortran_COMPILER_NAME ${Fortran_COMPILER_NAME})
set(SIXTRACK_FEAT_CR "${CMAKE_SYSTEM_NAME}_${Fortran_COMPILER_NAME}")
set(SIXTRACK_FEAT_DA "${CMAKE_SYSTEM_NAME}_${Fortran_COMPILER_NAME}")
if(CRLIBM AND ROUND_NEAR)
set(SIXTRACK_FEAT_CR "crlibm_rn_${SIXTRACK_FEAT_CR}")
set(SIXTRACK_FEAT_DA "crlibm_rn_${SIXTRACK_FEAT_DA}")
endif(CRLIBM AND ROUND_NEAR)
if(CRLIBM AND ROUND_UP)
set(SIXTRACK_FEAT_CR "crlibm_ru_${SIXTRACK_FEAT_CR}")
set(SIXTRACK_FEAT_DA "crlibm_ru_${SIXTRACK_FEAT_DA}")
endif(CRLIBM AND ROUND_UP)
if(CRLIBM AND ROUND_DOWN)
set(SIXTRACK_FEAT_CR "crlibm_rd_${SIXTRACK_FEAT_CR}")
set(SIXTRACK_FEAT_DA "crlibm_rd_${SIXTRACK_FEAT_DA}")
endif(CRLIBM AND ROUND_DOWN)
if(CRLIBM AND ROUND_ZERO)
set(SIXTRACK_FEAT_CR "crlibm_rz_${SIXTRACK_FEAT_CR}")
set(SIXTRACK_FEAT_DA "crlibm_rz_${SIXTRACK_FEAT_DA}")
endif(CRLIBM AND ROUND_ZERO)
if(CERNLIB)
set(SIXTRACK_FEAT_CR "cernlib_${SIXTRACK_FEAT_CR}")
endif()
if(BOINC)
set(SIXTRACK_FEAT_CR "boinc_${SIXTRACK_FEAT_CR}")
endif()
if(CR)
set(SIXTRACK_FEAT_CR "cr_${SIXTRACK_FEAT_CR}")
endif()
if(BEAMGAS)
set(SIXTRACK_FEAT_CR "beamgas_${SIXTRACK_FEAT_CR}")
endif()
if(DEBUG)
set(SIXTRACK_FEAT_CR "debug_${SIXTRACK_FEAT_CR}")
set(SIXTRACK_FEAT_DA "debug_${SIXTRACK_FEAT_DA}")
endif()
if(HDF5)
set(SIXTRACK_FEAT_CR "hdf5_${SIXTRACK_FEAT_CR}")
endif()
if(FIO)
set(SIXTRACK_FEAT_CR "fio_${SIXTRACK_FEAT_CR}")
set(SIXTRACK_FEAT_DA "fio_${SIXTRACK_FEAT_DA}")
endif()
if(MERLINSCATTER)
set(SIXTRACK_FEAT_CR "merlinscatter_${SIXTRACK_FEAT_CR}")
endif()
if(G4COLLIMATION)
set(SIXTRACK_FEAT_CR "g4collimation_${SIXTRACK_FEAT_CR}")
endif(G4COLLIMATION)
if(FLUKA)
set(SIXTRACK_FEAT_CR "FLUKA_${SIXTRACK_FEAT_CR}")
endif(FLUKA)
if(PYTHIA)
set(SIXTRACK_FEAT_CR "pythia_${SIXTRACK_FEAT_CR}")
endif()
if(ZLIB)
set(SIXTRACK_FEAT_CR "zlib_${SIXTRACK_FEAT_CR}")
endif()
if(ROOT)
set(SIXTRACK_FEAT_CR "root_${SIXTRACK_FEAT_CR}")
endif(ROOT)
if(STATIC)
set(SIXTRACK_FEAT_CR "${SIXTRACK_FEAT_CR}_static")
set(SIXTRACK_FEAT_DA "${SIXTRACK_FEAT_DA}_static")
endif()
if(AVX)
set(SIXTRACK_FEAT_CR "${SIXTRACK_FEAT_CR}_avx")
set(SIXTRACK_FEAT_DA "${SIXTRACK_FEAT_DA}_avx")
endif(AVX)
if(AVX2)
set(SIXTRACK_FEAT_CR "${SIXTRACK_FEAT_CR}_avx2")
set(SIXTRACK_FEAT_DA "${SIXTRACK_FEAT_DA}_avx2")
endif(AVX2)
if(AVX512)
set(SIXTRACK_FEAT_CR "${SIXTRACK_FEAT_CR}_avx512")
set(SIXTRACK_FEAT_DA "${SIXTRACK_FEAT_DA}_avx512")
endif(AVX512)
if(AVX512_SKYLAKE)
set(SIXTRACK_FEAT_CR "${SIXTRACK_FEAT_CR}_avx512skylake")
set(SIXTRACK_FEAT_DA "${SIXTRACK_FEAT_DA}_avx512skylake")
endif(AVX512_SKYLAKE)
if(NATIVE)
set(SIXTRACK_FEAT_CR "${SIXTRACK_FEAT_CR}_native")
set(SIXTRACK_FEAT_DA "${SIXTRACK_FEAT_DA}_native")
endif()
set(SIXTRACK_FEAT_CR "${SIXTRACK_FEAT_CR}_${CMAKE_SYSTEM_PROCESSOR}")
set(SIXTRACK_FEAT_DA "${SIXTRACK_FEAT_DA}_${CMAKE_SYSTEM_PROCESSOR}")
if(32BIT)
set(SIXTRACK_FEAT_CR "${SIXTRACK_FEAT_CR}_32bit")
set(SIXTRACK_FEAT_DA "${SIXTRACK_FEAT_DA}_32bit")
endif()
if(64BIT)
set(SIXTRACK_FEAT_CR "${SIXTRACK_FEAT_CR}_64bit")
set(SIXTRACK_FEAT_DA "${SIXTRACK_FEAT_DA}_64bit")
endif()
if(32BITM)
set(SIXTRACK_FEAT_CR "${SIXTRACK_FEAT_CR}_single")
set(SIXTRACK_FEAT_DA "${SIXTRACK_FEAT_DA}_single")
endif()
if(64BITM)
set(SIXTRACK_FEAT_CR "${SIXTRACK_FEAT_CR}_double")
set(SIXTRACK_FEAT_DA "${SIXTRACK_FEAT_DA}_double")
endif()
if(128BITM)
set(SIXTRACK_FEAT_CR "${SIXTRACK_FEAT_CR}_quad")
set(SIXTRACK_FEAT_DA "${SIXTRACK_FEAT_DA}_quad")
endif()
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set(SIXTRACK_FEAT_CR "${SIXTRACK_FEAT_CR}_DEBUG")
set(SIXTRACK_FEAT_DA "${SIXTRACK_FEAT_DA}_DEBUG")
endif()
# Create the sixtrack binary name string
set(SIXTRACK_BINARY_NAME "${PROJECT_NAME}_${NUM_VERSION}${GIT_BUILD}_${SIXTRACK_FEAT_CR}")
set(SIXTRACK_BINARY_NAME_DA "SixDA_${NUM_VERSION}${GIT_BUILD}_${SIXTRACK_FEAT_DA}")
###################################################################################################
# Setting the c pre-processor definitons
###################################################################################################
list(APPEND PREPRO_FLAGS_TOOLS BOINC BEAMGAS MERLINSCATTER G4COLLIMATION FLUKA CR PYTHIA NAFF)
list(APPEND PREPRO_FLAGS_LIB CRLIBM ROUND_NEAR ROUND_UP ROUND_DOWN ROUND_ZERO CERNLIB HDF5 FIO ROOT HASHLIB ZLIB DISTLIB)
list(APPEND PREPRO_FLAGS_COMPILE GFORTRAN IFORT NAGFOR WIN32 DEBUG MEMUSAGE)
###################################################################################################
# Select which fortran files to generate and compile
###################################################################################################
list(APPEND FORT90_LIB
aperture
bdex
beam6d
beam6d_fox
bouncy_castle
cheby
close
coll_common
coll_crystal
coll_db
coll_dist
coll_jawfit
coll_k2
collimation
common_modules
constants
core_tools
dabnew
dump
dynk
elements
elens
end_sixtrack
fma
lielib
linear_optics
mainarrays
matrix_inv
mod_alloc
mod_dist
mod_ffield
mod_ffield_aux
mod_find
mod_fluc
mod_funlux
mod_geometry
mod_meta
mod_particles
mod_random
mod_ranecu
mod_ranlux
mod_time
mod_units
mod_utils
pdgid
plato_seq
postprocessing
read_write
scatter
six_fox
sixtrack
sixtrack_input
string_tools
strings
version
wire
zipf
)
# Files unique to DA or CR version
list(APPEND FORT90_DA main_da sixda)
list(APPEND FORT90_CR main_cr sixve tracking track_thin track_thick)
# List of files that must be treated by DAFOR
list(APPEND DAFOR_F90 beam6d_fox cheby elens six_fox sixda)
if(CR)
list(APPEND FORT90_LIB checkpoint_restart)
endif(CR)
if(HDF5)
list(APPEND FORT90_LIB hdf5_output hdf5_sixtrack)
endif(HDF5)
if(HASHLIB)
list(APPEND FORT90_LIB mod_hash)
endif(HASHLIB)
if(BEAMGAS)
list(APPEND FORT90_CR beamgas)
endif(BEAMGAS)
if(FLUKA)
list(APPEND FORT90_LIB mod_fluka)
endif(FLUKA)
if(ROOT)
list(APPEND FORT90_LIB root_output)
endif(ROOT)
if(G4COLLIMATION)
list(APPEND FORT90_LIB geant4)
endif(G4COLLIMATION)
if(BOINC)
list(APPEND FORT90_LIB mod_boinc)
endif(BOINC)
if(PYTHIA)
add_library(pythia_wrapper STATIC pythia_wrapper.h pythia_wrapper.cpp)
target_compile_options(pythia_wrapper PRIVATE)
list(APPEND FORT90_LIB mod_pythia)
endif(PYTHIA)
foreach(loop IN LISTS FORT90_LIB)
list(APPEND SIXTRACK_SOURCES ${loop}.f90)
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${loop}.f90)
endforeach()
foreach(loop IN LISTS FORT90_CR)
list(APPEND SIXTRACK_SOURCES_CR ${loop}.f90)
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${loop}.f90)
endforeach()
foreach(loop IN LISTS FORT90_DA)
list(APPEND SIXTRACK_SOURCES_DA ${loop}.f90)
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${loop}.f90)
endforeach()
foreach(loop IN LISTS DAFOR_F90)
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${loop}a.f90)
endforeach()
if(ZLIB)
set(ZLIB_DIR ${CMAKE_SOURCE_DIR}/lib/zlib)
include_directories(${ZLIB_DIR} ${CMAKE_CURRENT_BINARY_DIR}/zlib)
add_subdirectory(${ZLIB_DIR} ${CMAKE_CURRENT_BINARY_DIR}/zlib)
endif(ZLIB)
###################################################################################################
# Checking if some requested packages exist
###################################################################################################
##Possible check for Root
if(ROOT)
set(CMAKE_MODULE_PATH /usr/share/root/cmake/ ${CMAKE_MODULE_PATH})
if(STATIC)
find_package(ROOT REQUIRED static)
else()
find_package(ROOT REQUIRED)
endif(STATIC)
if(NOT ROOT_FOUND)
message(FATAL_ERROR "Root enabled build requested but root was not found!")
endif(NOT ROOT_FOUND)
message(STATUS "ROOT include folders: ${ROOT_INCLUDE_DIRS}")
message(STATUS "ROOT definitions:${ROOT_DEFINITIONS}")
message(STATUS "ROOT CXX flags: ${ROOT_CXX_FLAGS}")
add_subdirectory(${CMAKE_SOURCE_DIR}/source/root_output)
endif(ROOT)
if(G4COLLIMATION)
if(STATIC)
find_package(Geant4 REQUIRED static)
else()
find_package(Geant4 REQUIRED)
endif(STATIC)
#no error checking yet
message(STATUS "Geant4 include folders: ${Geant4_INCLUDE_DIRS}")
message(STATUS "Geant4 use file: ${Geant4_USE_FILE}")
message(STATUS "Geant4 libraries: ${Geant4_LIBRARIES}")
message(STATUS "Geant4 definitions: ${Geant4_DEFINITIONS}")
message(STATUS "Geant4 CXX flags: ${Geant4_CXX_FLAGS}")
add_subdirectory(${CMAKE_SOURCE_DIR}/source/g4collimation)
endif(G4COLLIMATION)
if(BUILD_TESTING OR BOINC OR G4COLLIMATION OR CERNLIB)
find_package(Threads REQUIRED)
if(NOT Threads_FOUND)
message(FATAL_ERROR "Could not find a thread library! This is required for your selected build configuration.")
endif(NOT Threads_FOUND)
endif(BUILD_TESTING OR BOINC OR G4COLLIMATION OR CERNLIB)
###################################################################################################
# Checking if requested options are compatible
###################################################################################################
# Check we do not have both 32 and 64 bit options enabled
if(32BIT)
if(64BIT)
message(FATAL_ERROR "Cannot build with both 64 and 32 bit options enabled. Please pick one only.")
endif()
endif()
# Check we have at least one 32 or 64 bit option enabled
if(NOT 32BIT)
if(NOT 64BIT)
message(FATAL_ERROR "Must pick either a 64 or 32 bit build. Currently neither are selected.")
endif()
endif()
if(HDF5)
if(CR)
message(FATAL_ERROR "Cannot build HDF5 with CR enabled.")
endif()
if(NOT ZLIB)
message(FATAL_ERROR "Building with HDF5 requires ZLIB enabled.")
endif()
endif()
if(SIXDA)
if(CR)
message(STATUS "Will not build SixDA when checkpoint/restart is enabled.")
set(SIXDA OFF)
endif()
endif()
if(BOINC)
if(NOT CRLIBM)
message(FATAL_ERROR "Building with BOINC requires CRLIBM enabled.")
endif(NOT CRLIBM)
if(NOT CR)
message(FATAL_ERROR "Building with BOINC requires CR enabled.")
endif()
if(NOT ZLIB)
message(FATAL_ERROR "Building with BOINC requires ZLIB enabled.")
endif()
if(NOT HASHLIB)
message(FATAL_ERROR "Building with BOINC requires HASHLIB enabled.")
endif()
endif(BOINC)
if(FLUKA)
if(SIXDA)
message(STATUS "Will not build SixDA when FLUKA is enabled.")
set(SIXDA OFF)
endif()
endif()
if(G4COLLIMATION)
if(SIXDA)
message(STATUS "Will not build SixDA when G4COLLIMATION is enabled.")
set(SIXDA OFF)
endif()
endif()
if(MERLINSCATTER)
if(SIXDA)
message(STATUS "Will not build SixDA when MERLINSCATTER is enabled.")
set(SIXDA OFF)
endif()
endif()
if(BEAMGAS)
if(SIXDA)
message(STATUS "Will not build SixDA when BEAMGAS is enabled.")
set(SIXDA OFF)
endif()
endif()
if(32BITM)
if(64BITM)
message(FATAL_ERROR "Cannot use both single and double precision math.")
endif(64BITM)
if(128BITM)
message(FATAL_ERROR "Cannot use both single and quad precision math.")
endif(128BITM)
if(FLUKA)
message(FATAL_ERROR "Cannot use FLUKA with single precision math.")
endif(FLUKA)
if(CRLIBM)
message(FATAL_ERROR "Cannot use CRLIBM with single precision math.")
endif(CRLIBM)
if(DISTLIB)
message(FATAL_ERROR "Cannot use DISTLIB with single precision math.")
endif(DISTLIB)
endif(32BITM)
if(64BITM)
if(32BITM)
message(FATAL_ERROR "Cannot use both double and single precision math.")
endif(32BITM)
if(128BITM)
message(FATAL_ERROR "Cannot use both double and quad precision math.")
endif(128BITM)
endif(64BITM)
if(128BITM)
if(32BITM)
message(FATAL_ERROR "Cannot use both quad and single precision math.")
endif(32BITM)
if(64BITM)
message(FATAL_ERROR "Cannot use both quad and double precision math.")
endif(64BITM)
if(FLUKA)
message(FATAL_ERROR "Cannot use FLUKA with quad precision math.")
endif(FLUKA)
if(CRLIBM)
message(FATAL_ERROR "Cannot use CRLIBM with quad precision math.")
endif(CRLIBM)
if(DISTLIB)
message(FATAL_ERROR "Cannot use DISTLIB with quad precision math.")
endif(DISTLIB)
endif(128BITM)
if(NOT SIXDA)
message(STATUS "Not building SixDA version.")
endif(NOT SIXDA)
# Since each AVX option includes the lower ones, just turn the lower flags off to avoid duplication
if(AVX512_SKYLAKE)
set(AVX OFF)
set(AVX2 OFF)
set(AVX512 OFF)
endif(AVX512_SKYLAKE)
if(AVX512)
set(AVX OFF)
set(AVX2 OFF)
endif(AVX512)
if(AVX2)
set(AVX OFF)
endif(AVX2)
###################################################################################################
# Settings for compiler build flags
###################################################################################################
if(STATIC)
# This just sets the default build setting for shared libraries.
set(BUILD_SHARED_LIBS OFF)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(MIN_OSX_VERSION 10.10.5)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# FLAGS depend on the compiler
get_filename_component (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME)
if(Fortran_COMPILER_NAME MATCHES "gfortran.*")
##############
# gfortran #
##############
set(GFORTRAN ON)
set(CMAKE_Fortran_FLAGS "-frecord-marker=4 -fno-second-underscore -funroll-loops -std=f2008")
set(PREPRO_EXEC ${CMAKE_Fortran_COMPILER})
set(PREPRO_FLAGS -cpp -E -P)
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES aarch64 )
set (CMAKE_Fortran_FLAGS "-ffp-contract=off ${CMAKE_Fortran_FLAGS}")
endif()
set(CMAKE_Fortran_FLAGS_RELEASE "-O3")
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -g3 -fcheck=all")
if(WARN)
set(CMAKE_Fortran_FLAGS_RELEASE "-Wuninitialized ${CMAKE_Fortran_FLAGS_RELEASE}")
set(CMAKE_Fortran_FLAGS_DEBUG "-Wuninitialized -ffpe-trap=invalid,zero,overflow,underflow ${CMAKE_Fortran_FLAGS_DEBUG}")
else()
set(CMAKE_Fortran_FLAGS_DEBUG "-ffpe-trap=invalid,zero,overflow ${CMAKE_Fortran_FLAGS_DEBUG}")
endif()
if(INITNAN)
set(CMAKE_Fortran_FLAGS_RELEASE "-finit-real=snan -finit-character=0 ${CMAKE_Fortran_FLAGS_RELEASE}")
set(CMAKE_Fortran_FLAGS_DEBUG "-finit-real=snan -finit-character=0 ${CMAKE_Fortran_FLAGS_DEBUG}")
endif()
if(MEMUSAGE)
set(CMAKE_Fortran_FLAGS_RELEASE "-fall-intrinsics ${CMAKE_Fortran_FLAGS_RELEASE}")
set(CMAKE_Fortran_FLAGS_DEBUG "-fall-intrinsics ${CMAKE_Fortran_FLAGS_DEBUG}")
endif()
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES ppc64le )
set(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} -fno-expensive-optimizations -fno-inline-functions")
endif()
if(LTO)
set(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} -flto -Wl,-flto")
endif(LTO)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND BOINC)
set(CMAKE_Fortran_FLAGS "-mmacosx-version-min=${MIN_OSX_VERSION} ${CMAKE_Fortran_FLAGS}")
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND BOINC)
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES AMD64 OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES x86_64 OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES i686)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -mfpmath=sse -msse2")
if(32BIT)
set(CMAKE_Fortran_FLAGS "-m32 ${CMAKE_Fortran_FLAGS}")
endif(32BIT)
if(64BIT)
set(CMAKE_Fortran_FLAGS "-m64 ${CMAKE_Fortran_FLAGS}")
endif(64BIT)
if(AVX)
set(CMAKE_Fortran_FLAGS "-mavx ${CMAKE_Fortran_FLAGS}")
endif(AVX)
if(AVX2)
set(CMAKE_Fortran_FLAGS "-mavx -mavx2 -mno-fma4 -mno-fma ${CMAKE_Fortran_FLAGS}")
endif(AVX2)
if(AVX512)
set(CMAKE_Fortran_FLAGS "-mavx -mavx2 -mavx512f -mno-fma4 -mno-fma ${CMAKE_Fortran_FLAGS}")
endif(AVX512)
if(AVX512_SKYLAKE)
set(CMAKE_Fortran_FLAGS "-mavx -mavx2 -mavx512f -mavx512cd -mavx512bw -mavx512vl -mno-fma4 -mno-fma ${CMAKE_Fortran_FLAGS}")
endif(AVX512_SKYLAKE)
if(NATIVE)
set(CMAKE_Fortran_FLAGS "-march=native -mno-fma4 -mno-fma ${CMAKE_Fortran_FLAGS}")
endif(NATIVE)
if(PREFETCH)
set(CMAKE_Fortran_FLAGS "-fprefetch-loop-arrays ${CMAKE_Fortran_FLAGS}")
endif(PREFETCH)
endif()
if(STATIC)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_Fortran_LINKER_FLAGS "-Bstatic -static-libgcc -static-libgfortran ${CMAKE_Fortran_LINKER_FLAGS}")
else()
set(CMAKE_Fortran_LINKER_FLAGS "-static ${CMAKE_Fortran_LINKER_FLAGS}")
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
endif(STATIC)
if(COVERAGE)
set(CMAKE_Fortran_FLAGS "-fprofile-arcs -ftest-coverage ${CMAKE_Fortran_FLAGS}")
set(CMAKE_Fortran_LINKER_FLAGS "-fprofile-arcs ${CMAKE_Fortran_LINKER_FLAGS}")
endif(COVERAGE)
if(GPROF)
set(CMAKE_Fortran_FLAGS "-pg ${CMAKE_Fortran_FLAGS}")
set(CMAKE_Fortran_LINKER_FLAGS "-pg ${CMAKE_Fortran_LINKER_FLAGS}")
endif(GPROF)
elseif(Fortran_COMPILER_NAME MATCHES "ifort.*")
###########
# ifort #
###########
set(IFORT ON)
set(CMAKE_Fortran_FLAGS_RELEASE "-fp-model source -fp-model strict -fp-model no-except -O3 -no-fma -std15 -assume realloc-lhs")
set(CMAKE_Fortran_FLAGS_DEBUG "-fp-model source -fp-model strict -fp-model no-except -O0 -g -traceback -no-fma -std15 -assume realloc-lhs")
set(PREPRO_EXEC ${CMAKE_Fortran_COMPILER})
set(PREPRO_FLAGS -I${CMAKE_SOURCE_DIR}/source/include -fpp -E -P)
if(LTO)
set(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} -ffat-lto-objects -ipo")
endif(LTO)
if(WARN)
set(CMAKE_Fortran_FLAGS "-warn unused -check bounds ${CMAKE_Fortran_FLAGS}")
endif(WARN)
if(INITNAN)
set(CMAKE_Fortran_FLAGS_RELEASE "-init=snan,arrays ${CMAKE_Fortran_FLAGS_RELEASE}")
set(CMAKE_Fortran_FLAGS_DEBUG "-init=snan,arrays ${CMAKE_Fortran_FLAGS_DEBUG}")
endif()
if(32BIT)
set(CMAKE_Fortran_FLAGS_RELEASE "-m32 ${CMAKE_Fortran_FLAGS_RELEASE}")
set(CMAKE_Fortran_FLAGS_DEBUG "-m32 ${CMAKE_Fortran_FLAGS_DEBUG}")
set(CMAKE_Fortran_LINKER_FLAGS "-m32 ${CMAKE_Fortran_LINKER_FLAGS}")
endif(32BIT)
if(64BIT)
set(CMAKE_Fortran_FLAGS_RELEASE "-m64 ${CMAKE_Fortran_FLAGS_RELEASE}")
set(CMAKE_Fortran_FLAGS_DEBUG "-m64 ${CMAKE_Fortran_FLAGS_DEBUG}")
set(CMAKE_Fortran_LINKER_FLAGS "-m64 ${CMAKE_Fortran_LINKER_FLAGS}")
endif(64BIT)
if(AVX)
set(CMAKE_Fortran_FLAGS "-mavx ${CMAKE_Fortran_FLAGS}")
endif(AVX)
if(AVX2)
set(CMAKE_Fortran_FLAGS "-mavx -mavx2 -no-fma ${CMAKE_Fortran_FLAGS}")
endif(AVX2)
if(AVX512)
set(CMAKE_Fortran_FLAGS "-axcommon-avx512 -no-fma ${CMAKE_Fortran_FLAGS}")
endif(AVX512)
if(AVX512_SKYLAKE)
set(CMAKE_Fortran_FLAGS "-axskylake-avx512 -no-fma ${CMAKE_Fortran_FLAGS}")
endif(AVX512_SKYLAKE)
if(NATIVE)
set(CMAKE_Fortran_FLAGS_RELEASE "-xHost ${CMAKE_Fortran_FLAGS_RELEASE}")
endif(NATIVE)
if(STATIC)
set(CMAKE_Fortran_LINKER_FLAGS "-static ${CMAKE_Fortran_LINKER_FLAGS}")
endif(STATIC)
elseif(Fortran_COMPILER_NAME MATCHES "nagfor.*")
############
# nagfor #
############
set(NAGFOR ON)
set(CMAKE_Fortran_FLAGS_RELEASE "-O4 -dusty -ieee=full -dcfuns")
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -dusty -ieee=full -dcfuns -gline")
set(PREPRO_EXEC ${CMAKE_CXX_COMPILER})
set(PREPRO_FLAGS -cpp -E -P)
if(WARN)
set(CMAKE_Fortran_FLAGS "-w=ulv -w=uparam ${CMAKE_Fortran_FLAGS}")
else()
set(CMAKE_Fortran_FLAGS "-w=all ${CMAKE_Fortran_FLAGS}")
endif(WARN)
if(INITNAN)
set(CMAKE_Fortran_FLAGS_RELEASE "-nan ${CMAKE_Fortran_FLAGS_RELEASE}")
set(CMAKE_Fortran_FLAGS_DEBUG "-nan ${CMAKE_Fortran_FLAGS_DEBUG}")
endif()
if(32BIT)
set(CMAKE_Fortran_FLAGS_RELEASE "-abi=32 ${CMAKE_Fortran_FLAGS_RELEASE}")
set(CMAKE_Fortran_FLAGS_DEBUG "-abi=32 ${CMAKE_Fortran_FLAGS_DEBUG}")
endif(32BIT)
if(64BIT)
#See the nagfor man page for the different 64bit -abi options.
set(CMAKE_Fortran_FLAGS_RELEASE "-abi=64t ${CMAKE_Fortran_FLAGS_RELEASE}")
set(CMAKE_Fortran_FLAGS_DEBUG "-abi=64t ${CMAKE_Fortran_FLAGS_DEBUG}")
endif(64BIT)
if(NATIVE)
SET(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}")
endif(NATIVE)
if(STATIC)
set(CMAKE_Fortran_LINKER_FLAGS "-Bstatic ${CMAKE_Fortran_LINKER_FLAGS}")
endif(STATIC)
if(NOT STATIC)
set(CMAKE_Fortran_LINKER_FLAGS "-Bdynamic ${CMAKE_Fortran_LINKER_FLAGS}")
endif(NOT STATIC)
else()
# Generic catch option
message(STATUS "CMAKE_Fortran_COMPILER full path: " ${CMAKE_Fortran_COMPILER})
message(STATUS "Fortran compiler: " ${Fortran_COMPILER_NAME})
message(STATUS "No optimized Fortran compiler flags are known, we just try -O2 or -O0 -g...")
set(CMAKE_Fortran_FLAGS_RELEASE "-O2 ${CMAKE_Fortran_FLAGS_RELEASE}")
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -g ${CMAKE_Fortran_FLAGS_DEBUG}")
set(PREPRO_EXEC ${CMAKE_Fortran_COMPILER})
set(PREPRO_FLAGS -cpp -E -P)
endif()
# C Flags
if(${CMAKE_C_COMPILER_ID} MATCHES "GNU")
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES aarch64 )
set (CMAKE_C_FLAGS "-ffp-contract=off ${CMAKE_C_FLAGS}")
endif()
set (CMAKE_C_FLAGS_RELEASE "-O3")
set (CMAKE_C_FLAGS_DEBUG "-O0 -g3")
if(LTO)
set(CMAKE_Fortran_C_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto -Wl,-flto")
endif(LTO)
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES AMD64 OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES x86_64 OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES i686)
if(32BIT)
set(CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}")
endif(32BIT)
if(64BIT)
set(CMAKE_C_FLAGS "-m64 ${CMAKE_C_FLAGS}")
endif(64BIT)
if(AVX)
set(CMAKE_C_FLAGS "-mavx ${CMAKE_C_FLAGS}")
endif(AVX)
if(AVX2)
set(CMAKE_C_FLAGS "-mavx -mavx2 -mno-fma4 -mno-fma ${CMAKE_C_FLAGS}")
endif(AVX2)
if(AVX512)
set(CMAKE_C_FLAGS "-mavx -mavx2 -mavx512f -mno-fma4 -mno-fma ${CMAKE_C_FLAGS}")
endif(AVX512)
if(AVX512_SKYLAKE)
set(CMAKE_C_FLAGS "-mavx -mavx2 -mavx512f -mavx512cd -mavx512bw -mavx512vl -mno-fma4 -mno-fma ${CMAKE_C_FLAGS}")
endif(AVX512_SKYLAKE)
if(NATIVE)
set(CMAKE_C_FLAGS "-march=native ${CMAKE_C_FLAGS}")
endif(NATIVE)
if(PREFETCH)
set(CMAKE_C_FLAGS "-fprefetch-loop-arrays ${CMAKE_C_FLAGS}")
endif(PREFETCH)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND BOINC)
set(CMAKE_C_FLAGS "-mmacosx-version-min=${MIN_OSX_VERSION} ${CMAKE_C_FLAGS}")
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND BOINC)
if(STATIC)
set(CMAKE_C_LINKER_FLAGS "-static ${CMAKE_C_LINKER_FLAGS}")
endif(STATIC)
if(COVERAGE)
set(CMAKE_C_FLAGS "-fprofile-arcs -ftest-coverage ${CMAKE_C_FLAGS}")
set(CMAKE_C_LINKER_FLAGS "-fprofile-arcs ${CMAKE_C_LINKER_FLAGS}")
endif(COVERAGE)
if(GPROF)
set(CMAKE_C_FLAGS "-pg ${CMAKE_C_FLAGS}")
set(CMAKE_C_LINKER_FLAGS "-pg ${CMAKE_C_LINKER_FLAGS}")
endif(GPROF)
endif()
if(${CMAKE_C_COMPILER_ID} MATCHES "Intel")
if(32BIT)
set(CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}")
endif(32BIT)
if(64BIT)
set(CMAKE_C_FLAGS "-m64 ${CMAKE_C_FLAGS}")
endif(64BIT)
if(AVX)
set(CMAKE_C_FLAGS "-mavx ${CMAKE_C_FLAGS}")
endif(AVX)
if(AVX2)
set(CMAKE_C_FLAGS "-mavx -mavx2 -no-fma ${CMAKE_C_FLAGS}")
endif(AVX2)
if(AVX512)
set(CMAKE_C_FLAGS "-axcommon-avx512 -no-fma ${CMAKE_C_FLAGS}")
endif(AVX512)
if(AVX512_SKYLAKE)
set(CMAKE_C_FLAGS "-axskylake-avx512 -no-fma ${CMAKE_C_FLAGS}")
endif(AVX512_SKYLAKE)
if(NATIVE)
set(CMAKE_C_FLAGS "-xHost ${CMAKE_C_FLAGS}")
endif(NATIVE)
set(CMAKE_C_FLAGS_RELEASE "-O3")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g")
if(STATIC)
set(CMAKE_C_LINKER_FLAGS "-static ${CMAKE_C_LINKER_FLAGS}")
endif(STATIC)
endif()
# AppleClang
if(${CMAKE_C_COMPILER_ID} MATCHES "AppleClang")
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES aarch64 )
set (CMAKE_C_FLAGS "-ffp-contract=off ${CMAKE_C_FLAGS}")
endif()
set (CMAKE_C_FLAGS_RELEASE "-O3")
set (CMAKE_C_FLAGS_DEBUG "-O0 -g3")
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES AMD64 OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES x86_64 OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES i686)
if(32BIT)
set(CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}")
endif(32BIT)
if(64BIT)
set(CMAKE_C_FLAGS "-m64 ${CMAKE_C_FLAGS}")
endif(64BIT)
if(AVX)
set(CMAKE_C_FLAGS "-mavx ${CMAKE_C_FLAGS}")
endif(AVX)
if(AVX2)
set(CMAKE_C_FLAGS "-mavx -mavx2 -mno-fma4 -mno-fma ${CMAKE_C_FLAGS}")
endif(AVX2)
if(AVX512)
set(CMAKE_C_FLAGS "-mavx -mavx2 -mavx512f -mno-fma4 -mno-fma ${CMAKE_C_FLAGS}")
endif(AVX512)
if(AVX512_SKYLAKE)
set(CMAKE_C_FLAGS "-mavx -mavx2 -mavx512f -mavx512cd -mavx512bw -mavx512vl -mno-fma4 -mno-fma ${CMAKE_C_FLAGS}")
endif(AVX512_SKYLAKE)
if(NATIVE)
set(CMAKE_C_FLAGS "-march=native ${CMAKE_C_FLAGS}")
endif(NATIVE)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND BOINC)
set(CMAKE_C_FLAGS "-mmacosx-version-min=${MIN_OSX_VERSION} ${CMAKE_C_FLAGS}")
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND BOINC)
if(STATIC)
set(CMAKE_C_LINKER_FLAGS "-static ${CMAKE_C_LINKER_FLAGS}")
endif(STATIC)
endif()
# CXX Flags
if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES aarch64 )
set (CMAKE_CXX_FLAGS "-ffp-contract=off ${CMAKE_CXX_FLAGS}")
endif()
set (CMAKE_CXX_FLAGS_RELEASE "-O3")
set (CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
if(LTO)
# set(CMAKE_CXX_LINK_EXECUTABLE "")
set(CMAKE_Fortran_CXX_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto -Wl,-flto")
endif(LTO)
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES AMD64 OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES x86_64 OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES i686)
if(32BIT)
set(CMAKE_CXX_FLAGS "-m32 ${CMAKE_CXX_FLAGS}")
endif(32BIT)
if(64BIT)
set(CMAKE_CXX_FLAGS "-m64 ${CMAKE_CXX_FLAGS}")
endif(64BIT)
if(AVX)
set(CMAKE_CXX_FLAGS "-mavx ${CMAKE_CXX_FLAGS}")
endif(AVX)
if(AVX2)
set(CMAKE_CXX_FLAGS "-mavx -mavx2 -mno-fma4 -mno-fma ${CMAKE_CXX_FLAGS}")
endif(AVX2)
if(AVX512)
set(CMAKE_CXX_FLAGS "-mavx -mavx2 -mavx512f -mno-fma4 -mno-fma ${CMAKE_CXX_FLAGS}")
endif(AVX512)