Skip to content

Commit cfe5eaf

Browse files
Add EXCHCXX_ENABLE_LIBXC option to disable LibXC backend on request
1 parent 7b01715 commit cfe5eaf

12 files changed

Lines changed: 50 additions & 11 deletions

CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ option( EXCHCXX_ENABLE_BENCHMARK "Enable Performance Benchmark" OFF )
99
option( EXCHCXX_ENABLE_CUDA "Enable Device Code (CUDA)" OFF )
1010
option( EXCHCXX_ENABLE_HIP "Enable Device Code (HIP)" OFF )
1111
option( EXCHCXX_ENABLE_SYCL "Enable Device Code (SYCL)" OFF )
12+
option( EXCHCXX_ENABLE_LIBXC "Enable Libxc Backend" ON )
1213
option( BUILD_SHARED_LIBS "Build Shared Libs" OFF )
1314

1415

@@ -53,6 +54,7 @@ if( EXCHCXX_ENABLE_HIP )
5354
endif()
5455

5556

57+
if(EXCHCXX_ENABLE_LIBXC)
5658

5759
## Find LibXC
5860
find_package( Libxc 6.2.0 CONFIG QUIET )
@@ -96,6 +98,10 @@ else()
9698
set( BUILD_TESTING ${OLD_BUILD_TESTING} CACHE BOOL "" FORCE )
9799

98100
endif()
101+
102+
else( EXCHCXX_ENABLE_LIBXC )
103+
set( Libxc_FOUND FALSE )
104+
endif( EXCHCXX_ENABLE_LIBXC )
99105

100106
add_subdirectory( src )
101107

@@ -105,13 +111,13 @@ if( NOT DEFINED EXCHCXX_ENABLE_TESTS )
105111
endif()
106112

107113
if( CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND EXCHCXX_ENABLE_TESTS AND BUILD_TESTING )
108-
if(${Libxc_FOUND})
114+
if(${Libxc_FOUND} OR NOT EXCHCXX_ENABLE_LIBXC)
109115
message(WARNING "ExchCXX Unit Tests Require Local Patch of Libxc - Disabling")
110116
else()
111117
add_subdirectory( test )
112118
endif()
113119
endif()
114120

115-
if( EXCHCXX_ENABLE_BENCHMARK )
121+
if( EXCHCXX_ENABLE_BENCHMARK AND EXCHCXX_ENABLE_LIBXC )
116122
add_subdirectory( performance )
117123
endif()

cmake/ExchCXXConfig.cmake.in

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ get_filename_component(ExchCXX_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
44

55
list(APPEND CMAKE_MODULE_PATH ${ExchCXX_CMAKE_DIR})
66
include(CMakeFindDependencyMacro)
7-
find_dependency( Libxc @Libxc_VERSION@ EXACT CONFIG )
87

98

109
set( EXCHCXX_ENABLE_CUDA @EXCHCXX_ENABLE_CUDA@ )
1110
set( EXCHCXX_ENABLE_HIP @EXCHCXX_ENABLE_HIP@ )
1211
set( EXCHCXX_ENABLE_SYCL @EXCHCXX_ENABLE_SYCL@ )
1312
set( EXCHCXX_ENABLE_DEVICE @EXCHCXX_ENABLE_DEVICE@ )
13+
set( EXCHCXX_ENABLE_LIBXC @EXCHCXX_ENABLE_LIBXC@ )
14+
15+
if( EXCHCXX_ENABLE_LIBXC )
16+
find_dependency( Libxc @Libxc_VERSION@ EXACT CONFIG )
17+
endif()
1418

1519
if( EXCHCXX_ENABLE_CUDA )
1620
find_dependency( CUDAToolkit @CUDAToolkit_VERSION@ EXACT )

include/exchcxx/enums/backend.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@
4949
namespace ExchCXX {
5050

5151
enum class Backend {
52+
#ifdef EXCHCXX_ENABLE_LIBXC
5253
libxc,
54+
#endif
5355
builtin
5456
};
5557

58+
#ifdef EXCHCXX_ENABLE_LIBXC
5659
using libxc_name_string = detail::NamedType<std::string, struct LibxcNameString>;
60+
#endif
5761

5862
}

include/exchcxx/exchcxx_config.hpp.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#cmakedefine EXCHCXX_ENABLE_HIP
5050
#cmakedefine EXCHCXX_ENABLE_SYCL
5151
#cmakedefine EXCHCXX_ENABLE_DEVICE
52+
#cmakedefine EXCHCXX_ENABLE_LIBXC
5253

5354

5455
#ifdef EXCHCXX_ENABLE_CUDA

include/exchcxx/factory/xc_kernel.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,22 @@
5454

5555
namespace ExchCXX {
5656

57+
#ifdef EXCHCXX_ENABLE_LIBXC
5758
XCKernel libxc_kernel_factory(const Kernel, const Spin );
5859
XCKernel libxc_kernel_factory(const std::string xc_name, const Spin polar );
60+
#endif
61+
5962
XCKernel builtin_kernel_factory( Kernel, Spin );
6063

6164
static inline XCKernel kernel_factory(
6265
Backend backend, Kernel kern, Spin polar
6366
) {
6467

68+
#ifdef EXCHCXX_ENABLE_LIBXC
6569
if( backend == Backend::libxc )
6670
return libxc_kernel_factory( kern, polar );
6771
else
72+
#endif
6873
return builtin_kernel_factory( kern, polar );
6974

7075
}

include/exchcxx/xc_functional.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ class XCFunctional {
108108

109109
XCFunctional( const Backend, const Functional, const Spin );
110110
XCFunctional( const Functional func, const Spin polar) :
111+
#ifdef EXCHCXX_ENABLE_LIBXC
111112
XCFunctional( Backend::libxc, func, polar) { };
113+
#else
114+
XCFunctional( Backend::builtin, func, polar) { };
115+
#endif
112116

113117
XCFunctional( const XCFunctional& ) ;
114118
XCFunctional( XCFunctional&& ) noexcept;

include/exchcxx/xc_kernel.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,15 @@ class XCKernel {
7979

8080
XCKernel( const Backend backend, const Kernel kern,
8181
const Spin polar );
82+
#ifdef EXCHCXX_ENABLE_LIBXC
8283
XCKernel( const libxc_name_string& xc_name,
8384
const Spin polar );
8485
XCKernel( const Kernel kern, const Spin polar ) :
8586
XCKernel( Backend::libxc, kern, polar ){ };
87+
#else
88+
XCKernel( const Kernel kern, const Spin polar ) :
89+
XCKernel( Backend::builtin, kern, polar ){ };
90+
#endif
8691

8792
XCKernel( impl_ptr&& ptr ) ;
8893
XCKernel( const XCKernel& ) ;

src/CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
2-
3-
41
set( EXCHCXX_SOURCES
52
xc_kernel.cxx
63
xc_functional.cxx
7-
libxc.cxx
84
boilerplate.cxx
95
builtin.cxx
106
builtin_interface.cxx
117
builtin_kernel.cxx
128
)
9+
if(EXCHCXX_ENABLE_LIBXC)
10+
list(APPEND EXCHCXX_SOURCES libxc.cxx)
11+
endif()
12+
message(STATUS ${EXCHCXX_SOURCES})
1313

1414
add_library( exchcxx ${EXCHCXX_SOURCES} )
1515

1616
# TARGET properties
1717

1818
target_compile_features( exchcxx PUBLIC cxx_std_17 )
19-
target_link_libraries( exchcxx PUBLIC Libxc::xc )
19+
if( EXCHCXX_ENABLE_LIBXC )
20+
target_link_libraries( exchcxx PUBLIC Libxc::xc )
21+
endif()
2022

2123
# Generate exchcxx_config.hpp
2224
configure_file(

src/cuda/exchcxx_cuda.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
set( EXCHCXX_CUDA_SOURCES
22
cuda/xc_functional_device.cu
3-
cuda/libxc_device.cxx
43
cuda/builtin.cu
54
)
5+
if( EXCHCXX_ENABLE_LIBXC )
6+
list(APPEND EXCHCXX_CUDA_SOURCES cuda/libxc_device.cxx)
7+
endif()
68

79
find_package( CUDAToolkit REQUIRED )
810
#add_library( exchcxx_device OBJECT ${EXCHCXX_CUDA_SOURCES} )

src/hip/exchcxx_hip.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
set( EXCHCXX_HIP_SOURCES
22
hip/xc_functional_device.hip
3-
hip/libxc_device.hip
43
hip/builtin.hip
54
)
5+
if( EXCHCXX_ENABLE_LIBXC )
6+
list(APPEND EXCHCXX_HIP_SOURCES hip/libxc_device.hip)
7+
endif()
68

79
find_package( hip REQUIRED )
810

0 commit comments

Comments
 (0)