Skip to content
Permalink
Browse files

cmake build of exported library works, ready for 2.6.0-beta.2

  • Loading branch information...
evaleev committed May 16, 2019
1 parent 6210f6f commit 53c8981799915ac11c34505f2f6f3782ff5cd1ef
@@ -3,6 +3,11 @@

Following is a brief summary of changes made in each release of Libint.

- 2019-05-16: 2.6.0-beta.2
- initial support for CMake build of exported library; for consistency, renamed imported targets in FindLibint2.cmake
introduced in beta.1
- resolved issue #127: incorrect dimensions of 3-center ERI function pointer array used by Fortran interface

- 2019-05-07: 2.6.0-beta.1
- can read PBC-extended XYZ files
- provided (pkg-config based) FindLibint2.cmake module for CMake projects
@@ -27,8 +27,8 @@
#
# and the following imported targets
#
# Libint2::Libint - library only
# Libint2::LibintCXX - library + C++11 API; may need to add dependence on Eigen3 and/or Boost.Preprocessor if
# Libint2::int2 - library only
# Libint2::cxx - library + C++11 API; may need to add dependence on Eigen3 and/or Boost.Preprocessor if
# was not found by Libint at configure time
#
# Author: Eduard Valeyev - libint@valeyev.net
@@ -87,24 +87,24 @@ if (PKG_CONFIG_FOUND)
endif()

if(LIBINT2_FOUND AND NOT TARGET Libint2::Libint)
add_library(Libint2::Libint INTERFACE IMPORTED)
set_target_properties(Libint2::Libint PROPERTIES
add_library(Libint2::int2 INTERFACE IMPORTED)
set_target_properties(Libint2::int2 PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LIBINT2_INCLUDE_DIR};${LIBINT2_INCLUDE_DIR}/libint2"
)
set_target_properties(Libint2::Libint PROPERTIES
set_target_properties(Libint2::int2 PROPERTIES
INTERFACE_LINK_LIBRARIES ${LIBINT2_LIBRARY}
)
set_target_properties(Libint2::int2 PROPERTIES
INTERFACE_COMPILE_FEATURES "cxx_std_11"
)
endif()

if(LIBINT2_FOUND AND NOT TARGET Libint2::LibintCXX)
add_library(Libint2::LibintCXX INTERFACE IMPORTED)
set_target_properties(Libint2::LibintCXX PROPERTIES
if(LIBINT2_FOUND AND NOT TARGET Libint2::cxx)
add_library(Libint2::cxx INTERFACE IMPORTED)
set_target_properties(Libint2::cxx PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LIBINT2_INCLUDE_DIRS}"
)
set_target_properties(Libint2::LibintCXX PROPERTIES
INTERFACE_COMPILE_FEATURES "cxx_std_11"
)
target_link_libraries(Libint2::LibintCXX INTERFACE Libint2::Libint)
target_link_libraries(Libint2::cxx INTERFACE Libint2::int2)
endif()

else(PKG_CONFIG_FOUND)
@@ -117,8 +117,11 @@ exportdir::
$(INSTALL) $(INSTALLDIROPT) $(TOPDIR)/$(EXPORTDIR)/external
-$(INSTALL) $(INSTALLLIBOPT) $(SRCTOPDIR)/external/boost.tar.gz $(TOPDIR)/$(EXPORTDIR)/external/boost.tar.gz
$(TOPOBJDIR)/config.status --config > $(TOPDIR)/$(EXPORTDIR)/compiler.config
-$(INSTALL) $(INSTALLLIBOPT) $(SRCTOPDIR)/CMakeLists.txt.export $(TOPDIR)/$(EXPORTDIR)/CMakeLists.txt
-$(INSTALL) $(INSTALLLIBOPT) $(SRCDIR)/cmake/CMakeLists.txt.export $(TOPDIR)/$(EXPORTDIR)/CMakeLists.txt
-$(INSTALL) $(INSTALLLIBOPT) $(SRCDIR)/cmake/CMakeLists.txt.include.export $(TOPDIR)/$(EXPORTDIR)/include/CMakeLists.txt
$(INSTALL) $(INSTALLDIROPT) $(TOPDIR)/$(EXPORTDIR)/cmake
-$(INSTALL) $(INSTALLLIBOPT) $(SRCDIR)/cmake/libint2-config.cmake.in $(TOPDIR)/$(EXPORTDIR)/cmake/libint2-config.cmake.in
-$(INSTALL) $(INSTALLLIBOPT) $(SRCDIR)/cmake/hftest.cmake $(TOPDIR)/$(EXPORTDIR)/cmake/hftest.cmake
$(INSTALL) $(INSTALLDIROPT) $(TOPDIR)/$(EXPORTDIR)/cmake/modules
-$(INSTALL) $(INSTALLLIBOPT) $(SRCDIR)/cmake/modules/*.cmake $(TOPDIR)/$(EXPORTDIR)/cmake/modules
echo "set(LIBINT2_LIBRARY_CXX_SRC" > $(TOPDIR)/$(EXPORTDIR)/srclist.cmake
@@ -28,7 +28,7 @@ if (NOT LIBINT2_REALTYPE)
endif()

if (ENABLE_FORTRAN)
enable_language(FORTRAN)
enable_language(../fortran)
endif(ENABLE_FORTRAN)

# SHG ordering
@@ -58,10 +58,10 @@ endif()

find_package(Eigen3)
if (EIGEN3_FOUND)
add_library(Libint2_Eigen INTERFACE)
set_property(TARGET Libint2_Eigen PROPERTY
add_library(Eigen INTERFACE)
set_property(TARGET Eigen PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${EIGEN3_INCLUDE_DIR})
install(TARGETS Libint2_Eigen EXPORT libint COMPONENT libint)
install(TARGETS Eigen EXPORT libint2 COMPONENT Eigen)
set(LIBINT_HAS_EIGEN 1)
endif (EIGEN3_FOUND)

@@ -84,8 +84,17 @@ if (Boost_FOUND)

cmake_pop_check_state()

else (Boost_FOUND)

execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xzf ../../external/boost.tar.gz
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/include/libint2
)

endif(Boost_FOUND)

find_package(PythonInterp)

# Set install paths ====================================================================================================

set(LIBINT2_INSTALL_BINDIR "bin"
@@ -110,7 +119,7 @@ foreach(FN IN LISTS LIBINT2_LIBRARY_CXX_SRC)
list(APPEND LIB_CXX_SRC "src/${FN}")
endforeach()
add_library(int2 ${LIB_CXX_SRC})
target_include_directories(int2 PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_include_directories(int2 PRIVATE include)
target_include_directories(int2 INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> $<BUILD_INTERFACE:${PROJECT_BUILD_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BUILD_DIR}/include/libint2>
@@ -123,20 +132,36 @@ if (TARGET MPFR::GMPXX)
target_link_libraries(int2 PUBLIC MPFR::GMPXX)
endif()

# Add library to the list of installed components
install(TARGETS int2 EXPORT libint2
COMPONENT int2
LIBRARY DESTINATION "${LIBINT2_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${LIBINT2_INSTALL_LIBDIR}"
# includes are installed by the include/CMakeLists.txt.include.export
# INCLUDES DESTINATION "${LIBINT2_INSTALL_INCLUDEDIR}"
)
add_subdirectory(include)

# LibintCXX library ====================================================================================================

if (LIBINT_HAS_EIGEN)
add_library(Libint2_LibraryCXX INTERFACE)
target_compile_features(Libint2_LibraryCXX INTERFACE "cxx_std_11")
target_link_libraries(Libint2_LibraryCXX INTERFACE int2 Libint2_Eigen)
add_library(cxx INTERFACE)
target_compile_features(cxx INTERFACE "cxx_std_11")
target_link_libraries(cxx INTERFACE int2 Eigen)
if (LIBINT_HAS_SYSTEM_BOOST_PREPROCESSOR_VARIADICS)
target_include_directories(Libint2_LibraryCXX INTERFACE ${Boost_INCLUDE_DIR})
else(LIBINT_HAS_SYSTEM_BOOST_PREPROCESSOR_VARIADICS)
message(FATAL_ERROR "unpacking bundled Boost not supported yet")
target_include_directories(cxx INTERFACE ${Boost_INCLUDE_DIR})
endif(LIBINT_HAS_SYSTEM_BOOST_PREPROCESSOR_VARIADICS)
set(DATADIR_ABSOLUTE ${LIBINT2_INSTALL_DATADIR})
target_compile_definitions(Libint2_LibraryCXX INTERFACE
target_compile_definitions(cxx INTERFACE
$<BUILD_INTERFACE:SRCDATADIR="${PROJECT_SOURCE_DIR}/lib/basis">)
# Add library to the list of installed components
install(TARGETS cxx EXPORT libint2
COMPONENT cxx
LIBRARY DESTINATION "${LIBINT2_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${LIBINT2_INSTALL_LIBDIR}"
# includes are installed by the include/CMakeLists.txt.include.export
# INCLUDES DESTINATION "${LIBINT2_INSTALL_INCLUDEDIR}"
)
endif(LIBINT_HAS_EIGEN)

# Tests ====================================================================================================
@@ -163,8 +188,7 @@ set(utests_src
)

add_executable(unit_tests EXCLUDE_FROM_ALL tests/unit/test.cc ${utests_src})
target_link_libraries(unit_tests Libint2_LibraryCXX)
target_compile_definitions(unit_tests PUBLIC ${TEST_FEATURE_DEFINITIONS})
target_link_libraries(unit_tests cxx)
add_test(unit/build "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target unit_tests)
set_tests_properties(unit/build PROPERTIES FIXTURES_SETUP UNIT_TESTS_EXEC)
add_test(NAME unit/run
@@ -175,7 +199,6 @@ set_tests_properties(unit/run
add_executable(eritest EXCLUDE_FROM_ALL tests/eri/test.cc)
target_link_libraries(eritest int2)
target_include_directories(eritest PRIVATE ${CMAKE_SOURCE_DIR}/tests/eri)
target_compile_definitions(eritest PRIVATE ${TEST_FEATURE_DEFINITIONS})
add_test(eritest/build "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target eritest)
set_tests_properties(eritest/build PROPERTIES FIXTURES_SETUP ERITEST_EXEC)
add_test(NAME eritest/run0
@@ -191,6 +214,44 @@ add_test(NAME eritest/run2
set_tests_properties(eritest/run2
PROPERTIES FIXTURES_REQUIRED ERITEST_EXEC)

add_executable(hartree-fock EXCLUDE_FROM_ALL tests/hartree-fock/hartree-fock.cc)
target_link_libraries(hartree-fock cxx)
add_test(hftest/build "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target hartree-fock)
set_tests_properties(hftest/build PROPERTIES FIXTURES_SETUP HFTEST_EXEC)
if (PYTHONINTERP_FOUND)
add_test(NAME hftest/run
COMMAND COMMAND ${CMAKE_COMMAND}
-DtestName=hartree-fock
-DtestArgs=${CMAKE_SOURCE_DIR}/tests/hartree-fock/h2o.xyz
-DsrcDir=${CMAKE_SOURCE_DIR}
-DpythonExec=${PYTHON_EXECUTABLE}
-P ${CMAKE_SOURCE_DIR}/tests/hartree-fock/hftest.cmake)
else()
add_test(NAME hftest/run
COMMAND $<TARGET_FILE:hartree-fock> ${CMAKE_SOURCE_DIR}/tests/hartree-fock/h2o.xyz)
endif()
set_tests_properties(hftest/run
PROPERTIES FIXTURES_REQUIRED HFTEST_EXEC)

add_executable(hartree-fock++ EXCLUDE_FROM_ALL tests/hartree-fock/hartree-fock++.cc)
target_link_libraries(hartree-fock++ cxx)
add_test(hf++test/build "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target hartree-fock++)
set_tests_properties(hf++test/build PROPERTIES FIXTURES_SETUP HFXXTEST_EXEC)
if (PYTHONINTERP_FOUND)
add_test(NAME hf++test/run
COMMAND COMMAND ${CMAKE_COMMAND}
-DtestName=hartree-fock++
-DtestArgs=${CMAKE_SOURCE_DIR}/tests/hartree-fock/h2o_rotated.xyz
-DsrcDir=${CMAKE_SOURCE_DIR}
-DpythonExec=${PYTHON_EXECUTABLE}
-P ${CMAKE_SOURCE_DIR}/tests/hartree-fock/hftest.cmake)
else()
add_test(NAME hf++test/run
COMMAND $<TARGET_FILE:hartree-fock++> ${CMAKE_SOURCE_DIR}/tests/hartree-fock/h2o_rotated.xyz)
endif()
set_tests_properties(hf++test/run
PROPERTIES FIXTURES_REQUIRED HFXXTEST_EXEC)

# Configure files ======================================================================================================

configure_file(
@@ -200,13 +261,13 @@ configure_file(
)

configure_file(
${PROJECT_SOURCE_DIR}/include/libint2/basis.h.in
include/libint2/basis.h.in
${PROJECT_BINARY_DIR}/include/libint2/basis.h
@ONLY
)

configure_file(
${PROJECT_SOURCE_DIR}/libint2.pc.in
libint2.pc.in
${PROJECT_BINARY_DIR}/libint2.pc
@ONLY
)
@@ -219,31 +280,28 @@ install(FILES ${PROJECT_BINARY_DIR}/libint2.pc
write_basic_package_version_file(libint2-config-version.cmake
VERSION ${LIBINT_VERSION} COMPATIBILITY AnyNewerVersion)

# Create the targets file
#export(EXPORT libint2
# FILE "${PROJECT_BINARY_DIR}/libint2-targets.cmake")

## Create the configure file
#configure_package_config_file(cmake/mpqc-config.cmake.in
# "${PROJECT_BINARY_DIR}/mpqc-config.cmake"
# INSTALL_DESTINATION "${LIBINT2_INSTALL_CMAKEDIR}"
# PATH_VARS CMAKE_INSTALL_PREFIX LIBINT2_INSTALL_BINDIR
# LIBINT2_INSTALL_INCLUDEDIR LIBINT2_INSTALL_LIBDIR
# LIBINT2_INSTALL_DOCDIR LIBINT2_INSTALL_CMAKEDIR)
#
configure_package_config_file(cmake/libint2-config.cmake.in
"${PROJECT_BINARY_DIR}/libint2-config.cmake"
INSTALL_DESTINATION "${LIBINT2_INSTALL_CMAKEDIR}"
PATH_VARS CMAKE_INSTALL_PREFIX LIBINT2_INSTALL_BINDIR
LIBINT2_INSTALL_INCLUDEDIR LIBINT2_INSTALL_LIBDIR
LIBINT2_INSTALL_DOCDIR LIBINT2_INSTALL_CMAKEDIR)

## Install config, version, and target files
#install(EXPORT libint2
# FILE "libint2-targets.cmake"
# DESTINATION "${LIBINT2_INSTALL_CMAKEDIR}"
# COMPONENT libint2-config)
#install(FILES
# "${PROJECT_BINARY_DIR}/libint2-config.cmake"
# "${PROJECT_BINARY_DIR}/libint2-config-version.cmake"
# DESTINATION "${LIBINT2_INSTALL_CMAKEDIR}"
# COMPONENT libint2-config)
#add_custom_target(install-config
# COMMAND ${CMAKE_COMMAND} -DCOMPONENT=libint2-config -P ${CMAKE_BINARY_DIR}/cmake_install.cmake
# COMMENT "Installing Libint2 config components")
install(EXPORT libint2
FILE "libint2-targets.cmake"
DESTINATION "${LIBINT2_INSTALL_CMAKEDIR}"
NAMESPACE Libint2::
COMPONENT libint2-config)
install(FILES
"${PROJECT_BINARY_DIR}/libint2-config.cmake"
"${PROJECT_BINARY_DIR}/libint2-config-version.cmake"
DESTINATION "${LIBINT2_INSTALL_CMAKEDIR}"
COMPONENT libint2-config)
add_custom_target(install-config
COMMAND ${CMAKE_COMMAND} -DCOMPONENT=libint2-config -P ${CMAKE_BINARY_DIR}/cmake_install.cmake
COMMENT "Installing Libint2 config components")

feature_summary(WHAT ALL
DESCRIPTION "=== Libint2 Package/Feature Info ===")
@@ -0,0 +1,17 @@

install(DIRECTORY libint2
COMPONENT int2
DESTINATION "${LIBINT2_INSTALL_INCLUDEDIR}"
)
install(FILES libint2.h
COMPONENT int2
DESTINATION "${LIBINT2_INSTALL_INCLUDEDIR}"
)
install(FILES libint2_params.h libint2_iface.h libint2_types.h
COMPONENT int2
DESTINATION "${LIBINT2_INSTALL_INCLUDEDIR}/libint2"
)
install(FILES libint2.hpp
COMPONENT cxx
DESTINATION "${LIBINT2_INSTALL_INCLUDEDIR}"
)
@@ -0,0 +1,44 @@

macro(runtest)

set(OUTPUT_FILE_NAME "${CMAKE_BINARY_DIR}/tests/hartree-fock/${testName}.out")

set(CHECK_CMD "${pythonExec}" "${srcDir}/tests/hartree-fock/${testName}-validate.py")
if (${testName} STREQUAL "hartree-fock++")
set(CHECK_ARGS "${srcDir}/MakeVars.features")
endif()

execute_process(COMMAND
${CMAKE_BINARY_DIR}/${testName} ${testArgs}
OUTPUT_FILE "${OUTPUT_FILE_NAME}"
RESULT_VARIABLE TEST_RESULT)

if(TEST_RESULT)
message(STATUS "\nOUTPUT of " ${testName} " with args " ${testArgs})
execute_process(COMMAND
cat
${OUTPUT_FILE_NAME}
RESULT_VARIABLE
CAT_RESULT
)
message(FATAL_ERROR "Error running ${CMAKE_BINARY_DIR}/${testName}")
endif(TEST_RESULT)

execute_process(COMMAND
${CHECK_CMD} ${CHECK_ARGS} ${OUTPUT_FILE_NAME}
RESULT_VARIABLE CHECK_RESULT)

if(CHECK_RESULT)
message(STATUS "\nOUTPUT of " ${testName})
execute_process(COMMAND
cat
${OUTPUT_FILE_NAME}
RESULT_VARIABLE
CAT_RESULT
)
message(FATAL_ERROR "Error running ${CHECK_CMD} with args " ${CHECK_ARGS} ${OUTPUT_FILE_NAME})
endif(CHECK_RESULT)

endmacro(runtest)

runtest()
@@ -0,0 +1,32 @@
# - CMAKE Config file for the Libint2 package
# This will define the following CMake cache variables
#
# LIBINT2_FOUND - true if libint2.h header and libint2 library were found
# LIBINT2_VERSION - the libint2 version
# LIBINT2_INCLUDE_DIRS - (deprecated: use the CMake IMPORTED targets listed below) list of libint2 include directories
# LIBINT2_LIBRARIES - (deprecated: use the CMake IMPORTED targets listed below) list of libint2 libraries
#
# and the following imported targets
#
# Libint2::int2 - library only
# Libint2::cxx - (if Eigen + Boost was found at the library configure time) library + C++11 API
#
# Author: Eduard Valeyev - libint@valeyev.net

# Set package version
set(LIBINT2_VERSION "@PACKAGE_VERSION@")

@PACKAGE_INIT@

set(LIBINT2_LIBRARIES Libint2::int2)
set(LIBINT2_INCLUDE_DIRS "@PACKAGE_LIBINT2_INSTALL_INCLUDEDIR@")

# Include library IMPORT targets
if(NOT TARGET Libint2::int2)
include("${CMAKE_CURRENT_LIST_DIR}/libint2-targets.cmake")
if(NOT TARGET Libint2::int2)
message(FATAL_ERROR "expected Libint2::int2 among imported Libint2 targets")
endif()
endif()

set(LIBINT2_FOUND TRUE)

0 comments on commit 53c8981

Please sign in to comment.
You can’t perform that action at this time.