@@ -238,14 +238,10 @@ if(NOT DEFINED CMAKE_CXX_STANDARD)
238238endif ()
239239set (CMAKE_CXX_STANDARD_REQUIRED ON )
240240
241+ # Enable DFT-D4 languages before finding OpenMP.
241242if (ENABLE_DFTD4)
242- # DFTD4 requires enabling C and Fortran to work
243243 enable_language (C )
244244 enable_language (Fortran )
245- # Avoid custom-lapack fallback when resolving DFT-D4 dependencies
246- find_package (BLAS REQUIRED )
247- find_package (LAPACK REQUIRED )
248- find_package (dftd4 4.2.0 REQUIRED )
249245endif ()
250246
251247macro (set_if_higher VARIABLE VALUE )
@@ -363,6 +359,44 @@ if(USE_OPENMP)
363359 find_package (OpenMP REQUIRED )
364360endif ()
365361
362+ if (DEFINED ENV{MKLROOT} AND NOT DEFINED MKLROOT)
363+ set (MKLROOT "$ENV{MKLROOT} " )
364+ endif ()
365+ if (USE_KML)
366+ set (_kml_components BLAS LAPACK FFTW3)
367+ if (ENABLE_MPI)
368+ list (APPEND _kml_components ScaLAPACK)
369+ endif ()
370+ if (ENABLE_FLOAT_FFTW)
371+ list (APPEND _kml_components FFTW3_FLOAT)
372+ endif ()
373+
374+ find_package (KML REQUIRED COMPONENTS ${_kml_components} )
375+ abacus_add_feature_definitions (__KML )
376+ elseif (MKLROOT OR MKL_ROOT)
377+ find_package (MKL REQUIRED )
378+ abacus_add_feature_definitions (__MKL )
379+ elseif (NOT USE_SW)
380+ find_package (Lapack REQUIRED )
381+ # ScaLAPACK is a distributed-memory library and is only needed for the
382+ # MPI build. A serial build (e.g. the native Windows serial version)
383+ # must not require it.
384+ if (ENABLE_MPI)
385+ find_package (ScaLAPACK REQUIRED )
386+ endif ()
387+ if (NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU|Intel|Clang" )
388+ message (WARNING "Cannot determine the required Fortran runtime." )
389+ endif ()
390+ endif ()
391+
392+ if (NOT USE_KML AND NOT MKL_FOUND AND NOT USE_SW)
393+ find_package (FFTW3 REQUIRED )
394+ endif ()
395+
396+ if (ENABLE_DFTD4)
397+ find_package (dftd4 4.2.0 REQUIRED )
398+ endif ()
399+
366400include (CheckLanguage )
367401check_language (CUDA )
368402if (CMAKE_CUDA_COMPILER)
@@ -534,40 +568,6 @@ if(ENABLE_ASAN)
534568 add_link_options (-fsanitize=address )
535569endif ()
536570
537- if (DEFINED ENV{MKLROOT} AND NOT DEFINED MKLROOT)
538- set (MKLROOT "$ENV{MKLROOT} " )
539- endif ()
540- if (USE_KML)
541- set (_kml_components BLAS LAPACK FFTW3)
542- if (ENABLE_MPI)
543- list (APPEND _kml_components ScaLAPACK)
544- endif ()
545- if (ENABLE_FLOAT_FFTW)
546- list (APPEND _kml_components FFTW3_FLOAT)
547- endif ()
548-
549- find_package (KML REQUIRED COMPONENTS ${_kml_components} )
550- abacus_add_feature_definitions (__KML )
551- elseif (MKLROOT OR MKL_ROOT)
552- find_package (MKL REQUIRED )
553- abacus_add_feature_definitions (__MKL )
554- elseif (NOT USE_SW)
555- find_package (Lapack REQUIRED )
556- # ScaLAPACK is a distributed-memory library and is only needed for the
557- # MPI build. A serial build (e.g. the native Windows serial version)
558- # must not require it.
559- if (ENABLE_MPI)
560- find_package (ScaLAPACK REQUIRED )
561- endif ()
562- if (NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU|Intel|Clang" )
563- message (WARNING "Cannot determine the required Fortran runtime." )
564- endif ()
565- endif ()
566-
567- if (NOT USE_KML AND NOT MKL_FOUND AND NOT USE_SW)
568- find_package (FFTW3 REQUIRED )
569- endif ()
570-
571571if (ENABLE_FLOAT_FFTW)
572572 abacus_add_feature_definitions (__ENABLE_FLOAT_FFTW )
573573endif ()
0 commit comments