Skip to content

Commit 177fa66

Browse files
authored
CMake: Refactor feature build requirements into source/CMakeLists.txt (#7671)
* CMake: Refactor feature build requirements into source/CMakeLists.txt * Rename feature compile definitions (suggested by @ZhouXY-PKU) * Comment out ENABLE_EXX_DEV option
1 parent 085b91e commit 177fa66

76 files changed

Lines changed: 300 additions & 325 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 4 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ option(ENABLE_CNPY "Enable cnpy usage" OFF)
6868
cmake_dependent_option(ENABLE_ELPA "Enable ELPA for LCAO" ON "ENABLE_LCAO;ENABLE_MPI" OFF)
6969
cmake_dependent_option(ENABLE_LIBRI "Enable LibRI for hybrid functional"
7070
OFF "ENABLE_LCAO;ENABLE_MPI" OFF)
71-
cmake_dependent_option(ENABLE_EXX_DEV "Enable LibRI developing features" OFF "ENABLE_LIBRI" OFF)
7271
cmake_dependent_option(ENABLE_PEXSI "Enable PEXSI for LCAO" OFF "ENABLE_LCAO;ENABLE_MPI" OFF)
7372
cmake_dependent_option(ENABLE_MLALGO "Enable the machine learning algorithms"
7473
OFF "ENABLE_LCAO;ENABLE_MPI" OFF)
7574

75+
# EXX_DEV works with libRI PR#10 which is not merged into main branch; disabling it
76+
# cmake_dependent_option(ENABLE_EXX_DEV "Enable LibRI developing features" OFF "ENABLE_LIBRI" OFF)
77+
7678
# Two-center FFT is only used in LCAO
7779
cmake_dependent_option(ENABLE_FFT_TWO_CENTER "Enable FFT-based two-center integral method"
7880
ON "ENABLE_LCAO" OFF)
@@ -136,27 +138,6 @@ if(NOT DEFINED NVHPC_ROOT_DIR AND DEFINED ENV{NVHPC_ROOT})
136138
CACHE PATH "Path to NVIDIA HPC SDK root directory.")
137139
endif()
138140

139-
# Feature definitions are collected while options and dependencies are resolved
140-
# below. They are applied to targets in source/CMakeLists.txt.
141-
set_property(GLOBAL PROPERTY ABACUS_FEATURE_DEFINITIONS "")
142-
143-
function(abacus_normalize_definitions out_var)
144-
set(_defs)
145-
foreach(_def IN LISTS ARGN)
146-
if(_def MATCHES "^-D(.+)")
147-
list(APPEND _defs "${CMAKE_MATCH_1}")
148-
else()
149-
list(APPEND _defs "${_def}")
150-
endif()
151-
endforeach()
152-
set(${out_var} ${_defs} PARENT_SCOPE)
153-
endfunction()
154-
155-
function(abacus_add_feature_definitions)
156-
abacus_normalize_definitions(_defs ${ARGN})
157-
set_property(GLOBAL APPEND PROPERTY ABACUS_FEATURE_DEFINITIONS ${_defs})
158-
endfunction()
159-
160141
# enable json support
161142
if(ENABLE_RAPIDJSON)
162143
find_package(RapidJSON CONFIG REQUIRED)
@@ -167,7 +148,6 @@ if(ENABLE_RAPIDJSON)
167148
"Check if your RapidJSON installation provides a complete exported CMake configuration."
168149
)
169150
endif()
170-
abacus_add_feature_definitions(__RAPIDJSON)
171151
endif()
172152

173153
# get commit info
@@ -193,7 +173,6 @@ if(COMMIT_INFO)
193173
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
194174
RESULT_VARIABLE GIT_COMMIT_DATE_RESULT)
195175
if(GIT_COMMIT_HASH_RESULT EQUAL 0 AND GIT_COMMIT_DATE_RESULT EQUAL 0)
196-
abacus_add_feature_definitions(COMMIT_INFO)
197176
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/commit.h"
198177
"#define COMMIT \"${GIT_COMMIT_HASH} (${GIT_COMMIT_DATE})\"\n")
199178
set(ABACUS_COMMIT_INFO_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
@@ -272,14 +251,6 @@ if (USE_DSP)
272251
set(ABACUS_BIN_NAME abacus_dsp)
273252
endif()
274253

275-
if (USE_CUDA_ON_DCU)
276-
abacus_add_feature_definitions(__CUDA_ON_DCU)
277-
endif()
278-
279-
if (USE_CUDA_MPI)
280-
abacus_add_feature_definitions(__CUDA_MPI)
281-
endif()
282-
283254
list(APPEND CMAKE_MODULE_PATH
284255
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
285256
"${PROJECT_SOURCE_DIR}/cmake/modules")
@@ -359,45 +330,23 @@ if(CMAKE_CXX_COMPILER_ID MATCHES Intel)
359330
)
360331
endif()
361332

362-
if(ENABLE_ABACUS_LIBM)
363-
abacus_add_feature_definitions(__ABACUS_LIBM)
364-
endif()
365-
366333
if(ENABLE_NATIVE_OPTIMIZATION)
367334
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -mtune=native")
368335
endif()
369336

370-
# Windows (native build, e.g. MinGW-w64 or MSVC) portability defines:
371-
# _USE_MATH_DEFINES - expose M_PI and friends from <cmath>
372-
# NOMINMAX - stop <windows.h> defining min()/max() macros
373-
# _CRT_SECURE_NO_WARNINGS - silence CRT "use _s function" deprecations
374-
if(WIN32)
375-
abacus_add_feature_definitions(_USE_MATH_DEFINES NOMINMAX _CRT_SECURE_NO_WARNINGS)
376-
endif()
377-
378337
if(ENABLE_LCAO)
379-
abacus_add_feature_definitions(__LCAO)
380338
if(ENABLE_ELPA)
381339
find_package(ELPA REQUIRED)
382-
abacus_add_feature_definitions(__ELPA)
383-
endif()
384-
if(ENABLE_FFT_TWO_CENTER)
385-
abacus_add_feature_definitions(USE_NEW_TWO_CENTER)
386340
endif()
387341
if(ENABLE_PEXSI)
388342
find_package(PEXSI REQUIRED CONFIG)
389343
if(PEXSI_VERSION VERSION_LESS "2.0.0")
390344
message(FATAL_ERROR "PEXSI >= 2.0.0 is required")
391345
endif()
392-
abacus_add_feature_definitions(__PEXSI)
393346
set(CMAKE_CXX_STANDARD 14)
394347
endif()
395348
endif()
396349

397-
if(DEBUG_INFO)
398-
abacus_add_feature_definitions(__DEBUG)
399-
endif()
400-
401350
if(ENABLE_MPI)
402351
if(NOT CMAKE_CROSSCOMPILING)
403352
# FindMPI runs a probe executable to determine the MPI library version,
@@ -406,18 +355,9 @@ if(ENABLE_MPI)
406355
set(MPI_DETERMINE_LIBRARY_VERSION TRUE)
407356
endif()
408357
find_package(MPI COMPONENTS CXX REQUIRED)
409-
abacus_add_feature_definitions(__MPI)
410-
endif()
411-
412-
413-
if (USE_DSP)
414-
abacus_add_feature_definitions(__DSP)
415358
endif()
416359

417-
418-
419-
if (USE_SW)
420-
abacus_add_feature_definitions(__SW)
360+
if(USE_SW)
421361
set(SW ON)
422362
endif()
423363

@@ -440,10 +380,8 @@ if(USE_KML)
440380
endif()
441381

442382
find_package(KML REQUIRED COMPONENTS ${_kml_components})
443-
abacus_add_feature_definitions(__KML)
444383
elseif(MKLROOT OR MKL_ROOT)
445384
find_package(MKL REQUIRED)
446-
abacus_add_feature_definitions(__MKL)
447385
elseif(NOT USE_SW)
448386
find_package(Lapack REQUIRED)
449387
# ScaLAPACK is a distributed-memory library and is only needed for the
@@ -538,16 +476,13 @@ if(USE_CUDA)
538476
endif()
539477
enable_language(CUDA)
540478
if(USE_CUDA)
541-
abacus_add_feature_definitions(__CUDA)
542-
abacus_add_feature_definitions(__UT_USE_CUDA)
543479
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
544480
set(CMAKE_CUDA_FLAGS_DEBUG "${CMAKE_CUDA_FLAGS_DEBUG} -g -G" CACHE STRING "CUDA flags for debug build" FORCE)
545481
endif()
546482
if (ENABLE_OPENMP AND OpenMP_CXX_FOUND)
547483
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler=${OpenMP_CXX_FLAGS}" CACHE STRING "CUDA flags" FORCE)
548484
endif()
549485
if (ENABLE_NCCL_PARALLEL_DEVICE)
550-
abacus_add_feature_definitions(__NCCL_PARALLEL_DEVICE)
551486
include(cmake/modules/SetupNccl.cmake)
552487
abacus_setup_nccl()
553488
endif()
@@ -616,9 +551,6 @@ if(USE_ROCM)
616551
)
617552
endif()
618553

619-
abacus_add_feature_definitions(__ROCM)
620-
abacus_add_feature_definitions(__UT_USE_ROCM)
621-
abacus_add_feature_definitions(__HIP_PLATFORM_HCC__)
622554
endif()
623555

624556
if(ENABLE_ASAN)
@@ -632,10 +564,6 @@ if(ENABLE_ASAN)
632564
add_link_options(-fsanitize=address)
633565
endif()
634566

635-
if(ENABLE_FLOAT_FFTW)
636-
abacus_add_feature_definitions(__ENABLE_FLOAT_FFTW)
637-
endif()
638-
639567
if(ENABLE_MLALGO)
640568
find_path(libnpy_SOURCE_DIR npy.hpp HINTS ${libnpy_INCLUDE_DIR})
641569
if(NOT libnpy_SOURCE_DIR)
@@ -648,8 +576,6 @@ if(ENABLE_MLALGO)
648576
FetchContent_MakeAvailable(libnpy)
649577
else()
650578
endif()
651-
652-
abacus_add_feature_definitions(__MLALGO)
653579
endif()
654580

655581
# Torch uses outdated components to detect CUDA arch, causing failure on
@@ -683,7 +609,6 @@ if (ENABLE_CNPY)
683609

684610
# find ZLIB and link
685611
find_package(ZLIB REQUIRED)
686-
abacus_add_feature_definitions(__USECNPY)
687612
endif()
688613

689614
function(git_submodule_update)
@@ -714,47 +639,29 @@ if(ENABLE_LIBRI)
714639
find_package(LibRI REQUIRED)
715640
find_package(LibComm REQUIRED)
716641
find_package(cereal REQUIRED CONFIG)
717-
abacus_add_feature_definitions(__EXX EXX_DM=3 EXX_H_COMM=2 TEST_EXX_LCAO=0
718-
TEST_EXX_RADIAL=1)
719-
if(ENABLE_EXX_DEV)
720-
abacus_add_feature_definitions(__EXX_DEV)
721-
endif()
722642
endif()
723643

724644
if(ENABLE_LIBXC)
725645
find_package(Libxc CONFIG REQUIRED)
726646
if(Libxc_VERSION VERSION_LESS "5.1.7")
727647
message(FATAL_ERROR "Libxc >= 5.1.7 is required")
728648
endif()
729-
abacus_add_feature_definitions(USE_LIBXC)
730649
endif()
731650

732651
if(DEFINED DeePMD_DIR)
733-
abacus_add_feature_definitions(__DPMD HIGH_PREC)
734-
add_compile_options(-Wl,--no-as-needed)
735652
find_package(DeePMD REQUIRED)
736-
if(DeePMDC_FOUND)
737-
abacus_add_feature_definitions(__DPMDC)
738-
endif()
739653
endif()
740654

741655
if(DEFINED NEP_DIR)
742656
find_package(NEP REQUIRED)
743-
744-
if(NEP_FOUND)
745-
abacus_add_feature_definitions(__NEP)
746-
endif()
747657
endif()
748658

749659
if(DEFINED TensorFlow_DIR)
750660
find_package(TensorFlow REQUIRED)
751661
endif()
752662

753-
abacus_add_feature_definitions(__FFTW3 __SELINV METIS)
754-
755663
if(MATH_INFO)
756664
message(STATUS "Will gather math lib info.")
757-
abacus_add_feature_definitions(GATHER_INFO)
758665
# modifications on blas_connector and lapack_connector
759666
endif()
760667

0 commit comments

Comments
 (0)