-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathCMakeLists.txt
3212 lines (2848 loc) · 106 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
#***********************************************************************
# This file is part of OpenMolcas. *
# *
# OpenMolcas is free software; you can redistribute it and/or modify *
# it under the terms of the GNU Lesser General Public License, v. 2.1. *
# OpenMolcas is distributed in the hope that it will be useful, but it *
# is provided "as is" and without any express or implied warranties. *
# For more details see the full text of the license in the file *
# LICENSE or in <http://www.gnu.org/licenses/>. *
# *
# Copyright (C) 2014-2016, Steven Vancoillie *
# 2014-2023, Ignacio Fdez. Galván *
# 2015, Stefan Knecht *
# 2020, Gerardo Raggi *
#***********************************************************************
# Global CMakeLists.txt file for building OpenMolcas with CMake.
#
# Steven Vancoillie - Spring 2014, on a Saturday afternoon, with coffee
# Ignacio Fdez. Galván made several improvements / additions
# Gerardo Raggi - AppleClang
cmake_minimum_required (VERSION 3.12)
cmake_policy (VERSION 3.12...3.21)
project (OpenMolcas
LANGUAGES Fortran C
VERSION ""
)
#set (CMAKE_VERBOSE_MAKEFILE ON)
include (${PROJECT_SOURCE_DIR}/cmake/cmake_helpers.cmake)
# Prevent in-source builds
# If an in-source build is attempted, you will still need to clean up a few files manually.
set (CMAKE_DISABLE_SOURCE_CHANGES ON)
set (CMAKE_DISABLE_IN_SOURCE_BUILD ON)
get_filename_component (sourcedir "${CMAKE_SOURCE_DIR}" REALPATH)
get_filename_component (binarydir "${CMAKE_BINARY_DIR}" REALPATH)
if ("${sourcedir}" STREQUAL "${binarydir}")
message (FATAL_ERROR "In-source builds in ${CMAKE_BINARY_DIR} are not "
"allowed, please remove ./CMakeCache.txt and ./CMakeFiles/, create a "
"separate build directory and run cmake from there.")
endif ()
# discover some necessary tools
find_program (GIT "git")
find_program (PERL "perl")
mark_as_advanced (FORCE GIT PERL)
FIND_PACKAGE (Python COMPONENTS Interpreter)
################################################################################
# #
# Options #
# #
################################################################################
# The build type, specifies the different optimization types.
if (NOT DEFINED CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "")
set (CMAKE_BUILD_TYPE "Release" CACHE STRING
"Type of build, options are: None (CFLAGS/FFLAGS can be used), Debug, Garble, RelWithDebInfo, Release, Fast."
FORCE)
endif ()
set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS None Debug Garble RelWithDebInfo Release Fast)
# The place where OpenMolcas is installed with make install.
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX "/opt/OpenMolcas" CACHE PATH "Location where OpenMolcas will be installed." FORCE)
endif ()
set (EXTRA_INSTALL_TARGETS "")
set (EXTRA_INSTALL_DIRS "")
set (EXTRA_INSTALL_IMPORTED_LIBS "")
option (INSTALL_TESTS "Install the test files and verify script." OFF)
set (DEBUG_DEFS "${DEBUG_DEFS}" CACHE STRING "Additional user-supplied definitions.")
separate_arguments (DEBUG_DEFS)
option (BUILD_SHARED_LIBS "Build dynamically-linked libraries." OFF)
option (BUILD_STATIC_LIBS "Build statically-linked libraries too." OFF)
if (BUILD_SHARED_LIBS)
mark_as_advanced (CLEAR BUILD_STATIC_LIBS)
else ()
mark_as_advanced (FORCE BUILD_STATIC_LIBS)
endif ()
option (MPI "Enable MPI parallellization." OFF)
option (GA "Use Global Arrays library." OFF)
option (OPENMP "Enable multi-threading." OFF)
option (IPO "Enable interprocedural optimization (if supported)." OFF)
option (BOUNDS "Enable bounds checking (only GNU Fortran)." OFF)
option (EXPERT "Show advanced compiler flags in CMake GUI)." OFF)
option (BIGOT "Do not allow any compiler warning (treat them as errors)." OFF)
set (LINALG_OPTIONS "Choose linear algebra library, options: Internal (default), Runtime, MKL, OpenBLAS, AOCL, Accelerate, Manual.")
if (DEFINED LINALG)
set (LINALG "${LINALG}" CACHE STRING "${LINALG_OPTIONS}")
if (NOT ";Internal;Runtime;MKL;OpenBLAS;AOCL;Accelerate;Manual;" MATCHES ";${LINALG};")
message (FATAL_ERROR "Unsuported LINALG: ${LINALG}")
endif ()
else ()
set (LINALG "Internal" CACHE STRING "${LINALG_OPTIONS}")
endif ()
set_property (CACHE LINALG PROPERTY STRINGS Internal Runtime MKL OpenBLAS AOCL Accelerate Manual)
option (CUBLAS "Enable CUDA BLAS library." OFF)
option (NVBLAS "Enable NVidia BLAS library." OFF)
set (EXTERNAL_LIBXC "" CACHE STRING "Location for an external Libxc build")
option (FDE "Enable Frozen-density-embedding (FDE) interface." OFF)
option (GROMACS "Compile Gromacs interface." OFF)
option (BLOCK "Activate BLOCK-DMRG support." OFF)
option (CHEMPS2 "Activate CheMPS2-DMRG support." OFF)
option (DICE "Activate Dice-SHCI support." OFF)
option (GPERFTOOLS "Activate gperftools CPU profiling." OFF)
option (GCOV "Activate code coverage profiling (use with Debug/-O0)." OFF)
option (HDF5 "Activate HDF5 support for wavefunction format." ON)
option (TOOLS "Compile supported tools." OFF)
option (BUILD_TESTING "Build the unit_tests." ON)
if (";Debug;Garble;" MATCHES ";${CMAKE_BUILD_TYPE};")
add_compile_definitions (_ADDITIONAL_RUNTIME_CHECK_)
endif ()
if (";Debug;Garble;RelWithDebInfo;" MATCHES ";${CMAKE_BUILD_TYPE};" OR
CMAKE_Fortran_COMPILER_ID STREQUAL "NAG" OR
BIGOT)
add_compile_definitions (_WARNING_WORKAROUND_)
endif ()
# External projects
option (DMRG "Activate QCMaquis DMRG driver and library." OFF)
option (EFPLIB "Enable EFPLib library for effective fragment potentials (requires External/efp submodule)." OFF)
option (GA_BUILD "Build Global Arrays." OFF)
option (GEN1INT "Enable Gen1Int library for 1-electron integrals." OFF)
option (MolGUI "Enable the Molcas Graphical User Interface." OFF)
option (MSYM "Activate MSYM support (requires External/libmsym submodule)." OFF)
option (NECI "Activate NECI support (requires External/NECI submodule)." OFF)
option (NEVPT2 "Activate (DMRG)-NEVPT2 support." OFF)
option (WFA "Activate extended wavefunction analysis (requires External/libwfa submodule)." OFF)
################################################################################
# #
# Global settings #
# #
################################################################################
# mark that we are running CMake (for subprocesses)
set (ENV{CMAKE_SESSION} "OpenMolcas")
# project name and supported languages
#=====================================
message ("Configuring compilers:")
if (WFA OR MolGUI OR DMRG)
enable_language (CXX)
endif ()
#avoid using CXX compiler for linking
set (CMAKE_CXX_LINKER_PREFERENCE_PROPAGATES "FALSE")
add_compile_definitions (_MOLCAS_)
#set cmake module search paths
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH})
# location of molcas-extra
if (NOT DEFINED EXTRA)
if (DEFINED ENV{EXTRA})
set (EXTRA $ENV{EXTRA})
else ()
set (EXTRA "")
endif ()
endif ()
if (NOT "${EXTRA}" STREQUAL "")
if (NOT IS_ABSOLUTE "${EXTRA}")
set (EXTRA "${PROJECT_BINARY_DIR}/${EXTRA}")
endif ()
get_filename_component (EXTRA "${EXTRA}" ABSOLUTE)
if (NOT EXISTS "${EXTRA}")
message (WARNING "The molcas-extra directory ${EXTRA} does not exist.")
else ()
FILE (STRINGS "${EXTRA}/.molcashome" DIR_TYPE)
if ("${DIR_TYPE}" STREQUAL "molcas-extra")
set (EXTRA_DIR ${EXTRA})
add_compile_definitions (_HAVE_EXTRA_)
else ()
message (FATAL_ERROR "The directory ${EXTRA} does not contain molcas-extra.")
endif ()
endif ()
endif ()
set (EXTRA "${EXTRA}" CACHE PATH "Location of the molcas-extra directory." FORCE)
# possible locations for source code
set (OPENMOLCAS_DIR ${CMAKE_CURRENT_LIST_DIR})
if (NOT ${PROJECT_SOURCE_DIR} STREQUAL ${OPENMOLCAS_DIR})
set (basedirs ${PROJECT_SOURCE_DIR})
set (EXTRA_DIR ${PROJECT_SOURCE_DIR})
add_compile_definitions (_HAVE_EXTRA_)
endif ()
list (APPEND basedirs ${OPENMOLCAS_DIR})
if (NOT "${EXTRA}" STREQUAL "")
if (NOT ";${basedirs};" MATCHES ";${EXTRA};")
list (APPEND basedirs ${EXTRA})
endif ()
endif ()
foreach (BASE_DIR ${basedirs})
file (GLOB source_roots_tmp RELATIVE ${PROJECT_SOURCE_DIR} "${BASE_DIR}/src*")
list (SORT source_roots_tmp)
list (APPEND source_roots ${source_roots_tmp})
endforeach ()
list (REVERSE basedirs)
# get version from git if available, otherwise look in .molcasversion
#====================================================================
message ("Detecting Molcas version info:")
set (ENV{MOLCAS} ${PROJECT_BINARY_DIR})
set (ENV{OPENMOLCAS} ${OPENMOLCAS_DIR})
if (DEFINED EXTRA_DIR)
set (ENV{MOLCAS_SOURCE} ${EXTRA_DIR})
else ()
set (ENV{MOLCAS_SOURCE} ${OPENMOLCAS_DIR})
endif ()
execute_process (
COMMAND ${GIT} "rev-parse" "--git-dir"
WORKING_DIRECTORY ${OPENMOLCAS_DIR}
OUTPUT_VARIABLE GIT_REVPARSE_OUTPUT
ERROR_VARIABLE GIT_REVPARSE_ERROR
RESULT_VARIABLE GIT_REVPARSE_RC
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (GIT_REVPARSE_RC)
set (OPENMOLCAS_GIT_REPO "${OPENMOLCAS_DIR}/.git")
else ()
set (OPENMOLCAS_GIT_REPO "${GIT_REVPARSE_OUTPUT}")
if (NOT IS_ABSOLUTE "${OPENMOLCAS_GIT_REPO}")
set (OPENMOLCAS_GIT_REPO "${OPENMOLCAS_DIR}/${OPENMOLCAS_GIT_REPO}")
endif ()
endif ()
set (MOLCAS_VERSION_FILE "${PROJECT_SOURCE_DIR}/.molcasversion")
if (DEFINED EXTRA_DIR)
execute_process (
COMMAND ${GIT} "rev-parse" "--git-dir"
WORKING_DIRECTORY ${EXTRA_DIR}
OUTPUT_VARIABLE GIT_REVPARSE_OUTPUT
ERROR_VARIABLE GIT_REVPARSE_ERROR
RESULT_VARIABLE GIT_REVPARSE_RC
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (GIT_REVPARSE_RC)
set (EXTRA_GIT_REPO "${EXTRA_DIR}/.git")
else ()
set (EXTRA_GIT_REPO "${GIT_REVPARSE_OUTPUT}")
if (NOT IS_ABSOLUTE "${EXTRA_GIT_REPO}")
set (EXTRA_GIT_REPO "${EXTRA_DIR}/${EXTRA_GIT_REPO}")
endif ()
endif ()
endif ()
if (EXISTS ${GIT})
foreach (BASE_DIR ${basedirs})
if ("${BASE_DIR}" STREQUAL "${OPENMOLCAS_DIR}")
if (EXISTS ${OPENMOLCAS_GIT_REPO})
set (MOLCAS_GIT_REPO ${OPENMOLCAS_GIT_REPO})
else ()
continue ()
endif ()
set (label "")
elseif ("${BASE_DIR}" STREQUAL "${EXTRA_DIR}")
if (EXISTS ${EXTRA_GIT_REPO})
set (MOLCAS_GIT_REPO ${EXTRA_GIT_REPO})
else ()
continue ()
endif ()
set (label "-extra")
endif ()
# always set the HEAD as a source for configuring
configure_file ("${MOLCAS_GIT_REPO}/HEAD" git-head${label} COPYONLY)
# if it is a ref to a named branch, include the branch ref too
file (READ "${MOLCAS_GIT_REPO}/HEAD" HEAD_STRING)
string (STRIP "${HEAD_STRING}" HEAD_STRING)
string (REPLACE "ref: " "" HEAD_REF "${HEAD_STRING}")
if (EXISTS "${MOLCAS_GIT_REPO}/${HEAD_REF}")
configure_file ("${MOLCAS_GIT_REPO}/${HEAD_REF}" git-head-ref${label} COPYONLY)
endif ()
# now, get the actual versions from the git describe tool
execute_process (
COMMAND ${GIT} "describe" "--always" "--dirty" "--match" "v*"
WORKING_DIRECTORY ${BASE_DIR}
OUTPUT_VARIABLE MOLCAS_VERSION
ERROR_VARIABLE GIT_DESCRIBE_ERROR
RESULT_VARIABLE GIT_DESCRIBE_RC
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (GIT_DESCRIBE_RC)
message (FATAL_ERROR "Failed to run git: ${GIT_DESCRIBE_ERROR}")
endif ()
if ("${BASE_DIR}" STREQUAL "${OPENMOLCAS_DIR}")
set (OPENMOLCAS_VERSION ${MOLCAS_VERSION})
elseif ("${BASE_DIR}" STREQUAL "${EXTRA_DIR}")
set (EXTRA_VERSION ${MOLCAS_VERSION})
endif ()
endforeach (BASE_DIR)
# used for external projects (git submodules)
set (DEVELOPMENT_CODE)
execute_process (
COMMAND ${GIT} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
ERROR_QUIET
)
if (NOT ${GIT_BRANCH} STREQUAL "")
string (STRIP ${GIT_BRANCH} GIT_BRANCH)
endif ()
endif ()
if (DEFINED OPENMOLCAS_VERSION)
# Read the version from the .tags file, which should be populated when the code
# has been obtained from "git archive". Since there's no way to know if the
# code has been modified, add a question mark
elseif (EXISTS ${OPENMOLCAS_DIR}/.tags)
file (STRINGS ${OPENMOLCAS_DIR}/.tags LINES)
foreach (line ${LINES})
string (FIND "${line}" "(" has_paren)
string (FIND "${line}" "%" has_percent)
string (REGEX MATCH "tag: (v[^,]*)," match ${line})
# Parse the tag if present
if (has_paren GREATER -1)
if (NOT ${match} STREQUAL "")
set (OPENMOLCAS_VERSION "${CMAKE_MATCH_1} ?")
endif ()
# Or just use the commit sha, making sure this is not the raw file
elseif (has_percent EQUAL -1)
string (SUBSTRING ${line} 0 14 OPENMOLCAS_VERSION)
set (OPENMOLCAS_VERSION "o${OPENMOLCAS_VERSION} ?")
endif ()
endforeach ()
elseif (EXISTS ${MOLCAS_VERSION_FILE})
file (STRINGS ${MOLCAS_VERSION_FILE} LINES)
foreach (line ${LINES})
string (FIND "${line}" ".o" is_open)
string (FIND "${line}" ".x" is_extra)
if (is_open GREATER -1)
string (STRIP ${line} OPENMOLCAS_VERSION)
elseif (is_extra GREATER -1)
string (STRIP ${line} EXTRA_VERSION)
endif ()
endforeach ()
else ()
set (OPENMOLCAS_VERSION "unknown")
set (GIT_BRANCH "")
endif ()
message ("-- OPENMOLCAS_VERSION: ${OPENMOLCAS_VERSION}")
set (MOLCAS_VERSION ${OPENMOLCAS_VERSION})
if (DEFINED EXTRA_VERSION)
message ("-- EXTRA_VERSION: ${EXTRA_VERSION}")
set (MOLCAS_VERSION "${OPENMOLCAS_VERSION} & ${EXTRA_VERSION}")
endif ()
# set location of libraries and executables
#==========================================
set (LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
set (EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
# location for external projects (git submodules)
#================================================
set (extprojsdir "${OPENMOLCAS_DIR}/External")
# global include directory
#=========================
set (MAIN_INCLUDE_DIR ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/include)
configure_file (${OPENMOLCAS_DIR}/src/Include/molcasversion.h.in ${MAIN_INCLUDE_DIR}/molcasversion.h)
foreach (BASE_DIR ${basedirs})
if (EXISTS "${BASE_DIR}/src/Include")
include_directories (${BASE_DIR}/src/Include)
endif ()
endforeach ()
include_directories (${MAIN_INCLUDE_DIR})
# system information
#===================
message ("Detecting system info:")
# operating system
set (OS ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR})
message ("-- OS: ${OS}")
# address mode
if (${CMAKE_SIZEOF_VOID_P} EQUAL 8)
set (ADDRMODE 64)
add_compile_definitions (_I8_)
else ()
set (ADDRMODE 32)
endif ()
message ("-- ADDRMODE: ${ADDRMODE}")
# platform settings
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
add_compile_definitions (_LINUX_)
if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86" OR
${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
set (PLATFORM "LINUX")
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
set (PLATFORM "LINUX64")
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ia64")
set (PLATFORM "LINUX64_IA")
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ppc_64" OR
${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ppc64le")
set (PLATFORM "PPC64")
endif ()
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
add_compile_definitions (_LINUX_ _DARWIN_ _DARWIN_C_SOURCE)
set (CMAKE_MACOSX_RPATH 0)
set (PLATFORM "MacOS")
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "CYGWIN")
add_compile_definitions (_LINUX_ _CYGWIN_)
if (ADDRMODE EQUAL 32)
set (PLATFORM "WIN")
elseif (ADDRMODE EQUAL 64)
set (PLATFORM "WIN64")
endif ()
endif ()
if (NOT PLATFORM)
if (DEFINED EXTRA_DIR)
message (WARNING "Unsupported platform.")
endif ()
else ()
message ("-- PLATFORM: ${PLATFORM}")
endif ()
################################################################################
# #
# Compiler-specific settings #
# #
################################################################################
include (${PROJECT_SOURCE_DIR}/cmake/compilers.cmake)
# Generate the actual flags used in the build
#============================================
if (DMRG OR WFA)
if (NOT CXXCID)
message (FATAL_ERROR "unsupported CXX compiler: ${CMAKE_CXX_COMPILER_ID}")
endif ()
endif ()
if (NOT CCID)
message (FATAL_ERROR "unsupported C compiler: ${CMAKE_C_COMPILER_ID}")
endif ()
if (NOT FCID)
message (FATAL_ERROR "unsupported Fortran compiler: ${CMAKE_Fortran_COMPILER_ID}")
endif ()
# flatten namespace on Mac OS X
if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS} -flat_namespace")
endif ()
# Exception trapping
if (CMAKE_BUILD_TYPE STREQUAL "Garble")
add_compile_definitions (_GARBLE_ _FPE_TRAP_)
# Disable FPE traps for compilers that do not support IEEE Fortran modules
if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" AND
CMAKE_Fortran_COMPILER_VERSION VERSION_LESS "5.0")
remove_definitions (-D_FPE_TRAP_)
elseif (NOT LINALG STREQUAL "Internal")
message (WARNING
"Garble is active, but an external LINALG library is used! "
"The use of an external BLAS/LAPACK can result in floating point "
"exceptions handled by the library being trapped instead. "
"Please use -DLINALG=Internal for better chances for Garble to work correctly!")
set (FFLAGS_${FCID}_GARBLE "${FFLAGS_${FCID}_GARBLE} ${${FCID}_TRAP}")
else ()
message (WARNING
"Garble and floating point exception trapping are active! "
"It is possible that intended exceptions within BLAS/LAPACK crash the program. "
"Be warned!")
set (FFLAGS_${FCID}_GARBLE "${FFLAGS_${FCID}_GARBLE} ${${FCID}_TRAP}")
endif ()
endif ()
if (NOT CMAKE_GENERATOR STREQUAL "Ninja")
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${FFLAGS_${FCID}_PREPROCESS}")
endif ()
if (ADDRMODE EQUAL 64)
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${FFLAGS_${FCID}_ILP64}")
endif ()
if (OPENMP)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXFLAGS_${CXXCID}_OPENMP}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CFLAGS_${CCID}_OPENMP}")
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${FFLAGS_${FCID}_OPENMP}")
else ()
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXFLAGS_${CXXCID}_NO_OPENMP}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CFLAGS_${CCID}_NO_OPENMP}")
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${FFLAGS_${FCID}_NO_OPENMP}")
endif ()
if (BOUNDS)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXFLAGS_${CXXCID}_BOUNDS}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CFLAGS_${CCID}_BOUNDS}")
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${FFLAGS_${FCID}_BOUNDS}")
list (APPEND mma_util_defs "_MALLOC_INTERCEPT_")
endif ()
# Allow user-specified modifications
if (EXTRA_CXXFLAGS)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS}")
endif ()
if (EXTRA_CFLAGS)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
endif ()
if (EXTRA_FFLAGS)
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${EXTRA_FFLAGS}")
endif ()
################################################################################
# #
# Process options #
# #
################################################################################
if ((BLOCK AND CHEMPS2) OR
(BLOCK AND DMRG) OR
(BLOCK AND DICE) OR
(CHEMPS2 AND DMRG) OR
(CHEMPS2 AND DICE) OR
(DICE AND DMRG))
message (FATAL_ERROR "BLOCK, CHEMPS2, DICE, and DMRG options are not compatible.")
endif ()
# Install directory
#==================
if (NOT IS_ABSOLUTE "${CMAKE_INSTALL_PREFIX}")
set (CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_PREFIX}")
endif ()
get_filename_component (CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" ABSOLUTE)
# Parallel settings
#==================
if (MPI)
message ("Configuring with MPI parallellization:")
find_package (MPI REQUIRED)
add_compile_definitions (_MOLCAS_MPP_)
include_directories (${MPI_Fortran_INCLUDE_PATH} ${MPI_C_INCLUDE_PATH})
message ("-- MPI_C_INCLUDE_PATH: ${MPI_C_INCLUDE_PATH}")
message ("-- MPI_Fortran_INCLUDE_PATH: ${MPI_Fortran_INCLUDE_PATH}")
message ("-- MPI_C_LIBRARIES: ${MPI_C_LIBRARIES}")
message ("-- MPI_Fortran_LIBRARIES: ${MPI_Fortran_LIBRARIES}")
message ("-- MPIEXEC: ${MPIEXEC}")
execute_process (
COMMAND ${MPIEXEC} "--version"
OUTPUT_VARIABLE MPIEXEC_VERSION
ERROR_VARIABLE MPIEXEC_VERSION
)
if (MPIEXEC_VERSION MATCHES "OpenRTE" OR MPIEXEC_VERSION MATCHES "Open MPI")
set (MPI_IMPLEMENTATION "openmpi")
elseif (MPIEXEC_VERSION MATCHES "Intel\\(R\\) MPI")
set (MPI_IMPLEMENTATION "impi")
elseif (MPIEXEC_VERSION MATCHES "HYDRA")
set (MPI_IMPLEMENTATION "mpich")
else ()
# check for MPICH 3, which has only "mpichversion" as an executable,
# but "mpiexec --version" does not work
execute_process (
COMMAND "mpichversion"
OUTPUT_VARIABLE MPIEXEC_VERSION
ERROR_VARIABLE MPIEXEC_VERSION
)
if (MPIEXEC_VERSION MATCHES "MPICH")
set (MPI_IMPLEMENTATION "mpich")
else ()
message (FATAL_ERROR "Unknown or unsupported MPI implementation:\n${MPIEXEC_VERSION}")
endif ()
endif ()
message ("-- MPI_IMPLEMENTATION: ${MPI_IMPLEMENTATION}")
# MPICH and GCC > 10.0 requires explicit MPI interface
if ((MPI_IMPLEMENTATION STREQUAL "mpich" OR MPI_IMPLEMENTATION STREQUAL "impi") AND
CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" AND
CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER "10.0")
add_compile_definitions (_NEED_EXPLICIT_MPI_INTERFACE_)
endif ()
list (APPEND EXTERNAL_LIBRARIES ${MPI_Fortran_LIBRARIES})
endif ()
# Support for HDF5 I/O library
#=============================
if (HDF5)
if (ADDRMODE EQUAL 32)
message ("-- HDF5 interface not compatible with 32bit installations")
else ()
message ("Configuring HDF5 support:")
get_property (languages GLOBAL PROPERTY ENABLED_LANGUAGES)
if (";${languages};" MATCHES ";CXX;")
find_package (HDF5 COMPONENTS C CXX)
else ()
find_package (HDF5 COMPONENTS C)
endif ()
if (HDF5_FOUND)
message ("-- HDF5_INCLUDE_DIRS: ${HDF5_INCLUDE_DIRS}")
message ("-- HDF5_C_LIBRARIES: ${HDF5_C_LIBRARIES}")
if (HDF5_VERSION)
if (DMRG AND HDF5_VERSION VERSION_EQUAL "1.10.0.1")
message (FATAL_ERROR "This HDF5 version (${HDF5_VERSION}) is not supported by QCMaquis.")
endif ()
endif ()
list (APPEND EXTERNAL_LIBRARIES ${HDF5_C_LIBRARIES})
if (HDF5_CXX_LIBRARIES)
message ("-- HDF5_CXX_LIBRARIES: ${HDF5_CXX_LIBRARIES}")
list (APPEND EXTERNAL_LIBRARIES ${HDF5_CXX_LIBRARIES})
endif ()
else ()
message ("-- HDF5 not found, it will be deactivated")
endif ()
endif ()
endif ()
# BLAS/LAPACK settings
#=====================
message ("Configuring linear algebra libraries:")
# If one uses BLAS/LAPACK, you can use the CMake FindBLAS/FindLAPACK modules to
# set everything, which is determined by setting the BLA_VENDOR environment
# variable. Unfortunately, currently, the modules that comes with CMake doesn't
# seem to support any ilp64 version of MKL, as it only has e.g. Intel10_64lp
# For now, I'm using some non-portable thing.
set (MKLROOT "" CACHE PATH "MKL root directory.")
if (LINALG STREQUAL "MKL")
message ("-- Using Intel Math Kernel Library (MKL)")
# quick bypass for 32bit, don't bother with it (for now?)
if (NOT ADDRMODE EQUAL 64)
message (FATAL_ERROR "Use of MKL for 32bit installation not implemented.")
endif ()
mark_as_advanced (CLEAR MKLROOT)
if (MKLROOT STREQUAL "")
set (MKLROOT $ENV{MKLROOT} CACHE PATH "MKL root directory." FORCE)
if (NOT MKLROOT)
message (FATAL_ERROR
"You must set environment variable MKLROOT, "
"or specify -DMKLROOT=/path/to/mkl_root_dir "
"when running cmake.")
endif ()
endif ()
# at this point, MKLROOT should be defined and not empty
message ("-- MKLROOT = ${MKLROOT}")
# here we check if MKLROOT has changed after it was last used
# succesfully, if so then we need to reprocess the checks here.
if (NOT MKLROOT STREQUAL MKLROOT_LAST)
# reset MKL paths
set (MKL_INCLUDE_PATH "${MKLROOT}/include" CACHE PATH "location of MKL include files." FORCE)
set (MKL_LIBRARY_PATH "${MKLROOT}/lib" CACHE PATH "location of MKL libraries." FORCE)
# uncache variables
unset (LIBMKL_BLAS CACHE)
unset (LIBMKL_LAPACK CACHE)
unset (LIBMKL_CORE CACHE)
unset (LIBMKL_INTERFACE CACHE)
unset (LIBMKL_SEQUENTIAL CACHE)
unset (LIBMKL_THREADING CACHE)
unset (LIBMKL_SCALAPACK CACHE)
unset (LIBMKL_BLACS CACHE)
# cache last used MKLROOT
set (MKLROOT_LAST ${MKLROOT} CACHE INTERNAL "last value." FORCE)
endif ()
message ("-- MKL_INCLUDE_PATH = ${MKL_INCLUDE_PATH}")
message ("-- MKL_LIBRARY_PATH = ${MKL_LIBRARY_PATH}")
if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
if (ADDRMODE EQUAL 32)
message (FATAL_ERROR
"PLATFORM=MacOS, but you use ADDRMODE=32. This is "
"either a VERY old, unsupported platform, or "
"there is a configuration error.")
endif ()
else ()
if (ADDRMODE EQUAL 64)
list (APPEND mkllibs "intel64")
elseif (ADDRMODE EQUAL 32)
list (APPEND mkllibs "ia32")
endif ()
endif ()
# core library
if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
find_library (LIBMKL_CORE
NAMES "libmkl_core.a"
PATHS ${MKL_LIBRARY_PATH}
PATH_SUFFIXES ${mkllibs}
NO_DEFAULT_PATH
)
else ()
find_library (LIBMKL_CORE
NAMES "mkl_core"
PATHS ${MKL_LIBRARY_PATH}
PATH_SUFFIXES ${mkllibs}
NO_DEFAULT_PATH
)
endif ()
# compiler-specific library interface
if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
find_library (LIBMKL_BLAS
NAMES "libmkl_blas95_ilp64.a"
PATHS ${MKL_LIBRARY_PATH}
PATH_SUFFIXES ${mkllibs}
NO_DEFAULT_PATH
)
find_library (LIBMKL_LAPACK
NAMES "libmkl_lapack95_ilp64.a"
PATHS ${MKL_LIBRARY_PATH}
PATH_SUFFIXES ${mkllibs}
NO_DEFAULT_PATH
)
find_library (LIBMKL_INTERFACE
NAMES "libmkl_intel_ilp64.a"
PATHS ${MKL_LIBRARY_PATH}
PATH_SUFFIXES ${mkllibs}
NO_DEFAULT_PATH
)
else ()
find_library (LIBMKL_INTERFACE
NAMES "mkl_gf_ilp64"
PATHS ${MKL_LIBRARY_PATH}
PATH_SUFFIXES ${mkllibs}
NO_DEFAULT_PATH
)
endif ()
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" OR
CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM")
find_library (LIBMKL_INTERFACE
NAMES "mkl_intel_ilp64"
PATHS ${MKL_LIBRARY_PATH}
PATH_SUFFIXES ${mkllibs}
NO_DEFAULT_PATH
)
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "PGI") # apparently PGI uses this too
find_library (LIBMKL_INTERFACE
NAMES "mkl_intel_ilp64"
PATHS ${MKL_LIBRARY_PATH}
PATH_SUFFIXES ${mkllibs}
NO_DEFAULT_PATH
)
endif ()
# sequential/compiler-specific threading interface
if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
find_library (LIBMKL_SEQUENTIAL
NAMES "libmkl_sequential.a"
PATHS ${MKL_LIBRARY_PATH}
PATH_SUFFIXES ${mkllibs}
NO_DEFAULT_PATH
)
else ()
find_library (LIBMKL_SEQUENTIAL
NAMES "mkl_sequential"
PATHS ${MKL_LIBRARY_PATH}
PATH_SUFFIXES ${mkllibs}
NO_DEFAULT_PATH
)
endif ()
if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
set (LIBMKL_OMP_LINK_FLAGS "${FFLAGS_GNU_OPENMP}")
find_library (LIBMKL_THREADING
NAMES "mkl_gnu_thread"
PATHS ${MKL_LIBRARY_PATH}
PATH_SUFFIXES ${mkllibs}
NO_DEFAULT_PATH
)
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" OR
CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM")
set (LIBMKL_OMP_LINK_FLAGS "${FFLAGS_Intel_OPENMP}")
find_library (LIBMKL_THREADING
NAMES "mkl_intel_thread"
PATHS ${MKL_LIBRARY_PATH}
PATH_SUFFIXES ${mkllibs}
NO_DEFAULT_PATH
)
endif ()
# find scalapack/blacs for parallel lapack support
find_library (LIBMKL_SCALAPACK
NAMES "mkl_scalapack_ilp64"
PATHS ${MKL_LIBRARY_PATH}
PATH_SUFFIXES ${mkllibs}
NO_DEFAULT_PATH
)
if (MPI_IMPLEMENTATION STREQUAL "openmpi")
find_library (LIBMKL_BLACS
NAMES "mkl_blacs_openmpi_ilp64"
PATHS ${MKL_LIBRARY_PATH}
PATH_SUFFIXES ${mkllibs}
NO_DEFAULT_PATH
)
elseif (MPI_IMPLEMENTATION STREQUAL "impi")
find_library (LIBMKL_BLACS
NAMES "mkl_blacs_intelmpi_ilp64"
PATHS ${MKL_LIBRARY_PATH}
PATH_SUFFIXES ${mkllibs}
NO_DEFAULT_PATH
)
elseif (MPI_IMPLEMENTATION STREQUAL "mpich")
find_library (LIBMKL_BLACS
NAMES "mkl_blacs_intelmpi_ilp64"
PATHS ${MKL_LIBRARY_PATH}
PATH_SUFFIXES ${mkllibs}
NO_DEFAULT_PATH
)
endif ()
# generate actual library list with paths
if (MPI AND LIBMKL_SCALAPACK)
add_compile_definitions (_SCALAPACK_)
list (APPEND MKL_LIBRARIES ${LIBMKL_SCALAPACK})
endif ()
if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
list (APPEND MKL_LIBRARIES ${LIBMKL_BLAS})
list (APPEND MKL_LIBRARIES ${LIBMKL_LAPACK})
endif ()
list (APPEND MKL_LIBRARIES ${LIBMKL_INTERFACE})
list (APPEND MKL_LIBRARIES ${LIBMKL_CORE})
if (OPENMP)
set (CMAKE_EXE_LINKER_FLAGS ${LIBMKL_OMP_LINK_FLAGS})
list (APPEND MKL_LIBRARIES ${LIBMKL_THREADING})
else ()
list (APPEND MKL_LIBRARIES ${LIBMKL_SEQUENTIAL})
endif ()
if (MPI AND LIBMKL_BLACS)
list (APPEND MKL_LIBRARIES ${LIBMKL_BLACS})
endif ()
list (APPEND linalg_util_defs "_MKL_")
set (LINALG_LIBRARIES ${MKL_LIBRARIES})
else ()
mark_as_advanced (FORCE MKLROOT)
endif ()
# AOCL settings, I don't think FindBLAS supports recent AOCL either
set (AOCLROOT "" CACHE PATH "AOCL path.")
if (LINALG STREQUAL "AOCL")
message ("-- Using AMD Optimizing CPU Libraries (AOCL)")
mark_as_advanced (CLEAR AOCLROOT)
if (AOCLROOT STREQUAL "")
set (AOCLROOT $ENV{AOCLROOT} CACHE PATH "AOCL root directory." FORCE)
if (NOT AOCLROOT)
message (FATAL_ERROR
"You must set environment variable AOCLROOT, "
"or specify -DAOCLROOT=/path/to/AOCL_dir "
"when running cmake.")
endif ()
endif ()
# Search libflame first
find_library (LIBFLAME
NAMES flame
PATHS ${AOCLROOT}
PATH_SUFFIXES lib
NO_DEFAULT_PATH
)
if (NOT LIBFLAME)
message (FATAL_ERROR "LIBFLAME not found" )
endif ()
# Search libblis
find_library (LIBBLIS
NAMES blis
PATHS ${AOCLROOT}
PATH_SUFFIXES lib
NO_DEFAULT_PATH
)
if (NOT LIBBLIS)
message (FATAL_ERROR "LIBBLIS not found" )
endif ()
unset (LIBAOCL CACHE)
set (LIBAOCL ${LIBFLAME} ${LIBBLIS})
if (NOT LIBAOCL)
message (FATAL_ERROR
"AOCL library not found, please check that "
"the AOCLROOT variable is set and points to "
"a valid AOCL installation directory.")
endif ()
list (APPEND linalg_util_defs "_AOCL_")
set (LINALG_LIBRARIES ${LIBAOCL})
else ()
mark_as_advanced (FORCE AOCLROOT)
endif ()
# OpenBLAS
set (OPENBLASROOT "" CACHE PATH "OpenBLAS root directory.")
if (LINALG STREQUAL "OpenBLAS")
message ("-- Using OpenBLAS LAPACK+BLAS libraries")
# find out what OPENBLASROOT is
mark_as_advanced (CLEAR OPENBLASROOT)
if (OPENBLASROOT STREQUAL "")
set (OPENBLASROOT $ENV{OPENBLASROOT} CACHE PATH "OpenBLAS root directory." FORCE)
if (NOT OPENBLASROOT)
message (FATAL_ERROR
"You must set environment variable OPENBLASROOT, "
"or specify -DOPENBLASROOT=/path/to/openblas_dir "
"when running cmake.")
endif ()
endif ()
# at this point, OPENBLASROOT should be defined and not empty
message ("-- OPENBLASROOT = ${OPENBLASROOT}")
# here we check if OPENBLASROOT has changed after it was last used
# succesfully, if so then we need to reprocess the checks here.
if (NOT OPENBLASROOT STREQUAL OPENBLASROOT_LAST)
# we need to redo the library search later, because OPENBLASROOT
# changed since the last time we defined it.
unset (LIBOPENBLAS CACHE)
# check if the configuration header is available
set (OPENBLAS_CONFIG "${OPENBLASROOT}/include/openblas_config.h")
if (NOT EXISTS ${OPENBLAS_CONFIG})
# for system-wide OpenBLAS installations the config path might be different
# so try with an alternative path
set (OPENBLAS_CONFIG "${OPENBLASROOT}/include/openblas/openblas_config.h")
endif ()
if (NOT EXISTS ${OPENBLAS_CONFIG})
message (FATAL_ERROR
"Could not find OpenBLAS config header in: ${OPENBLASROOT} "
"(tried ${OPENBLASROOT}/include/openblas_config.h and "
"please check if the OPENBLASROOT variable points to a "
"valid OpenBLAS installation directory.")
endif ()
# check if the OpenBLAS installation was configured with 64bit integer support
message ("-- Checking OpenBLAS for 64-bit integer interface...")
include (CheckSymbolExists)
unset (OPENBLAS_WITH_ILP64 CACHE)
check_symbol_exists ("OPENBLAS_USE64BITINT" ${OPENBLAS_CONFIG} OPENBLAS_WITH_ILP64)
if (ADDRMODE EQUAL 64 AND NOT OPENBLAS_WITH_ILP64)
message (FATAL_ERROR
"OpenBLAS was not configured for 64-bit integer interface, "
"please build OpenBLAS with INTERFACE64=1 defined.")
endif ()
# save the last location to check if it changed between configurations
set (OPENBLASROOT_LAST ${OPENBLASROOT} CACHE INTERNAL "last value." FORCE)
endif ()
# search for the OpenBLAS library
find_library (LIBOPENBLAS
NAMES openblas
PATHS ${OPENBLASROOT}
PATH_SUFFIXES lib
NO_DEFAULT_PATH
)
if (NOT LIBOPENBLAS)
message (FATAL_ERROR
"OpenBLAS library not found, please check that "
"the OPENBLASROOT variable is set and points to "
"a valid OpenBLAS installation directory.")
endif ()
# here we check if LIBOPENBLAS has changed after it was processed
# succesfully, if not we do not need to rerun anything here.
if (NOT LIBOPENBLAS STREQUAL LIBOPENBLAS_LAST)
# check if the OpenBLAS library contains LAPACK functionality
message ("-- Checking OpenBLAS for LAPACK functionality...")