Skip to content

Commit f91b2d6

Browse files
yizeyi18caic99
andauthored
Build: Improving CMake performance for finding LibXC and ELPA (#3478)
* Fix for finding LibXC and ELPA * For compatibility to previous routines * syntax fix for FindELPA.cmake * Update cmake/FindELPA.cmake Co-authored-by: Chun Cai <[email protected]> * Using CMake interface as default for finding LibXC * update docs * fix for FindLibxc: changing imcompatible if statement * fix for FindLibxc: changing imcompatible if statement * fix for FindLibxc: changing imcompatible if statement * update docs for installing pkg-config * Update FindLibxc.cmake * Update FindLibxc.cmake * remove previous LibXC routine in CMakeLists.txt Co-authored-by: Chun Cai <[email protected]> * Update easy_install.md with Makefile-built LibXC supported * Update easy_install.md to include different behavior in different version on finding ELPA --------- Co-authored-by: Chun Cai <[email protected]>
1 parent 05d4625 commit f91b2d6

File tree

4 files changed

+72
-24
lines changed

4 files changed

+72
-24
lines changed

CMakeLists.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,8 @@ if(DEFINED Libxc_DIR)
536536
set(ENABLE_LIBXC ON)
537537
endif()
538538
if(ENABLE_LIBXC)
539-
find_package(Libxc REQUIRED HINTS
540-
${Libxc_DIR}/share/cmake/Libxc
541-
${Libxc_DIR}/lib/cmake/Libxc
542-
${Libxc_DIR}/lib64/cmake/Libxc
543-
)
539+
# use `cmake/FindLibxc.cmake` to detect Libxc installation with `pkg-config`
540+
find_package(Libxc REQUIRED)
544541
message(STATUS "Found Libxc: version " ${Libxc_VERSION})
545542
if(${Libxc_VERSION} VERSION_LESS 5.1.7)
546543
message(FATAL_ERROR "LibXC >= 5.1.7 is required.")

cmake/FindELPA.cmake

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,49 @@
77
# ELPA_INCLUDE_DIR - Where to find ELPA headers.
88
#
99

10-
find_path(ELPA_INCLUDE_DIR
10+
find_package(PkgConfig)
11+
12+
if(PKG_CONFIG_FOUND)
13+
if(DEFINED ELPA_DIR)
14+
string(APPEND CMAKE_PREFIX_PATH ";${ELPA_DIR}")
15+
endif()
16+
if(USE_OPENMP)
17+
pkg_search_module(ELPA REQUIRED IMPORTED_TARGET GLOBAL elpa_openmp)
18+
else()
19+
pkg_search_module(ELPA REQUIRED IMPORTED_TARGET GLOBAL elpa)
20+
endif()
21+
else()
22+
find_path(ELPA_INCLUDE_DIRS
1123
elpa/elpa.h
1224
HINTS ${ELPA_DIR}
1325
PATH_SUFFIXES "include" "include/elpa"
1426
)
15-
if(USE_OPENMP)
16-
find_library(ELPA_LIBRARY
17-
NAMES elpa_openmp elpa
18-
HINTS ${ELPA_DIR}
19-
PATH_SUFFIXES "lib"
20-
)
21-
else()
22-
find_library(ELPA_LIBRARY
23-
NAMES elpa
24-
HINTS ${ELPA_DIR}
25-
PATH_SUFFIXES "lib"
26-
)
27+
if(USE_OPENMP)
28+
find_library(ELPA_LINK_LIBRARIES
29+
NAMES elpa_openmp elpa
30+
HINTS ${ELPA_DIR}
31+
PATH_SUFFIXES "lib"
32+
)
33+
else()
34+
find_library(ELPA_LINK_LIBRARIES
35+
NAMES elpa
36+
HINTS ${ELPA_DIR}
37+
PATH_SUFFIXES "lib"
38+
)
39+
endif()
40+
#message(
41+
# "ELPA : We need pkg-config to get all information about the elpa library")
2742
endif()
2843

2944
# Handle the QUIET and REQUIRED arguments and
3045
# set ELPA_FOUND to TRUE if all variables are non-zero.
3146
include(FindPackageHandleStandardArgs)
32-
find_package_handle_standard_args(ELPA DEFAULT_MSG ELPA_LIBRARY ELPA_INCLUDE_DIR)
47+
find_package_handle_standard_args(ELPA DEFAULT_MSG ELPA_LINK_LIBRARIES ELPA_INCLUDE_DIRS)
3348

3449
# Copy the results to the output variables and target.
3550
if(ELPA_FOUND)
36-
set(ELPA_LIBRARIES ${ELPA_LIBRARY})
37-
set(ELPA_INCLUDE_DIR ${ELPA_INCLUDE_DIR})
51+
set(ELPA_LIBRARY ${ELPA_LINK_LIBRARIES})
52+
set(ELPA_INCLUDE_DIR ${ELPA_INCLUDE_DIRS})
3853

3954
if(NOT TARGET ELPA::ELPA)
4055
add_library(ELPA::ELPA UNKNOWN IMPORTED)

cmake/FindLibxc.cmake

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
include(FindPackageHandleStandardArgs)
2+
3+
if(DEFINED Libxc_DIR)
4+
string(APPEND CMAKE_PREFIX_PATH ";${Libxc_DIR}")
5+
endif()
6+
# Using CMake interface as default.
7+
# NO REQUIRED here, otherwhile it would throw error
8+
# with no LibXC found.
9+
find_package(Libxc HINTS
10+
${Libxc_DIR}/share/cmake/Libxc
11+
${Libxc_DIR}/lib/cmake/Libxc
12+
${Libxc_DIR}/lib64/cmake/Libxc
13+
)
14+
if(NOT TARGET Libxc::xc)
15+
find_package(PkgConfig REQUIRED)
16+
pkg_search_module(Libxc REQUIRED IMPORTED_TARGET GLOBAL libxc)
17+
find_package_handle_standard_args(Libxc DEFAULT_MSG Libxc_LINK_LIBRARIES Libxc_INCLUDE_DIRS)
18+
endif()
19+
20+
21+
# Copy the results to the output variables and target.
22+
# if find_package() above works, Libxc::xc would be present and
23+
# below would be skipped.
24+
if(Libxc_FOUND AND NOT TARGET Libxc::xc)
25+
set(Libxc_LIBRARY ${Libxc_LINK_LIBRARIES})
26+
set(Libxc_LIBRARIES ${Libxc_LIBRARY})
27+
set(Libxc_INCLUDE_DIR ${Libxc_INCLUDE_DIRS})
28+
add_library(Libxc::xc UNKNOWN IMPORTED)
29+
set_target_properties(Libxc::xc PROPERTIES
30+
IMPORTED_LOCATION "${Libxc_LIBRARY}"
31+
INTERFACE_INCLUDE_DIRECTORIES "${Libxc_INCLUDE_DIR}")
32+
endif()
33+
34+
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${Libxc_INCLUDE_DIR})
35+
36+
mark_as_advanced(Libxc_INCLUDE_DIR Libxc_LIBRARY)

docs/quick_start/easy_install.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ These requirements support the calculation of plane-wave basis in ABACUS. For LC
2828
Some of these packages can be installed with popular package management system, such as `apt` and `yum`:
2929

3030
```bash
31-
sudo apt update && sudo apt install -y libopenblas-openmp-dev liblapack-dev libscalapack-mpi-dev libelpa-dev libfftw3-dev libcereal-dev libxc-dev g++ make cmake bc git
31+
sudo apt update && sudo apt install -y libopenblas-openmp-dev liblapack-dev libscalapack-mpi-dev libelpa-dev libfftw3-dev libcereal-dev libxc-dev g++ make cmake bc git pkgconf
3232
```
3333

3434
> Installing ELPA by apt only matches requirements on Ubuntu 22.04. For earlier linux distributions, you should build ELPA from source.
@@ -111,12 +111,12 @@ Here, 'build' is the path for building ABACUS; and '-D' is used for setting up s
111111
- `LAPACK_DIR`: Path to OpenBLAS library `libopenblas.so`(including BLAS and LAPACK)
112112
- `SCALAPACK_DIR`: Path to ScaLAPACK library `libscalapack.so`
113113
- `ELPA_DIR`: Path to ELPA install directory; should be the folder containing 'include' and 'lib'.
114-
> Note: If you install ELPA from source, please add a symlink to avoid the additional include file folder with version name: `ln -s elpa/include/elpa-2021.05.002/elpa elpa/include/elpa`. This is a known behavior of ELPA.
114+
> Note: In ABACUS v3.5.1 or earlier, if you install ELPA from source , please add a symlink to avoid the additional include file folder with version name: `ln -s elpa/include/elpa-2021.05.002/elpa elpa/include/elpa` to help the build system find ELPA headers.
115115
116116
- `FFTW3_DIR`: Path to FFTW3.
117117
- `CEREAL_INCLUDE_DIR`: Path to the parent folder of `cereal/cereal.hpp`. Will download from GitHub if absent.
118118
- `Libxc_DIR`: (Optional) Path to Libxc.
119-
> Note: Building Libxc from source with Makefile does NOT support using it in CMake here. Please compile Libxc with CMake instead.
119+
> Note: In ABACUS v3.5.1 or earlier, Libxc built from source with Makefile is NOT supported; please compile Libxc with CMake instead.
120120
- `LIBRI_DIR`: (Optional) Path to LibRI.
121121
- `LIBCOMM_DIR`: (Optional) Path to LibComm.
122122

0 commit comments

Comments
 (0)