@@ -238,16 +238,6 @@ if(NOT DEFINED CMAKE_CXX_STANDARD)
238238endif ()
239239set (CMAKE_CXX_STANDARD_REQUIRED ON )
240240
241- if (ENABLE_DFTD4)
242- # DFTD4 requires enabling C and Fortran to work
243- enable_language (C )
244- 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 )
249- endif ()
250-
251241macro (set_if_higher VARIABLE VALUE )
252242 if (${VARIABLE} LESS ${VALUE} )
253243 set (${VARIABLE} ${VALUE} )
@@ -308,6 +298,50 @@ if(WIN32)
308298 abacus_add_feature_definitions (_USE_MATH_DEFINES NOMINMAX _CRT_SECURE_NO_WARNINGS )
309299endif ()
310300
301+ if (DEFINED ENV{MKLROOT} AND NOT DEFINED MKLROOT)
302+ set (MKLROOT "$ENV{MKLROOT} " )
303+ endif ()
304+ if (USE_KML)
305+ set (_kml_components BLAS LAPACK FFTW3)
306+ if (ENABLE_MPI)
307+ list (APPEND _kml_components ScaLAPACK)
308+ endif ()
309+ if (ENABLE_FLOAT_FFTW)
310+ list (APPEND _kml_components FFTW3_FLOAT)
311+ endif ()
312+
313+ find_package (KML REQUIRED COMPONENTS ${_kml_components} )
314+ abacus_add_feature_definitions (__KML )
315+ elseif (MKLROOT OR MKL_ROOT)
316+ find_package (MKL REQUIRED )
317+ abacus_add_feature_definitions (__MKL )
318+ elseif (NOT USE_SW)
319+ find_package (Lapack REQUIRED )
320+ # ScaLAPACK is a distributed-memory library and is only needed for the
321+ # MPI build. A serial build (e.g. the native Windows serial version)
322+ # must not require it.
323+ if (ENABLE_MPI)
324+ find_package (ScaLAPACK REQUIRED )
325+ endif ()
326+ if (NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU|Intel|Clang" )
327+ message (WARNING "Cannot determine the required Fortran runtime." )
328+ endif ()
329+ endif ()
330+
331+ if (NOT USE_KML AND NOT MKL_FOUND AND NOT USE_SW)
332+ find_package (FFTW3 REQUIRED )
333+ endif ()
334+
335+ if (ENABLE_FLOAT_FFTW)
336+ abacus_add_feature_definitions (__ENABLE_FLOAT_FFTW )
337+ endif ()
338+
339+ if (ENABLE_DFTD4)
340+ enable_language (C )
341+ enable_language (Fortran )
342+ find_package (dftd4 4.2.0 REQUIRED )
343+ endif ()
344+
311345if (ENABLE_LCAO)
312346 find_package (cereal CONFIG REQUIRED )
313347 abacus_add_feature_definitions (__LCAO )
@@ -350,8 +384,6 @@ if (USE_DSP)
350384 abacus_add_feature_definitions (__DSP )
351385endif ()
352386
353-
354-
355387if (USE_SW)
356388 abacus_add_feature_definitions (__SW )
357389 set (SW ON )
@@ -534,44 +566,6 @@ if(ENABLE_ASAN)
534566 add_link_options (-fsanitize=address )
535567endif ()
536568
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-
571- if (ENABLE_FLOAT_FFTW)
572- abacus_add_feature_definitions (__ENABLE_FLOAT_FFTW )
573- endif ()
574-
575569if (ENABLE_MLALGO)
576570 find_path (libnpy_SOURCE_DIR npy.hpp HINTS ${libnpy_INCLUDE_DIR} )
577571 if (NOT libnpy_SOURCE_DIR )
0 commit comments