diff --git a/CMakeLists.txt b/CMakeLists.txt index 16d48ad..484da48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ option( EXCHCXX_ENABLE_BENCHMARK "Enable Performance Benchmark" OFF ) option( EXCHCXX_ENABLE_CUDA "Enable Device Code (CUDA)" OFF ) option( EXCHCXX_ENABLE_HIP "Enable Device Code (HIP)" OFF ) option( EXCHCXX_ENABLE_SYCL "Enable Device Code (SYCL)" OFF ) +option( EXCHCXX_ENABLE_LIBXC "Enable Libxc Backend" ON ) option( BUILD_SHARED_LIBS "Build Shared Libs" OFF ) @@ -53,6 +54,7 @@ if( EXCHCXX_ENABLE_HIP ) endif() +if(EXCHCXX_ENABLE_LIBXC) ## Find LibXC find_package( Libxc 6.2.0 CONFIG QUIET ) @@ -96,6 +98,10 @@ else() set( BUILD_TESTING ${OLD_BUILD_TESTING} CACHE BOOL "" FORCE ) endif() + +else( EXCHCXX_ENABLE_LIBXC ) + set( Libxc_FOUND FALSE ) +endif( EXCHCXX_ENABLE_LIBXC ) add_subdirectory( src ) @@ -105,13 +111,13 @@ if( NOT DEFINED EXCHCXX_ENABLE_TESTS ) endif() if( CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND EXCHCXX_ENABLE_TESTS AND BUILD_TESTING ) - if(${Libxc_FOUND}) + if(${Libxc_FOUND} OR NOT EXCHCXX_ENABLE_LIBXC) message(WARNING "ExchCXX Unit Tests Require Local Patch of Libxc - Disabling") else() add_subdirectory( test ) endif() endif() -if( EXCHCXX_ENABLE_BENCHMARK ) +if( EXCHCXX_ENABLE_BENCHMARK AND EXCHCXX_ENABLE_LIBXC ) add_subdirectory( performance ) endif() diff --git a/cmake/ExchCXXConfig.cmake.in b/cmake/ExchCXXConfig.cmake.in index dd11def..8897548 100644 --- a/cmake/ExchCXXConfig.cmake.in +++ b/cmake/ExchCXXConfig.cmake.in @@ -4,13 +4,17 @@ get_filename_component(ExchCXX_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) list(APPEND CMAKE_MODULE_PATH ${ExchCXX_CMAKE_DIR}) include(CMakeFindDependencyMacro) -find_dependency( Libxc @Libxc_VERSION@ EXACT CONFIG ) set( EXCHCXX_ENABLE_CUDA @EXCHCXX_ENABLE_CUDA@ ) set( EXCHCXX_ENABLE_HIP @EXCHCXX_ENABLE_HIP@ ) set( EXCHCXX_ENABLE_SYCL @EXCHCXX_ENABLE_SYCL@ ) set( EXCHCXX_ENABLE_DEVICE @EXCHCXX_ENABLE_DEVICE@ ) +set( EXCHCXX_ENABLE_LIBXC @EXCHCXX_ENABLE_LIBXC@ ) + +if( EXCHCXX_ENABLE_LIBXC ) + find_dependency( Libxc @Libxc_VERSION@ EXACT CONFIG ) +endif() if( EXCHCXX_ENABLE_CUDA ) find_dependency( CUDAToolkit @CUDAToolkit_VERSION@ EXACT ) diff --git a/include/exchcxx/enums/backend.hpp b/include/exchcxx/enums/backend.hpp index 6f1a3cc..963972f 100644 --- a/include/exchcxx/enums/backend.hpp +++ b/include/exchcxx/enums/backend.hpp @@ -49,10 +49,14 @@ namespace ExchCXX { enum class Backend { +#ifdef EXCHCXX_ENABLE_LIBXC libxc, +#endif builtin }; +#ifdef EXCHCXX_ENABLE_LIBXC using libxc_name_string = detail::NamedType; +#endif } diff --git a/include/exchcxx/exchcxx_config.hpp.in b/include/exchcxx/exchcxx_config.hpp.in index 11b2291..37e4383 100644 --- a/include/exchcxx/exchcxx_config.hpp.in +++ b/include/exchcxx/exchcxx_config.hpp.in @@ -49,6 +49,7 @@ #cmakedefine EXCHCXX_ENABLE_HIP #cmakedefine EXCHCXX_ENABLE_SYCL #cmakedefine EXCHCXX_ENABLE_DEVICE +#cmakedefine EXCHCXX_ENABLE_LIBXC #ifdef EXCHCXX_ENABLE_CUDA diff --git a/include/exchcxx/factory/xc_kernel.hpp b/include/exchcxx/factory/xc_kernel.hpp index bdbc3f3..dafb2e7 100644 --- a/include/exchcxx/factory/xc_kernel.hpp +++ b/include/exchcxx/factory/xc_kernel.hpp @@ -54,17 +54,22 @@ namespace ExchCXX { +#ifdef EXCHCXX_ENABLE_LIBXC XCKernel libxc_kernel_factory(const Kernel, const Spin ); XCKernel libxc_kernel_factory(const std::string xc_name, const Spin polar ); +#endif + XCKernel builtin_kernel_factory( Kernel, Spin ); static inline XCKernel kernel_factory( Backend backend, Kernel kern, Spin polar ) { +#ifdef EXCHCXX_ENABLE_LIBXC if( backend == Backend::libxc ) return libxc_kernel_factory( kern, polar ); else +#endif return builtin_kernel_factory( kern, polar ); } diff --git a/include/exchcxx/xc_functional.hpp b/include/exchcxx/xc_functional.hpp index 470a4c3..a22457a 100644 --- a/include/exchcxx/xc_functional.hpp +++ b/include/exchcxx/xc_functional.hpp @@ -108,7 +108,11 @@ class XCFunctional { XCFunctional( const Backend, const Functional, const Spin ); XCFunctional( const Functional func, const Spin polar) : +#ifdef EXCHCXX_ENABLE_LIBXC XCFunctional( Backend::libxc, func, polar) { }; +#else + XCFunctional( Backend::builtin, func, polar) { }; +#endif XCFunctional( const XCFunctional& ) ; XCFunctional( XCFunctional&& ) noexcept; diff --git a/include/exchcxx/xc_kernel.hpp b/include/exchcxx/xc_kernel.hpp index 21efbd4..6262c70 100644 --- a/include/exchcxx/xc_kernel.hpp +++ b/include/exchcxx/xc_kernel.hpp @@ -79,10 +79,15 @@ class XCKernel { XCKernel( const Backend backend, const Kernel kern, const Spin polar ); +#ifdef EXCHCXX_ENABLE_LIBXC XCKernel( const libxc_name_string& xc_name, const Spin polar ); XCKernel( const Kernel kern, const Spin polar ) : XCKernel( Backend::libxc, kern, polar ){ }; +#else + XCKernel( const Kernel kern, const Spin polar ) : + XCKernel( Backend::builtin, kern, polar ){ }; +#endif XCKernel( impl_ptr&& ptr ) ; XCKernel( const XCKernel& ) ; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e314e9e..ec0adad 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,22 +1,24 @@ - - - set( EXCHCXX_SOURCES xc_kernel.cxx xc_functional.cxx - libxc.cxx boilerplate.cxx builtin.cxx builtin_interface.cxx builtin_kernel.cxx ) +if(EXCHCXX_ENABLE_LIBXC) + list(APPEND EXCHCXX_SOURCES libxc.cxx) +endif() +message(STATUS ${EXCHCXX_SOURCES}) add_library( exchcxx ${EXCHCXX_SOURCES} ) # TARGET properties target_compile_features( exchcxx PUBLIC cxx_std_17 ) -target_link_libraries( exchcxx PUBLIC Libxc::xc ) +if( EXCHCXX_ENABLE_LIBXC ) + target_link_libraries( exchcxx PUBLIC Libxc::xc ) +endif() # Generate exchcxx_config.hpp configure_file( diff --git a/src/cuda/exchcxx_cuda.cmake b/src/cuda/exchcxx_cuda.cmake index b816919..27f9cf8 100644 --- a/src/cuda/exchcxx_cuda.cmake +++ b/src/cuda/exchcxx_cuda.cmake @@ -1,8 +1,10 @@ set( EXCHCXX_CUDA_SOURCES cuda/xc_functional_device.cu - cuda/libxc_device.cxx cuda/builtin.cu ) +if( EXCHCXX_ENABLE_LIBXC ) + list(APPEND EXCHCXX_CUDA_SOURCES cuda/libxc_device.cxx) +endif() find_package( CUDAToolkit REQUIRED ) #add_library( exchcxx_device OBJECT ${EXCHCXX_CUDA_SOURCES} ) diff --git a/src/hip/exchcxx_hip.cmake b/src/hip/exchcxx_hip.cmake index 87ea219..5aa9c64 100644 --- a/src/hip/exchcxx_hip.cmake +++ b/src/hip/exchcxx_hip.cmake @@ -1,8 +1,10 @@ set( EXCHCXX_HIP_SOURCES hip/xc_functional_device.hip - hip/libxc_device.hip hip/builtin.hip ) +if( EXCHCXX_ENABLE_LIBXC ) + list(APPEND EXCHCXX_HIP_SOURCES hip/libxc_device.hip) +endif() find_package( hip REQUIRED ) diff --git a/src/sycl/exchcxx_sycl.cmake b/src/sycl/exchcxx_sycl.cmake index 5646976..c1f80f5 100644 --- a/src/sycl/exchcxx_sycl.cmake +++ b/src/sycl/exchcxx_sycl.cmake @@ -1,8 +1,10 @@ set( EXCHCXX_SYCL_SOURCES sycl/xc_functional_device.cxx - sycl/libxc_device.cxx sycl/builtin_sycl.cxx ) +if( EXCHCXX_ENABLE_LIBXC ) + list(APPEND EXCHCXX_SYCL_SOURCES sycl/libxc_device.cxx) +endif() target_sources( exchcxx PRIVATE ${EXCHCXX_SYCL_SOURCES} ) diff --git a/src/xc_kernel.cxx b/src/xc_kernel.cxx index 87bead4..2fd052e 100644 --- a/src/xc_kernel.cxx +++ b/src/xc_kernel.cxx @@ -92,10 +92,12 @@ XCKernel::XCKernel( const Spin polar) : XCKernel( kernel_factory( backend, kern, polar ) ) { } +#ifdef EXCHCXX_ENABLE_LIBXC XCKernel::XCKernel( const libxc_name_string& xc_name, const Spin polar) : XCKernel( libxc_kernel_factory( xc_name.get(), polar ) ) { } +#endif XCKernel::XCKernel( impl_ptr&& ptr ) :