forked from deepmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
779 lines (689 loc) · 24.7 KB
/
Copy pathCMakeLists.txt
File metadata and controls
779 lines (689 loc) · 24.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
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
# ==============================================================================
# External dependency interfaces
# ==============================================================================
#
# This file is the only place where ABACUS target linkage is assembled. The
# top-level CMakeLists.txt resolves options and packages but deliberately does
# not construct or link ABACUS targets.
#
# Link order is part of the build contract. Static linkers resolve archives
# from left to right, so every consumer must precede the provider of its
# unresolved symbols. Keep the final link closure ordered as follows:
#
# 1. ABACUS internal targets, from high-level consumers to lower-level
# providers;
# 2. optional external feature libraries used by those internal targets;
# 3. numerical backends and their MPI, OpenMP, compiler-runtime, and system
# dependencies.
#
# Do not sort or globally deduplicate this closure. A package target must carry
# its own transitive requirements in INTERFACE_LINK_LIBRARIES. Cyclic static
# archives must be handled locally by the corresponding package target or
# adapter rather than by wrapping the entire ABACUS link line in a linker group.
# This target intentionally carries compile usage requirements only. It must
# not link an external library: internal object libraries and unit tests consume
# it for headers, flags, and definitions, while the final executable owns the
# complete link closure below.
add_library(abacus_compile_requirements INTERFACE)
add_library(abacus::compile_requirements ALIAS abacus_compile_requirements)
include(CompilerConfiguration)
set(_abacus_feature_definitions
__FFTW3
$<$<BOOL:${ENABLE_RAPIDJSON}>:__RAPIDJSON>
$<$<BOOL:${USE_CUDA_ON_DCU}>:__CUDA_ON_DCU>
$<$<BOOL:${USE_CUDA_MPI}>:__CUDA_MPI>
$<$<BOOL:${ENABLE_ABACUS_LIBM}>:__ABACUS_LIBM>
$<$<BOOL:${WIN32}>:_USE_MATH_DEFINES>
$<$<BOOL:${WIN32}>:NOMINMAX>
$<$<BOOL:${WIN32}>:_CRT_SECURE_NO_WARNINGS>
$<$<BOOL:${ENABLE_LCAO}>:__LCAO>
$<$<BOOL:${ENABLE_ELPA}>:__ELPA>
$<$<BOOL:${ENABLE_FFT_TWO_CENTER}>:__FFT_TWO_CENTER>
$<$<BOOL:${ENABLE_PEXSI}>:__PEXSI>
$<$<BOOL:${DEBUG_INFO}>:__DEBUG>
$<$<BOOL:${ENABLE_MPI}>:__MPI>
$<$<BOOL:${USE_DSP}>:__DSP>
$<$<BOOL:${USE_SW}>:__SW>
$<$<BOOL:${USE_KML}>:__KML>
$<$<AND:$<NOT:$<BOOL:${USE_KML}>>,$<BOOL:${MKL_FOUND}>>:__MKL>
$<$<BOOL:${USE_CUDA}>:__CUDA>
$<$<BOOL:${USE_CUDA}>:__UT_USE_CUDA>
$<$<BOOL:${ENABLE_NCCL_PARALLEL_DEVICE}>:__NCCL_PARALLEL_DEVICE>
$<$<BOOL:${ENABLE_CUSOLVERMP}>:__CUSOLVERMP>
$<$<BOOL:${ENABLE_CUBLASMP}>:__CUBLASMP>
$<$<BOOL:${_use_cal}>:__USE_CAL>
$<$<BOOL:${USE_ROCM}>:__ROCM>
$<$<BOOL:${USE_ROCM}>:__UT_USE_ROCM>
$<$<BOOL:${USE_ROCM}>:__HIP_PLATFORM_HCC__>
$<$<BOOL:${ENABLE_FLOAT_FFTW}>:__FLOAT_FFTW>
$<$<BOOL:${ENABLE_MLALGO}>:__MLALGO>
$<$<BOOL:${ENABLE_CNPY}>:__CNPY>
$<$<BOOL:${ENABLE_LIBRI}>:__EXX>
$<$<BOOL:${ENABLE_LIBRI}>:EXX_DM=3>
$<$<BOOL:${ENABLE_LIBRI}>:EXX_H_COMM=2>
$<$<BOOL:${ENABLE_LIBRI}>:TEST_EXX_LCAO=0>
$<$<BOOL:${ENABLE_LIBRI}>:TEST_EXX_RADIAL=1>
$<$<BOOL:${ENABLE_EXX_DEV}>:__EXX_DEV>
$<$<BOOL:${ENABLE_LIBXC}>:__LIBXC>
$<$<BOOL:${ENABLE_DFTD4}>:__DFTD4>
$<$<BOOL:${MATH_INFO}>:GATHER_INFO>)
if(ABACUS_COMMIT_INFO_INCLUDE_DIR)
list(APPEND _abacus_feature_definitions COMMIT_INFO)
endif()
if(DEFINED DeePMD_DIR)
list(APPEND _abacus_feature_definitions __DPMD HIGH_PREC)
if(DeePMDC_FOUND)
list(APPEND _abacus_feature_definitions __DPMDC)
endif()
endif()
if(DEFINED NEP_DIR AND NEP_FOUND)
list(APPEND _abacus_feature_definitions __NEP)
endif()
target_include_directories(abacus_compile_requirements INTERFACE
${ABACUS_SOURCE_DIR}
${ABACUS_SOURCE_DIR}/source_base/module_container)
if(ABACUS_COMMIT_INFO_INCLUDE_DIR)
target_include_directories(abacus_compile_requirements INTERFACE
${ABACUS_COMMIT_INFO_INCLUDE_DIR})
endif()
function(abacus_add_target_compile_requirements target)
if(NOT TARGET "${target}")
return()
endif()
get_target_property(_include_dirs "${target}" INTERFACE_INCLUDE_DIRECTORIES)
if(_include_dirs)
target_include_directories(abacus_compile_requirements INTERFACE
${_include_dirs})
endif()
get_target_property(_system_include_dirs "${target}" INTERFACE_SYSTEM_INCLUDE_DIRECTORIES)
if(_system_include_dirs)
target_include_directories(abacus_compile_requirements SYSTEM INTERFACE
${_system_include_dirs})
endif()
get_target_property(_compile_definitions "${target}" INTERFACE_COMPILE_DEFINITIONS)
if(_compile_definitions)
target_compile_definitions(abacus_compile_requirements INTERFACE
${_compile_definitions})
endif()
get_target_property(_compile_options "${target}" INTERFACE_COMPILE_OPTIONS)
if(_compile_options)
target_compile_options(abacus_compile_requirements INTERFACE
${_compile_options})
endif()
get_target_property(_compile_features "${target}" INTERFACE_COMPILE_FEATURES)
if(_compile_features)
target_compile_features(abacus_compile_requirements INTERFACE
${_compile_features})
endif()
endfunction()
add_library(abacus_linalg_libs INTERFACE)
add_library(abacus::linalg_libs ALIAS abacus_linalg_libs)
add_library(abacus_feature_libs INTERFACE)
add_library(abacus::feature_libs ALIAS abacus_feature_libs)
add_library(abacus_link_libs INTERFACE)
add_library(abacus::link_libs ALIAS abacus_link_libs)
target_link_libraries(abacus_link_libs INTERFACE
abacus::feature_libs
abacus::linalg_libs)
# ------------------------------------------------------------------------------
# Ordered numerical backends and runtime closure
# ------------------------------------------------------------------------------
set(_abacus_linalg_libs)
set(_abacus_linalg_include_dirs)
if(USE_KML)
if(ENABLE_MPI)
list(APPEND _abacus_linalg_libs KML::ScaLAPACK)
else()
list(APPEND _abacus_linalg_libs KML::LAPACK)
endif()
list(APPEND _abacus_linalg_libs KML::FFTW3)
list(APPEND _abacus_linalg_include_dirs ${KML_INCLUDE_DIRS})
if(ENABLE_FLOAT_FFTW)
list(APPEND _abacus_linalg_libs KML::FFTW3_FLOAT)
endif()
elseif(MKL_FOUND)
list(APPEND _abacus_linalg_libs ${MKL_LIBRARIES})
if(CMAKE_CXX_COMPILER_ID MATCHES Intel)
list(APPEND _abacus_linalg_libs ifcore)
endif()
elseif(USE_SW)
list(APPEND _abacus_linalg_include_dirs
${SW_MATH}/include
${SW_FFT}/include)
list(APPEND _abacus_linalg_libs
${SW_FFT}/lib/libfftw3.a
${SW_MATH}/libswfft.a
${SW_MATH}/libswscalapack.a
${SW_MATH}/libswlapack.a
${SW_MATH}/libswblas.a
gfortran)
else()
if(ENABLE_MPI)
list(APPEND _abacus_linalg_libs ScaLAPACK::ScaLAPACK)
endif()
if(ENABLE_OPENMP)
list(APPEND _abacus_linalg_libs FFTW3::FFTW3_OMP)
endif()
list(APPEND _abacus_linalg_libs
FFTW3::FFTW3
LAPACK::LAPACK
BLAS::BLAS)
list(APPEND _abacus_linalg_include_dirs ${FFTW3_INCLUDE_DIRS})
if(ENABLE_FLOAT_FFTW)
list(APPEND _abacus_linalg_libs FFTW3::FFTW3_FLOAT)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
list(APPEND _abacus_linalg_libs gfortran)
elseif(CMAKE_CXX_COMPILER_ID MATCHES Intel)
list(APPEND _abacus_linalg_libs ifcore)
endif()
endif()
if(ENABLE_MPI)
list(APPEND _abacus_linalg_libs MPI::MPI_CXX)
endif()
if(ENABLE_OPENMP)
list(APPEND _abacus_linalg_libs OpenMP::OpenMP_CXX)
endif()
list(APPEND _abacus_linalg_libs Threads::Threads)
# libm exists on Linux and MinGW-w64 but not in the MSVC CRT.
if(NOT MSVC)
list(APPEND _abacus_linalg_libs m)
endif()
target_link_libraries(abacus_linalg_libs INTERFACE ${_abacus_linalg_libs})
target_include_directories(abacus_linalg_libs INTERFACE ${_abacus_linalg_include_dirs})
target_include_directories(abacus_compile_requirements INTERFACE
${_abacus_linalg_include_dirs})
foreach(_abacus_linalg_target IN ITEMS
Threads::Threads
MPI::MPI_CXX
OpenMP::OpenMP_CXX
FFTW3::FFTW3
FFTW3::FFTW3_OMP
FFTW3::FFTW3_FLOAT
KML::LAPACK
KML::ScaLAPACK
KML::FFTW3
KML::FFTW3_FLOAT)
abacus_add_target_compile_requirements(${_abacus_linalg_target})
endforeach()
if(MKL_FOUND)
abacus_add_target_compile_requirements("${MKL_LIBRARIES}")
endif()
# ------------------------------------------------------------------------------
# Optional external feature libraries
# ------------------------------------------------------------------------------
set(_abacus_feature_libs
$<$<BOOL:${ENABLE_RAPIDJSON}>:RapidJSON>
$<$<BOOL:${ENABLE_ELPA}>:ELPA::ELPA>
$<$<BOOL:${ENABLE_PEXSI}>:PEXSI::PEXSI>
$<$<BOOL:${ENABLE_CNPY}>:cnpy>
$<$<BOOL:${ENABLE_CNPY}>:ZLIB::ZLIB>
$<$<BOOL:${ENABLE_LIBRI}>:cereal::cereal>
$<$<BOOL:${ENABLE_LIBXC}>:Libxc::xc>)
set(_abacus_feature_include_dirs)
set(_abacus_feature_compile_options)
if(ENABLE_ELPA)
list(APPEND _abacus_feature_include_dirs ${ELPA_INCLUDE_DIR})
endif()
if(ENABLE_MLALGO)
if(libnpy_INCLUDE_DIR)
list(APPEND _abacus_feature_include_dirs ${libnpy_INCLUDE_DIR})
endif()
if(libnpy_SOURCE_DIR)
list(APPEND _abacus_feature_include_dirs ${libnpy_SOURCE_DIR}/include)
endif()
endif()
if(ENABLE_MLALGO OR DEFINED Torch_DIR)
list(APPEND _abacus_feature_include_dirs ${TORCH_INCLUDE_DIRS})
list(APPEND _abacus_feature_compile_options ${ABACUS_TORCH_CXX_FLAGS})
endif()
if(ENABLE_CNPY)
if(cnpy_INCLUDE_DIR)
list(APPEND _abacus_feature_include_dirs ${cnpy_INCLUDE_DIR})
endif()
if(cnpy_SOURCE_DIR)
list(APPEND _abacus_feature_include_dirs ${cnpy_SOURCE_DIR})
endif()
endif()
if(ENABLE_LIBRI)
list(APPEND _abacus_feature_include_dirs
${LIBRI_DIR}/include
${LIBCOMM_DIR}/include)
endif()
if(DEFINED DeePMD_DIR)
if(DeePMDC_FOUND)
list(APPEND _abacus_feature_libs DeePMD::deepmd_c)
else()
list(APPEND _abacus_feature_libs DeePMD::deepmd_cc)
endif()
list(APPEND _abacus_feature_include_dirs ${DeePMD_DIR}/include)
endif()
if(DEFINED NEP_DIR AND NEP_FOUND)
list(APPEND _abacus_feature_libs NEP::nep)
endif()
if(DEFINED TensorFlow_DIR AND TensorFlow_FOUND)
list(APPEND _abacus_feature_libs TensorFlow::tensorflow_cc)
list(APPEND _abacus_feature_include_dirs ${TensorFlow_DIR}/include)
endif()
if(USE_DSP)
list(APPEND _abacus_feature_libs
${OMPI_LIBRARY1}
${MT_HOST_DIR}/hthreads/lib/libhthread_device.a
${MT_HOST_DIR}/hthreads/lib/libhthread_host.a)
list(APPEND _abacus_feature_include_dirs
${MTBLAS_FFT_DIR}/libmtblas/include
${MT_HOST_DIR}/include)
endif()
if(USE_CUDA)
if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 12.9)
list(APPEND _abacus_feature_libs cudart)
else()
list(APPEND _abacus_feature_libs cudart nvToolsExt)
endif()
list(APPEND _abacus_feature_include_dirs ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 13.0
AND EXISTS "${CUDAToolkit_ROOT}/include/cccl")
list(APPEND _abacus_feature_include_dirs "${CUDAToolkit_ROOT}/include/cccl")
endif()
if(ENABLE_NCCL_PARALLEL_DEVICE)
list(APPEND _abacus_feature_libs NCCL::NCCL)
endif()
if(ENABLE_CUSOLVERMP)
if(_use_cal)
list(APPEND _abacus_feature_libs CAL::CAL cusolverMp::cusolverMp)
else()
list(APPEND _abacus_feature_libs NCCL::NCCL cusolverMp::cusolverMp)
endif()
endif()
if(ENABLE_CUBLASMP)
list(APPEND _abacus_feature_libs cublasMp::cublasMp)
endif()
endif()
if(USE_ROCM)
list(APPEND _abacus_feature_libs
hip::host
hip::device
hip::hipfft
roc::hipblas
roc::hipsolver)
list(APPEND _abacus_feature_include_dirs ${ROCM_PATH}/include)
endif()
if(ENABLE_ASAN)
list(APPEND _abacus_feature_libs -fsanitize=address)
endif()
target_link_libraries(abacus_feature_libs INTERFACE ${_abacus_feature_libs})
if(DEFINED DeePMD_DIR AND UNIX AND NOT APPLE)
target_link_options(abacus_feature_libs INTERFACE "LINKER:--no-as-needed")
endif()
target_include_directories(abacus_compile_requirements INTERFACE
${_abacus_feature_include_dirs})
target_compile_options(abacus_compile_requirements INTERFACE
${_abacus_feature_compile_options})
foreach(_abacus_feature_target IN ITEMS
RapidJSON
cereal::cereal
ELPA::ELPA
Libxc::xc
dftd4::dftd4
DeePMD::deepmd_c
DeePMD::deepmd_cc
NEP::nep
TensorFlow::tensorflow_cc
ZLIB::ZLIB
PEXSI::PEXSI
NCCL::NCCL
CAL::CAL
cusolverMp::cusolverMp
cublasMp::cublasMp
hip::host
hip::device
hip::hipfft
roc::hipblas
roc::hipsolver)
abacus_add_target_compile_requirements(${_abacus_feature_target})
endforeach()
# ------------------------------------------------------------------------------
# Per-target feature definitions and common compile usage requirements
# ------------------------------------------------------------------------------
function(abacus_normalize_definitions out_var)
set(_defs)
foreach(_def IN LISTS ARGN)
if(_def MATCHES "^-D(.+)")
list(APPEND _defs "${CMAKE_MATCH_1}")
else()
list(APPEND _defs "${_def}")
endif()
endforeach()
set(${out_var} ${_defs} PARENT_SCOPE)
endfunction()
define_property(
DIRECTORY
PROPERTY ABACUS_DISABLED_FEATURE_DEFINITIONS
INHERITED
BRIEF_DOCS "ABACUS feature definitions disabled for targets in this directory"
FULL_DOCS "Feature definitions disabled for targets created in this directory.")
define_property(
DIRECTORY
PROPERTY ABACUS_LOCAL_FEATURE_DEFINITIONS
INHERITED
BRIEF_DOCS "Additional ABACUS feature definitions for targets in this directory"
FULL_DOCS "Additional feature definitions for targets created in this directory.")
define_property(
TARGET
PROPERTY ABACUS_KEPT_FEATURE_DEFINITIONS
BRIEF_DOCS "Feature definitions this target keeps despite a directory-level disable"
FULL_DOCS "Feature definitions that must not be stripped from this target even "
"when its source directory disables them via "
"abacus_disable_feature_definitions(). Used by tests that genuinely need a "
"feature (e.g. __MPI) inside a directory that otherwise disables it.")
function(abacus_disable_feature_definitions)
abacus_normalize_definitions(_defs ${ARGN})
set_property(DIRECTORY APPEND PROPERTY
ABACUS_DISABLED_FEATURE_DEFINITIONS ${_defs})
endfunction()
function(abacus_add_local_feature_definitions)
abacus_normalize_definitions(_defs ${ARGN})
set_property(DIRECTORY APPEND PROPERTY
ABACUS_LOCAL_FEATURE_DEFINITIONS ${_defs})
endfunction()
function(abacus_apply_build_options target)
if(NOT TARGET "${target}")
return()
endif()
get_target_property(_type "${target}" TYPE)
if(_type STREQUAL "INTERFACE_LIBRARY" OR _type STREQUAL "UTILITY")
return()
endif()
get_target_property(_imported "${target}" IMPORTED)
if(_imported)
return()
endif()
get_target_property(_source_dir "${target}" SOURCE_DIR)
set(_defs "${_abacus_feature_definitions}")
get_property(_disabled DIRECTORY "${_source_dir}" PROPERTY ABACUS_DISABLED_FEATURE_DEFINITIONS)
get_property(_local DIRECTORY "${_source_dir}" PROPERTY ABACUS_LOCAL_FEATURE_DEFINITIONS)
get_target_property(_kept "${target}" ABACUS_KEPT_FEATURE_DEFINITIONS)
if(_kept)
# A target may opt back into definitions its directory disables.
list(REMOVE_ITEM _disabled ${_kept})
endif()
if(_disabled)
# Filter after conditional definitions have been evaluated.
string(JOIN "|" _disabled_regex ${_disabled})
set(_defs "$<FILTER:${_defs},EXCLUDE,^(${_disabled_regex})$>")
endif()
if(_local)
list(APPEND _defs ${_local})
endif()
if(_defs)
target_compile_definitions("${target}" PRIVATE
"$<REMOVE_DUPLICATES:${_defs}>")
endif()
target_link_libraries("${target}" PRIVATE abacus::compile_requirements)
endfunction()
function(abacus_apply_build_options_to_dir dir)
# FetchContent adds third-party projects as subdirectories of its caller.
# Keep the recursive application strictly within ABACUS's own source tree so
# exported third-party targets never acquire ABACUS compile requirements.
set(_abacus_source_root "${PROJECT_SOURCE_DIR}/source/")
string(FIND "${dir}/" "${_abacus_source_root}" _abacus_source_pos)
if(NOT _abacus_source_pos EQUAL 0)
return()
endif()
get_property(_targets DIRECTORY "${dir}" PROPERTY BUILDSYSTEM_TARGETS)
foreach(_target IN LISTS _targets)
abacus_apply_build_options("${_target}")
endforeach()
get_property(_subdirs DIRECTORY "${dir}" PROPERTY SUBDIRECTORIES)
foreach(_subdir IN LISTS _subdirs)
abacus_apply_build_options_to_dir("${_subdir}")
endforeach()
endfunction()
# ==============================================================================
# Executable, source tree, and tests
# ==============================================================================
set(ABACUS_TEST_DIR "${PROJECT_SOURCE_DIR}/tests")
include(${PROJECT_SOURCE_DIR}/cmake/Testing.cmake)
add_executable(${ABACUS_BIN_NAME} source_main/main.cpp)
set_target_properties(
${ABACUS_BIN_NAME}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(ABACUS_BIN_PATH ${PROJECT_BINARY_DIR}/${ABACUS_BIN_NAME})
if(USE_CUDA)
set_property(TARGET ${ABACUS_BIN_NAME}
PROPERTY CUDA_ARCHITECTURES ${CMAKE_CUDA_ARCHITECTURES})
target_compile_definitions(${ABACUS_BIN_NAME} PRIVATE __USE_NVTX)
endif()
if(ENABLE_COVERAGE)
add_coverage(${ABACUS_BIN_NAME})
endif()
include(${PROJECT_SOURCE_DIR}/cmake/BuildInfo.cmake)
setup_build_info()
add_subdirectory(source_base)
add_subdirectory(source_cell)
add_subdirectory(source_psi)
add_subdirectory(source_estate)
add_subdirectory(source_hamilt)
add_subdirectory(source_pw)
add_subdirectory(source_lcao)
add_subdirectory(source_hsolver)
add_subdirectory(source_basis/module_ao)
add_subdirectory(source_basis/module_nao)
add_subdirectory(source_md)
add_subdirectory(source_basis/module_pw)
add_subdirectory(source_esolver)
add_subdirectory(source_io)
add_subdirectory(source_relax)
add_subdirectory(source_lcao/module_ri)
add_subdirectory(source_io/module_parameter)
add_subdirectory(source_lcao/module_lr)
add_subdirectory(source_lcao/module_rdmft) # add by jghan
add_library(
driver
OBJECT
source_main/driver.cpp
source_main/driver_run.cpp)
list(APPEND device_srcs
source_pw/module_pwdft/kernels/nonlocal_op.cpp
source_pw/module_pwdft/kernels/veff_op.cpp
source_pw/module_pwdft/kernels/ekinetic_op.cpp
source_pw/module_pwdft/kernels/meta_op.cpp
source_pw/module_stodft/kernels/hpsi_norm_op.cpp
source_basis/module_pw/kernels/pw_op.cpp
source_hsolver/kernels/hegvd_op.cpp
source_hsolver/kernels/bpcg_kernel_op.cpp
source_estate/kernels/elecstate_op.cpp
source_base/module_device/device.cpp
source_base/module_device/device_helpers.cpp
source_base/module_device/output_device.cpp
source_base/module_device/memory_op.cpp
source_base/kernels/math_kernel_op.cpp
source_base/kernels/math_kernel_op_vec.cpp
source_pw/module_pwdft/kernels/force_op.cpp
source_pw/module_pwdft/kernels/stress_op.cpp
source_pw/module_pwdft/kernels/onsite_op.cpp
source_pw/module_pwdft/kernels/wf_op.cpp
source_pw/module_pwdft/kernels/vnl_op.cpp
source_base/kernels/math_ylm_op.cpp
source_hamilt/module_xc/kernels/xc_functional_op.cpp
source_pw/module_pwdft/kernels/cal_density_real_op.cpp
source_pw/module_pwdft/kernels/mul_potential_op.cpp
source_pw/module_pwdft/kernels/vec_mul_cx_op.cpp
source_pw/module_pwdft/kernels/exx_cal_energy_op.cpp)
if(USE_CUDA)
list(APPEND device_srcs
source_pw/module_pwdft/kernels/cuda/nonlocal_op.cu
source_pw/module_pwdft/kernels/cuda/veff_op.cu
source_pw/module_pwdft/kernels/cuda/ekinetic_op.cu
source_pw/module_pwdft/kernels/cuda/meta_op.cu
source_pw/module_stodft/kernels/cuda/hpsi_norm_op.cu
source_pw/module_pwdft/kernels/cuda/onsite_op.cu
source_basis/module_pw/kernels/cuda/pw_op.cu
source_hsolver/kernels/cuda/hegvd_op.cu
source_hsolver/kernels/cuda/bpcg_kernel_op.cu
source_estate/kernels/cuda/elecstate_op.cu
source_base/module_device/cuda/memory_op.cu
source_pw/module_pwdft/kernels/cuda/force_op.cu
source_pw/module_pwdft/kernels/cuda/stress_op.cu
source_pw/module_pwdft/kernels/cuda/wf_op.cu
source_pw/module_pwdft/kernels/cuda/vnl_op.cu
source_base/module_device/cuda_compat.cpp
source_base/kernels/cuda/math_ylm_op.cu
source_base/kernels/cuda/math_kernel_op.cu
source_base/kernels/cuda/math_kernel_op_vec.cu
source_hamilt/module_xc/kernels/cuda/xc_functional_op.cu
source_pw/module_ofdft/kernels/cuda/kedf_wt_gpu.cu
source_pw/module_pwdft/kernels/cuda/cal_density_real_op.cu
source_pw/module_pwdft/kernels/cuda/mul_potential_op.cu
source_pw/module_pwdft/kernels/cuda/vec_mul_vec_complex.cu
source_pw/module_pwdft/kernels/cuda/exx_cal_energy_op.cu)
endif()
if(USE_ROCM)
hip_add_library(device_rocm STATIC
source_pw/module_pwdft/kernels/rocm/nonlocal_op.hip.cu
source_pw/module_pwdft/kernels/rocm/veff_op.hip.cu
source_pw/module_pwdft/kernels/rocm/ekinetic_op.hip.cu
source_pw/module_pwdft/kernels/rocm/meta_op.hip.cu
source_pw/module_pwdft/kernels/rocm/onsite_op.hip.cu
source_pw/module_stodft/kernels/rocm/hpsi_norm_op.hip.cu
source_basis/module_pw/kernels/rocm/pw_op.hip.cu
source_hsolver/kernels/rocm/hegvd_op.hip.cu
source_hsolver/kernels/rocm/bpcg_kernel_op.hip.cu
source_estate/kernels/rocm/elecstate_op.hip.cu
source_base/module_device/rocm/memory_op.hip.cu
source_pw/module_pwdft/kernels/rocm/force_op.hip.cu
source_pw/module_pwdft/kernels/rocm/stress_op.hip.cu
source_pw/module_pwdft/kernels/rocm/wf_op.hip.cu
source_pw/module_pwdft/kernels/rocm/vnl_op.hip.cu
source_base/kernels/rocm/math_kernel_op.hip.cu
source_base/kernels/rocm/math_kernel_op_vec.hip.cu
source_base/kernels/rocm/math_ylm_op.hip.cu
source_hamilt/module_xc/kernels/rocm/xc_functional_op.hip.cu)
endif()
if(USE_DSP)
list(APPEND device_srcs
source_base/kernels/dsp/dsp_connector.cpp)
endif()
add_library(device OBJECT ${device_srcs})
if(USE_CUDA)
target_link_libraries(device PRIVATE cusolver cublas cufft)
elseif(USE_ROCM)
target_link_libraries(device PRIVATE
device_rocm
hip::host
hip::device
hip::hipfft
roc::hipblas
roc::hipsolver)
endif()
# base uses symbols from device (memory_op and math_ylm_op).
target_link_libraries(base PUBLIC device)
if(ENABLE_COVERAGE)
add_coverage(driver)
endif()
# ==============================================================================
# Final link closure and ordering
# ==============================================================================
target_link_libraries(
${ABACUS_BIN_NAME}
PRIVATE
# Internal ABACUS targets: consumers before providers.
driver
esolver
hsolver
hamilt_general
elecstate
module_pwdft
module_ofdft
module_stodft
module_dfpt
xc_
vdw
relax
io_advanced
io_basic
io_input
surchem
neighbor_search
neighbor
md
planewave
symmetry
cell
parameter
psi_overall_init
psi_init
psi
dftu
deltaspin
container
device
base)
if(ENABLE_ELPA)
target_link_libraries(${ABACUS_BIN_NAME} PRIVATE genelpa)
endif()
if(ENABLE_LCAO)
target_link_libraries(
${ABACUS_BIN_NAME}
PRIVATE
hamilt_lcao
tddft
orb
gint
hcontainer
numerical_atomic_orbitals
lr
rdmft)
if(ENABLE_LIBRI)
target_link_libraries(${ABACUS_BIN_NAME} PRIVATE bse)
endif()
if(ENABLE_PEXSI)
target_link_libraries(${ABACUS_BIN_NAME} PRIVATE pexsi)
endif()
if(USE_CUDA)
target_link_libraries(${ABACUS_BIN_NAME} PRIVATE diag_cusolver)
endif()
endif()
if(ENABLE_MLALGO)
target_link_libraries(${ABACUS_BIN_NAME} PRIVATE deepks hamilt_mlkedf)
endif()
if(ENABLE_LIBRI)
target_link_libraries(${ABACUS_BIN_NAME} PRIVATE ri module_exx_symmetry)
endif()
if(ENABLE_RAPIDJSON)
target_link_libraries(${ABACUS_BIN_NAME} PRIVATE json_output)
endif()
# External closure: feature consumers precede numerical providers and runtimes.
target_link_libraries(${ABACUS_BIN_NAME} PRIVATE abacus::link_libs)
# Torch includes some LAPACK routines, but with floating-point exceptions.
if(ENABLE_MLALGO OR DEFINED Torch_DIR)
target_link_libraries(${ABACUS_BIN_NAME} PRIVATE ${TORCH_LIBRARIES})
endif()
# Apply feature definitions and common compile usage requirements only after all
# source targets have been created.
abacus_apply_build_options_to_dir("${CMAKE_CURRENT_SOURCE_DIR}")
abacus_apply_build_options(${ABACUS_BIN_NAME})
# Register integration tests only after the final executable and its path are
# available. Unit tests are added by source subdirectories through AddTest().
if(BUILD_TESTING)
add_subdirectory("${ABACUS_TEST_DIR}" "${PROJECT_BINARY_DIR}/tests")
endif()
install(PROGRAMS ${ABACUS_BIN_PATH} TYPE BIN)
# Create a symbolic link 'abacus' pointing to the actual executable. Skipped on
# Windows because symlink creation needs elevated/developer-mode privileges and
# the executable carries an .exe suffix anyway.
if(NOT WIN32)
install(
CODE "
execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink
${ABACUS_BIN_NAME}
${CMAKE_INSTALL_PREFIX}/bin/abacus
WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin
COMMAND_ERROR_IS_FATAL ANY)
")
endif()
if(ENABLE_COVERAGE)
coverage_evaluate()
endif()