Skip to content

Commit a990427

Browse files
committed
CMake: Resolve DFT-D4 dependencies after math libraries
1 parent c475041 commit a990427

4 files changed

Lines changed: 67 additions & 41 deletions

File tree

.github/workflows/build_test_cmake.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ jobs:
2323

2424
- tag: gnu
2525
external_toolchain_args: ""
26-
build_args: "-DENABLE_LIBXC=ON -DENABLE_MLALGO=ON -DENABLE_LIBRI=ON"
26+
build_args: "-DENABLE_LIBXC=ON -DENABLE_MLALGO=ON -DENABLE_LIBRI=ON -DENABLE_DFTD4=ON"
2727
name: "Build extra components with GNU toolchain"
2828
- tag: intel
2929
external_toolchain_args: "--with-intel"
30-
build_args: "-DENABLE_LIBXC=ON -DENABLE_PEXSI=ON -DENABLE_MLALGO=ON -DENABLE_LIBRI=ON"
30+
build_args: "-DENABLE_LIBXC=ON -DENABLE_PEXSI=ON -DENABLE_MLALGO=ON -DENABLE_LIBRI=ON -DENABLE_DFTD4=ON"
3131
name: "Build extra components with Intel toolchain"
3232

3333
- tag: cuda

CMakeLists.txt

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,10 @@ if(NOT DEFINED CMAKE_CXX_STANDARD)
238238
endif()
239239
set(CMAKE_CXX_STANDARD_REQUIRED ON)
240240

241+
# Enable DFT-D4 languages before finding OpenMP.
241242
if(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)
249245
endif()
250246

251247
macro(set_if_higher VARIABLE VALUE)
@@ -363,6 +359,44 @@ if(USE_OPENMP)
363359
find_package(OpenMP REQUIRED)
364360
endif()
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+
366400
include(CheckLanguage)
367401
check_language(CUDA)
368402
if(CMAKE_CUDA_COMPILER)
@@ -534,40 +568,6 @@ if(ENABLE_ASAN)
534568
add_link_options(-fsanitize=address)
535569
endif()
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-
571571
if(ENABLE_FLOAT_FFTW)
572572
abacus_add_feature_definitions(__ENABLE_FLOAT_FFTW)
573573
endif()

cmake/modules/FindKML.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,18 @@ if(KML_FOUND)
267267
endif()
268268
endif()
269269

270+
# Compatibility with packages that consume the standard CMake math targets.
271+
if(TARGET KML::BLAS AND NOT TARGET BLAS::BLAS)
272+
add_library(BLAS::BLAS INTERFACE IMPORTED)
273+
set_property(TARGET BLAS::BLAS PROPERTY
274+
INTERFACE_LINK_LIBRARIES KML::BLAS)
275+
endif()
276+
if(TARGET KML::LAPACK AND NOT TARGET LAPACK::LAPACK)
277+
add_library(LAPACK::LAPACK INTERFACE IMPORTED)
278+
set_property(TARGET LAPACK::LAPACK PROPERTY
279+
INTERFACE_LINK_LIBRARIES KML::LAPACK)
280+
endif()
281+
270282
mark_as_advanced(
271283
KML_INCLUDE_DIR
272284
KML_RUNTIME_LIBRARY

cmake/modules/FindMKL.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,20 @@ if(MKL_FOUND)
273273
endif()
274274
endif()
275275

276+
# Compatibility with packages that consume the standard CMake math targets.
277+
if(TARGET abacus::mkl)
278+
if(NOT TARGET BLAS::BLAS)
279+
add_library(BLAS::BLAS INTERFACE IMPORTED)
280+
set_property(TARGET BLAS::BLAS PROPERTY
281+
INTERFACE_LINK_LIBRARIES abacus::mkl)
282+
endif()
283+
if(NOT TARGET LAPACK::LAPACK)
284+
add_library(LAPACK::LAPACK INTERFACE IMPORTED)
285+
set_property(TARGET LAPACK::LAPACK PROPERTY
286+
INTERFACE_LINK_LIBRARIES abacus::mkl)
287+
endif()
288+
endif()
289+
276290
mark_as_advanced(
277291
_abacus_mkl_include
278292
_abacus_mkl_fftw_include

0 commit comments

Comments
 (0)