11cmake_minimum_required (VERSION 3.16 )
2+
3+ # Require out-of-source builds
4+ file (TO_CMAKE_PATH "${CMAKE_BINARY_DIR } /CMakeLists.txt" LOC_PATH )
5+ if (EXISTS "${LOC_PATH} " )
6+ message (
7+ FATAL_ERROR
8+ "You cannot build in a source directory (or any directory with a CMakeLists.txt file). "
9+ "Please make a build subdirectory." )
10+ endif ()
11+
12+ include (CMakeDependentOption )
13+ message (WARNING
14+ "The build system now uses cmake_dependent_option extensively.\n "
15+ "Many advanced options are now conditionally enabled based on their dependencies; "
16+ "when dependency conditions are not met, the corresponding options will be"
17+ "automatically turned OFF and hidden in cmake-gui/ccmake.\n "
18+ "Please review your configuration if you previously set these options manually."
19+ )
20+
221if (POLICY CMP0135) # https://cmake.org/cmake/help/git-stage/policy/CMP0135.html
322 cmake_policy (SET CMP0135 NEW )
423 # Otherwise this policy generates a warning on CMake 3.24
@@ -16,24 +35,17 @@ project(
1635option (ENABLE_MPI "Enable MPI" ON )
1736option (ENABLE_OPENMP "Enable OpenMP" ON )
1837option (USE_CUDA "Enable CUDA" OFF )
19- option (USE_CUDA_MPI "Enable CUDA-aware MPI" OFF )
20- option (USE_CUDA_ON_DCU "Enable CUDA on DCU" OFF )
2138option (USE_ROCM "Enable ROCm" OFF )
2239option (USE_DSP "Enable DSP" OFF )
40+ option (USE_CUDA_ON_DCU "Enable CUDA on DCU" OFF )
2341option (USE_KML "Enable Kunpeng Math Library" OFF )
2442option (USE_SW "Enable SW Architecture" OFF )
2543
2644option (ENABLE_ABACUS_LIBM "Build libmath from source to speed up" OFF )
2745option (ENABLE_LIBXC "Enable using the LibXC package" OFF )
2846option (ENABLE_FLOAT_FFTW "Enable using single-precision FFTW library." OFF )
2947
30- option (ENABLE_MLALGO "Enable the machine learning algorithms" OFF )
31-
3248option (ENABLE_LCAO "Enable LCAO algorithm" ON )
33- option (ENABLE_ELPA "Enable ELPA for LCAO" ON )
34- option (ENABLE_LIBRI "Enable LibRI for hybrid functional" OFF )
35- option (EXX_DEV "Enable LibRI developing features" OFF )
36- option (ENABLE_PEXSI "Enable PEXSI for LCAO" OFF )
3749option (ENABLE_DFTD4 "Enable DFT-D4 dispersion correction" OFF )
3850
3951option (BUILD_TESTING "Build unittests" OFF )
@@ -48,12 +60,35 @@ option(ENABLE_NATIVE_OPTIMIZATION
4860 "Enable compilation optimization for the native machine's CPU type" OFF )
4961
5062option (COMMIT_INFO "Print commit information in log" ON )
51- option (ENABLE_FFT_TWO_CENTER "Enable FFT-based two-center integral method" ON )
5263option (ENABLE_GOOGLEBENCH "Enable GOOGLE-benchmark usage" OFF )
5364option (ENABLE_RAPIDJSON "Enable rapid-json usage" OFF )
5465option (ENABLE_CNPY "Enable cnpy usage" OFF )
55- option (ENABLE_CUSOLVERMP "Enable cusolvermp" OFF )
56- option (ENABLE_NCCL_PARALLEL_DEVICE "Enable NCCL-backed collectives in parallel_device" OFF )
66+
67+ # Options requiring MPI and LCAO
68+ cmake_dependent_option (ENABLE_ELPA "Enable ELPA for LCAO" ON "ENABLE_LCAO;ENABLE_MPI" OFF )
69+ cmake_dependent_option (ENABLE_LIBRI "Enable LibRI for hybrid functional"
70+ OFF "ENABLE_LCAO;ENABLE_MPI" OFF )
71+ cmake_dependent_option (ENABLE_EXX_DEV "Enable LibRI developing features" OFF "ENABLE_LIBRI" OFF )
72+ cmake_dependent_option (ENABLE_PEXSI "Enable PEXSI for LCAO" OFF "ENABLE_LCAO;ENABLE_MPI" OFF )
73+ cmake_dependent_option (ENABLE_MLALGO "Enable the machine learning algorithms"
74+ OFF "ENABLE_LCAO;ENABLE_MPI" OFF )
75+
76+ # Two-center FFT is only used in LCAO
77+ cmake_dependent_option (ENABLE_FFT_TWO_CENTER "Enable FFT-based two-center integral method"
78+ ON "ENABLE_LCAO" OFF )
79+
80+ # Benchmark requires BUILD_TESTING
81+ cmake_dependent_option (ENABLE_GOOGLEBENCH "Enable GOOGLE-benchmark usage"
82+ OFF "BUILD_TESTING" OFF )
83+
84+ # Options requiring CUDA
85+ cmake_dependent_option (USE_CUDA_MPI "Enable CUDA-aware MPI" OFF "USE_CUDA;ENABLE_MPI" OFF )
86+ cmake_dependent_option (ENABLE_CUSOLVERMP "Enable cuSOLVERMp"
87+ OFF "USE_CUDA;ENABLE_MPI;ENABLE_LCAO" OFF )
88+ cmake_dependent_option (ENABLE_CUBLASMP "Enable cuBLASMp" OFF "ENABLE_CUSOLVERMP" OFF )
89+ cmake_dependent_option (ENABLE_NCCL_PARALLEL_DEVICE
90+ "Enable NCCL-backed collectives in parallel_device; requires MPI"
91+ OFF "USE_CUDA;ENABLE_MPI" OFF )
5792
5893# ==============================================================================
5994# Deprecated options (TODO: Remove this section in the future release)
@@ -63,20 +98,19 @@ function(abacus_rename_option old_name new_name)
6398 if (NOT _old_defined)
6499 return ()
65100 endif ()
66- message (WARNING "${old_name} has been renamed to ${new_name} ." )
101+ message (DEPRECATION "${old_name} has been renamed to ${new_name} ." )
67102 get_property (_type CACHE "${new_name} " PROPERTY TYPE)
68103 get_property (_help CACHE "${new_name} " PROPERTY HELPSTRING)
69104 set ("${new_name} " "${${old_name} }" CACHE "${_type} " "${_help} " FORCE )
70105 unset ("${old_name} " CACHE )
71106endfunction ()
72107abacus_rename_option (USE_OPENMP ENABLE_OPENMP )
73108abacus_rename_option (USE_ABACUS_LIBM ENABLE_ABACUS_LIBM )
74- abacus_rename_option (USE_ELPA ENABLE_ELPA )
75109abacus_rename_option (INFO MATH_INFO )
76110
77111if (DEFINED CACHE{ENABLE_LIBCOMM})
78112 message (
79- WARNING
113+ DEPRECATION
80114 "Option ENABLE_LIBCOMM is deprecated and will be ignored in a future release. "
81115 "LibComm is now treated as an implementation dependency of LibRI; "
82116 "please use -DENABLE_LIBRI=ON instead."
@@ -129,7 +163,8 @@ if(ENABLE_RAPIDJSON)
129163 if (NOT TARGET RapidJSON)
130164 message (
131165 FATAL_ERROR
132- "RapidJSON was found, but target RapidJSON is missing. Check if your RapidJSON installation provides a complete exported CMake configuration."
166+ "RapidJSON was found, but target RapidJSON is missing. "
167+ "Check if your RapidJSON installation provides a complete exported CMake configuration."
133168 )
134169 endif ()
135170 abacus_add_feature_definitions (__RAPIDJSON )
@@ -141,8 +176,8 @@ if(COMMIT_INFO)
141176 if (NOT Git_FOUND)
142177 message (
143178 WARNING
144- "Git is not found, and abacus will not output the git commit information in log. \n\
145- You can install Git first and reinstall abacus." )
179+ "Git is not found, and abacus will not output the git commit information in log.\n "
180+ " You can install Git first and reinstall abacus." )
146181 else ()
147182 message (STATUS "Found git: attempting to get commit info..." )
148183 execute_process (
@@ -170,12 +205,6 @@ You can install Git first and reinstall abacus.")
170205 endif ()
171206endif ()
172207
173- # Serial version of ABACUS will not use ELPA
174- if (NOT ENABLE_MPI)
175- set (ENABLE_ELPA OFF )
176- set (ENABLE_MLALGO OFF )
177- endif ()
178-
179208# Different exe files of ABACUS
180209unset (ABACUS_BIN_NAME CACHE )
181210
@@ -236,7 +265,10 @@ endif()
236265
237266# Use DSP hardware
238267if (USE_DSP)
239- set (ENABLE_ELPA OFF )
268+ if (ENABLE_ELPA)
269+ message (WARNING USE_DSP is incompatible with ELPA; switching off ENABLE_ELPA)
270+ set (ENABLE_ELPA OFF )
271+ endif ()
240272 set (ABACUS_BIN_NAME abacus_dsp)
241273endif ()
242274
@@ -349,11 +381,9 @@ if(ENABLE_LCAO)
349381 find_package (ELPA REQUIRED )
350382 abacus_add_feature_definitions (__ELPA )
351383 endif ()
352-
353384 if (ENABLE_FFT_TWO_CENTER)
354385 abacus_add_feature_definitions (USE_NEW_TWO_CENTER )
355386 endif ()
356-
357387 if (ENABLE_PEXSI)
358388 find_package (PEXSI REQUIRED CONFIG )
359389 if (PEXSI_VERSION VERSION_LESS "2.0.0" )
@@ -362,9 +392,6 @@ if(ENABLE_LCAO)
362392 abacus_add_feature_definitions (__PEXSI )
363393 set (CMAKE_CXX_STANDARD 14)
364394 endif ()
365- else ()
366- set (ENABLE_MLALGO OFF )
367- set (ENABLE_LIBRI OFF )
368395endif ()
369396
370397if (DEBUG_INFO)
@@ -520,10 +547,6 @@ if(USE_CUDA)
520547 set (CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler=${OpenMP_CXX_FLAGS} " CACHE STRING "CUDA flags" FORCE )
521548 endif ()
522549 if (ENABLE_NCCL_PARALLEL_DEVICE)
523- if (NOT ENABLE_MPI)
524- message (FATAL_ERROR
525- "ENABLE_NCCL_PARALLEL_DEVICE requires ENABLE_MPI=ON." )
526- endif ()
527550 abacus_add_feature_definitions (__NCCL_PARALLEL_DEVICE )
528551 include (cmake/modules/SetupNccl.cmake )
529552 abacus_setup_nccl ()
@@ -693,7 +716,7 @@ if(ENABLE_LIBRI)
693716 find_package (cereal REQUIRED CONFIG )
694717 abacus_add_feature_definitions (__EXX EXX_DM=3 EXX_H_COMM=2 TEST_EXX_LCAO=0
695718 TEST_EXX_RADIAL=1 )
696- if (EXX_DEV )
719+ if (ENABLE_EXX_DEV )
697720 abacus_add_feature_definitions (__EXX_DEV )
698721 endif ()
699722endif ()
0 commit comments