From ee93781e5a70f782f83051b92185bc93a2ebf641 Mon Sep 17 00:00:00 2001 From: "Lori A. Burns" Date: Sat, 6 Jan 2024 02:38:49 -0500 Subject: [PATCH] base lib take 2 take 3 take 4 take 5 take 6 take 7 take 8 take 9 take 10 take 11 take 12 take 13 take 14 --- .github/workflows/ci_cmake.yml | 152 ++++++++++++++++++++++- .github/workflows/cmake.yml | 2 +- CMakeLists.txt | 24 +++- INSTALL.md | 2 + cmake/modules/DynamicVersion.cmake | 54 ++++----- include/libint2/config2.h.cmake.in | 2 +- src/bin/CMakeLists.txt | 3 +- src/bin/libint/CMakeLists.txt | 4 +- src/lib/libint/CMakeLists.txt | 51 +++++++- src/lib/libint/CMakeLists.txt.export | 175 ++++++++++++++++++++++++++- src/lib/libint/populate.cmake | 52 ++++++++ tests/CMakeLists.txt | 86 +++++++++++++ 12 files changed, 556 insertions(+), 51 deletions(-) create mode 100644 tests/CMakeLists.txt diff --git a/.github/workflows/ci_cmake.yml b/.github/workflows/ci_cmake.yml index 3edba671b..961012401 100644 --- a/.github/workflows/ci_cmake.yml +++ b/.github/workflows/ci_cmake.yml @@ -20,6 +20,10 @@ jobs: - os: macos-latest cxx: clang++ cc: clang + - build_type: Release + build_shared_libs: ON + - build_type: Debug + build_shared_libs: OFF name: "Repo • ${{ matrix.os }}: ${{ matrix.cxx }} ${{ matrix.build_type }}" runs-on: ${{ matrix.os }} @@ -32,7 +36,7 @@ jobs: BUILD_CONFIG : > -G Ninja -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} - -DBUILD_SHARED_LIBS=OFF + -DBUILD_SHARED_LIBS=${{ matrix.build_shared_libs }} -DMPIEXEC_PREFLAGS='--bind-to;none;--allow-run-as-root' -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/build/library -DWITH_MAX_AM=2;2 @@ -112,10 +116,154 @@ jobs: cmake -S ../.. -B build $BUILD_CONFIG --log-level=DEBUG cmake --build build --target check-libint2compiler + - name: Generate Libint export + if: ${{ steps.skip_check.outputs.should_skip != 'true' }} + shell: bash + working-directory: ${{github.workspace}}/build/compiler + run: | + cmake --build build --target export + cd build && echo "ARTIFACT=`ls -1 libint*tgz`" >> $GITHUB_ENV + + - name: Archive Library Tarball + if: ${{ steps.skip_check.outputs.should_skip != 'true' && matrix.build_type == 'Release'}} + uses: actions/upload-artifact@v3 + with: + if-no-files-found: error + name: ${{ runner.os }}-${{ matrix.cxx }} + path: ${{github.workspace}}/build/compiler/build/${{ env.ARTIFACT }} + retention-days: 1 + - name: Generate Libint library if: ${{ steps.skip_check.outputs.should_skip != 'true' }} shell: bash working-directory: ${{github.workspace}}/build/compiler run: | - cmake --build build --target libint-library-generate + cmake --build build --target library check-libint2 + cd build && echo "ARTIFACT=`ls -1 libint*tgz`" >> $GITHUB_ENV + +#rm -rf buildcm/ && cmake -S. -Bbuildcm -GNinja -DEXPORT_COMPRESSOR=bzip2 -DWITH_MAX_AM="2;2" -DWITH_ERI_MAX_AM="2;2" -DWITH_ERI3_MAX_AM="3;2" -DENABLE_ERI=1 -DENABLE_ERI3=1 -DMULTIPOLE_MAX_ORDER=2 -DBUILD_SHARED_LIBS=ON && time cmake --build buildcm --target check-libint2 + + build_export: + needs: build_repo + if: always() && (needs.build_repo.outputs.should_skip != 'true') + strategy: + fail-fast: false + matrix: + cfg: + - runs-on: ubuntu-latest + lane: ubuntu-gnu + libargs: > + -DBUILD_SHARED_LIBS=ON + testargs: "" + + - runs-on: windows-latest + lane: windows-clang-cl + libargs: > + -GNinja + -DCMAKE_BUILD_TYPE=Release + -DBUILD_SHARED_LIBS=OFF + -DCMAKE_CXX_COMPILER=clang-cl + -DCMAKE_C_COMPILER=clang-cl + testargs: > + -GNinja + -DCMAKE_BUILD_TYPE=Release + -DCMAKE_CXX_COMPILER=clang-cl + -DCMAKE_C_COMPILER=clang-cl + + - runs-on: macos-latest + lane: macos-clang + libargs: > + -DBUILD_SHARED_LIBS=ON + testargs: "" + + - runs-on: ubuntu-latest + lane: ubuntu-intel + libargs: > + -DCMAKE_CXX_COMPILER=icpx + -DCMAKE_CXX_FLAGS="--gcc-toolchain=${CONDA_PREFIX} --sysroot=${CONDA_PREFIX}/${HOST}/sysroot -target ${HOST}" + testargs: > + -DCMAKE_CXX_COMPILER=icpx + -DCMAKE_CXX_FLAGS="--gcc-toolchain=${CONDA_PREFIX} --sysroot=${CONDA_PREFIX}/${HOST}/sysroot -target ${HOST}" + + name: "Export • ${{ matrix.cfg.lane }}" + runs-on: ${{ matrix.cfg.runs-on }} + + steps: + # Note we're not checking out the repo. All src from Linux tarball generated above. + + - name: Write a Conda Env File + shell: bash -l {0} + run: | + cat > export.yaml <>> @@ -269,6 +269,8 @@ option_with_print(LIBINT_PROFILE "Turn on profiling instrumentation of the library. (Generated code will require C++11!)" OFF) option_with_print(LIBINT2_ENABLE_MPFR "Use GNU MPFR library for high-precision testing (EXPERTS ONLY). Consumed at library build-time." OFF) +option_with_default(EXPORT_COMPRESSOR + "Export tarball with compression gzip or bzip2" gzip) # next one defined by `include(CTest)` message(STATUS "Showing option BUILD_TESTING: ${BUILD_TESTING}") @@ -305,6 +307,16 @@ booleanize01(LIBINT_ACCUM_INTS) booleanize01(LIBINT_FLOP_COUNT) booleanize01(LIBINT_PROFILE) +if (EXPORT_COMPRESSOR STREQUAL "gzip") + set(EXPORT_COMPRESSOR_CMD "cfz") + set(EXPORT_COMPRESSOR_EXT "tgz") +elseif (EXPORT_COMPRESSOR STREQUAL "bzip2") + set(EXPORT_COMPRESSOR_CMD "jcf") + set(EXPORT_COMPRESSOR_EXT "tbz2") +else() + message(FATAL_ERROR "No valid compressor; invoke CMake with -DEXPORT_COMPRESSOR=gzip|bzip2") +endif() + ################################## Dependencies ################################# diff --git a/INSTALL.md b/INSTALL.md index c8ed17886..529ae3e9c 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -267,6 +267,8 @@ Note that options, docs, and CMake components are focused on the C++ interface, ### Build Library How (G L) (TARBALL) * `CMAKE_BUILD_TYPE` — G L — [Standard CMake variable](https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html) [Default=Release] +* `BUILD_SHARED_LIBS` — L — Build Libint library as shared, not static. [Standard CMake variable](https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html) [Default=OFF] +* `LIBINT2_BUILD_SHARED_AND_STATIC_LIBS` — L — Build both shared and static Libint libraries in one shot. Uses `-fPIC`. [Default=OFF] ### Detecting Dependencies (G L C) (TARBALL) diff --git a/cmake/modules/DynamicVersion.cmake b/cmake/modules/DynamicVersion.cmake index 6c1b88c2a..c50be9de4 100644 --- a/cmake/modules/DynamicVersion.cmake +++ b/cmake/modules/DynamicVersion.cmake @@ -15,6 +15,11 @@ Helper module to get the project's version dynamically. Format is compatible wit include_guard() list(APPEND CMAKE_MESSAGE_CONTEXT DynamicVersion) +if (POLICY CMP0140) + # Enable using return(PROPAGATE) + # TODO: Remove when cmake 3.25 is commonly distributed + cmake_policy(SET CMP0140 NEW) +endif () #[==============================================================================================[ # Preparations # @@ -118,9 +123,6 @@ function(dynamic_version) `${OUTPUT_FOLDER}/.git_commit` Current commit - `${OUTPUT_FOLDER}/.git_distance` - Current git distance from tag - ## See also - [pypa/setuptools_scm](https://github.com/pypa/setuptools_scm) @@ -227,10 +229,14 @@ function(dynamic_version) COMMAND_ERROR_IS_FATAL ANY) # Copy all configured files - foreach (file IN ITEMS .DynamicVersion.json .version .git_describe .git_commit .git_distance) - if (EXISTS ${file}) - file(COPY_FILE ${ARGS_TMP_FOLDER}/${file} ${ARGS_OUTPUT_FOLDER}/${file}) - endif () + foreach (file IN ITEMS .DynamicVersion.json .version .git_describe .git_commit) + if (EXISTS ${ARGS_TMP_FOLDER}/${file}) + if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.21) + file(COPY_FILE ${ARGS_TMP_FOLDER}/${file} ${ARGS_OUTPUT_FOLDER}/${file}) + else () + file(COPY ${ARGS_TMP_FOLDER}/${file} DESTINATION ${ARGS_OUTPUT_FOLDER}/) + endif () + endif () endforeach () # Check configuration state @@ -359,13 +365,13 @@ function(get_dynamic_version) # Set fallback values if (DEFINED ARGS_FALLBACK_VERSION) string(JSON data SET - ${data} version ${ARGS_FALLBACK_VERSION}) + ${data} version \"${ARGS_FALLBACK_VERSION}\") file(WRITE ${ARGS_TMP_FOLDER}/.DynamicVersion.json ${data}) file(WRITE ${ARGS_TMP_FOLDER}/.version ${ARGS_FALLBACK_VERSION}) endif () if (DEFINED ARGS_FALLBACK_HASH) string(JSON data SET - ${data} commit ${ARGS_FALLBACK_HASH}) + ${data} commit \"${ARGS_FALLBACK_HASH}\") file(WRITE ${ARGS_TMP_FOLDER}/.DynamicVersion.json ${data}) file(WRITE ${ARGS_TMP_FOLDER}/.git_commit ${ARGS_FALLBACK_HASH}) endif () @@ -403,8 +409,11 @@ function(get_dynamic_version) ${data} version \"${CMAKE_MATCH_2}\") file(WRITE ${ARGS_TMP_FOLDER}/.version ${CMAKE_MATCH_2}) # Get commit hash + # Cannot use Regex match from here, need to run string(REGEX MATCH) again + # https://gitlab.kitware.com/cmake/cmake/-/issues/23770 file(STRINGS ${ARGS_GIT_ARCHIVAL_FILE} node REGEX "^node:[ ]?(.*)") + string(REGEX MATCH "^node:[ ]?(.*)" node "${node}") string(JSON data SET ${data} commit \"${CMAKE_MATCH_1}\") file(WRITE ${ARGS_TMP_FOLDER}/.git_commit ${CMAKE_MATCH_1}) @@ -433,13 +442,13 @@ function(get_dynamic_version) OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY) # Get version and describe-name - execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --match=?[0-9.]* + execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --long --abbrev=8 --match=?[0-9.]* WORKING_DIRECTORY ${ARGS_PROJECT_SOURCE} OUTPUT_VARIABLE describe-name OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY) # Match any part containing digits and periods (strips out rc and so on) - if (NOT describe-name MATCHES "^([v]?([0-9\\.]+).*)") + if (NOT describe-name MATCHES "^([v]?([0-9\\.]+)-([0-9]+)-g(.*))") message(${error_message_type} "Version tag is ill-formatted\n" " Describe-name: ${describe-name}" @@ -452,26 +461,13 @@ function(get_dynamic_version) string(JSON data SET ${data} version \"${CMAKE_MATCH_2}\") file(WRITE ${ARGS_TMP_FOLDER}/.version ${CMAKE_MATCH_2}) + string(JSON data SET + ${data} distance \"${CMAKE_MATCH_3}\") + string(JSON data SET + ${data} short_sha \"${CMAKE_MATCH_4}\") string(JSON data SET ${data} commit \"${git-hash}\") file(WRITE ${ARGS_TMP_FOLDER}/.git_commit ${git-hash}) - # Get full describe with distance - execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --long --match=?[0-9.]* - WORKING_DIRECTORY ${ARGS_PROJECT_SOURCE} - OUTPUT_VARIABLE describe-name-long - OUTPUT_STRIP_TRAILING_WHITESPACE - COMMAND_ERROR_IS_FATAL ANY) - # Match version (as above) and distance - if (NOT describe-name-long MATCHES "^([v]?([0-9\\.]+)-([0-9]+)-.*)") - message(${error_message_type} - "Version tag is ill-formatted\n" - " Describe-name-long: ${describe-name-long}" - ) - return() - endif () - string(JSON data SET - ${data} distance \"${CMAKE_MATCH_3}\") - file(WRITE ${ARGS_TMP_FOLDER}/.git_distance ${CMAKE_MATCH_3}) message(DEBUG "Found appropriate tag from git" ) @@ -507,3 +503,5 @@ if (DynamicVersion_RUN) endif () get_dynamic_version(${DynamicVersion_ARGS}) endif () + +list(POP_BACK CMAKE_MESSAGE_CONTEXT) diff --git a/include/libint2/config2.h.cmake.in b/include/libint2/config2.h.cmake.in index 0344ee87b..66ea311f9 100644 --- a/include/libint2/config2.h.cmake.in +++ b/include/libint2/config2.h.cmake.in @@ -40,7 +40,7 @@ #define LIBINT2_ALIGN_SIZE @LIBINT2_ALIGN_SIZE@ /* User-defined real type */ -#cmakedefine LIBINT2_REALTYPE "@LIBINT2_REALTYPE@" +#cmakedefine LIBINT2_REALTYPE @LIBINT2_REALTYPE@ /* Specifies the ordering of solid harmonics Gaussians in a shell. Retired Jan 2023 in favor of becoming a generator-time-only option */ /* #cmakedefine LIBINT_SHGSHELL_ORDERING @LIBINT_SHGSHELL_ORDERING@ */ diff --git a/src/bin/CMakeLists.txt b/src/bin/CMakeLists.txt index 2bcf79f3a..7de67d430 100644 --- a/src/bin/CMakeLists.txt +++ b/src/bin/CMakeLists.txt @@ -2,8 +2,7 @@ add_subdirectory(libint) include(AddCustomTargetSubproject) add_custom_target_subproject( - libint2compiler - check + libint2compiler check # target check-libint2compiler USES_TERMINAL COMMAND ${CMAKE_CTEST_COMMAND} -V -R "libint2/compiler" ) diff --git a/src/bin/libint/CMakeLists.txt b/src/bin/libint/CMakeLists.txt index f9b82c565..532a6da97 100644 --- a/src/bin/libint/CMakeLists.txt +++ b/src/bin/libint/CMakeLists.txt @@ -39,15 +39,15 @@ target_compile_definitions( libint-libcompiler PUBLIC __COMPILING_LIBINT2=1 - # MSVC does not include constants, unless _USE_MATH_DEFINES is defined. $<$:_USE_MATH_DEFINES> + # MSVC does not include constants, unless _USE_MATH_DEFINES is defined. ) target_compile_options( libint-libcompiler PUBLIC + $<$:/EHsc> # Set the exception handling model (allows "throw") - $<$:"/EHsc"> ) target_compile_features( diff --git a/src/lib/libint/CMakeLists.txt b/src/lib/libint/CMakeLists.txt index c6f4e6c1d..e652bdccb 100644 --- a/src/lib/libint/CMakeLists.txt +++ b/src/lib/libint/CMakeLists.txt @@ -23,6 +23,11 @@ configure_file( "${EXPORT_STAGE_DIR}/features" @ONLY) +configure_file( + "${PROJECT_SOURCE_DIR}/include/libint2/basis.h.in" # TODO could move to basis.h.cmake.in when libtool retires + "include/libint2/basis.h" + @ONLY) + add_custom_command( OUTPUT ${EXPORT_STAGE_DIR}/CMakeLists.txt @@ -43,23 +48,39 @@ add_custom_target(libint-library-populate DEPENDS ${EXPORT_STAGE_DIR}/CMakeLists add_custom_command( OUTPUT - "${EXPORT_STAGE_DIR}.tgz" - COMMAND ${CMAKE_COMMAND} -E tar "cfz" "${EXPORT_STAGE_DIR}.tgz" "${EXPORT_STAGE_DIR}" + "${EXPORT_STAGE_DIR}.${EXPORT_COMPRESSOR_EXT}" + COMMAND ${CMAKE_COMMAND} -E tar ${EXPORT_COMPRESSOR_CMD} "${EXPORT_STAGE_DIR}.${EXPORT_COMPRESSOR_EXT}" "${EXPORT_STAGE_DIR}" DEPENDS libint-library-generate libint-library-populate WORKING_DIRECTORY "${EXPORT_STAGE_DIR}/.." COMMENT "Exporting tarball of Libint2 library source" ) -add_custom_target(libint-library-export DEPENDS "${EXPORT_STAGE_DIR}.tgz") + add_custom_target( + libint-library-export + DEPENDS + "${EXPORT_STAGE_DIR}.${EXPORT_COMPRESSOR_EXT}" + ) +add_custom_target(export DEPENDS libint-library-export) + +# <<< Build Library >>> - # <<< Build Library >>> +include(CheckLanguage) +check_language(C) +if(CMAKE_C_COMPILER) + enable_language(C) +else() + message(FATAL_ERROR "No C language support; invoke CMake with -D CMAKE_C_COMPILER=/path/to/C/compiler to resolve") +endif() include(ExternalProject) list(APPEND library_CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DBUILD_TESTING=${BUILD_TESTING} + -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} + -DLIBINT2_BUILD_SHARED_AND_STATIC_LIBS=${LIBINT2_BUILD_SHARED_AND_STATIC_LIBS} -DLIBINT2_ALIGN_SIZE=${LIBINT_ALIGN_SIZE} -DLIBINT2_REALTYPE=${LIBINT2_REALTYPE} -DLIBINT2_ENABLE_MPFR=${LIBINT2_ENABLE_MPFR} @@ -99,7 +120,7 @@ add_custom_target(libint-library-export DEPENDS "${EXPORT_STAGE_DIR}.tgz") BUILD_ALWAYS 1 # download generalized to generating source by unpacking source tarball # * DOWNLOAD_DIR is tidier but fails on Windows - URL "${EXPORT_STAGE_DIR}.tgz" + URL "${EXPORT_STAGE_DIR}.${EXPORT_COMPRESSOR_EXT}" LOG_DOWNLOAD 1 CMAKE_ARGS "${library_CMAKE_ARGS}" CMAKE_CACHE_ARGS @@ -108,5 +129,25 @@ add_custom_target(libint-library-export DEPENDS "${EXPORT_STAGE_DIR}.tgz") -DCMAKE_CXX_COMPILER_ARG1:STRING=${CMAKE_CXX_COMPILER_ARG1} -DCMAKE_C_COMPILER_ARG1:STRING=${CMAKE_C_COMPILER_ARG1} -DCMAKE_PREFIX_PATH:STRING=${CMAKE_PREFIX_PATH} + TEST_COMMAND "" + STEP_TARGETS build ) + ExternalProject_Get_property(library BINARY_DIR) + + if (BUILD_TESTING) + include(AddCustomTargetSubproject) + add_custom_target_subproject( + libint2 check # target check-libint2 + USES_TERMINAL + COMMAND ${CMAKE_CTEST_COMMAND} -V -R "libint2/" + WORKING_DIRECTORY ${BINARY_DIR} + DEPENDS + "library-build" + ) + endif() + install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/include/libint2/basis.h" + DESTINATION "${STAGED_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/libint2" + ) diff --git a/src/lib/libint/CMakeLists.txt.export b/src/lib/libint/CMakeLists.txt.export index 72e043505..48c42d0eb 100644 --- a/src/lib/libint/CMakeLists.txt.export +++ b/src/lib/libint/CMakeLists.txt.export @@ -29,12 +29,18 @@ set(pnv libint2) # projectnameversion # See "TARBALL" labels in INSTALL.md for elaboration of options, dependencies, & targets. ################################### Options #################################### +include(CTest) include(options) include(CheckFunctionExists) # <<< General >>> -option_with_default(CMAKE_BUILD_TYPE "Build type" Release) +option_with_default(CMAKE_BUILD_TYPE + "Build type" Release) +option_with_print(BUILD_SHARED_LIBS + "Build Libint library as shared, not static" OFF) +option_with_print(LIBINT2_BUILD_SHARED_AND_STATIC_LIBS + "Build both shared and static Libint libraries in one shot. Uses -fPIC." OFF) option_with_print(LIBINT2_ENABLE_MPFR "Use GNU MPFR library for high-precision testing (requires MPFR. EXPERTS ONLY)" OFF) option_with_print(LIBINT2_ENABLE_PYTHON @@ -52,12 +58,19 @@ if (HAVE_POSIX_MEMALIGN) option_with_default(LIBINT2_ALIGN_SIZE "(EXPERT) if posix_memalign is available, this will specify alignment of Libint data, in units of sizeof(LIBINT2_REALTYPE). Default is to use built-in heuristics." 0) mark_as_advanced(LIBINT2_ALIGN_SIZE) +elseif (MSVC) + set(HAVE_POSIX_MEMALIGN 1) # aliased in memory.h + set(LIBINT2_ALIGN_SIZE "0" CACHE STRING "") endif() option_with_default(LIBINT2_REALTYPE "Specifies the floating-point data type used by the library." double) include(int_userreal) +# <<< Miscellaneous >>> + +# next one defined by `include(CTest)` +message(STATUS "Showing option BUILD_TESTING: ${BUILD_TESTING}") # <<< Ordering Conventions >>> @@ -147,14 +160,168 @@ configure_file( include/libint2/config2.h.cmake.in include/libint2/config2.h @ONLY) -# configuration.cc defines a string summary of capabilities. @ONLY is maximally -# deferred in case config2 changes the summary (as it used to when -# LIBINT_SHGSHELL_ORDERING was library-config-time selected). configure_file( + # configuration.cc defines a string summary of capabilities. @ONLY is maximally + # deferred in case config2 changes the summary (as it used to when + # LIBINT_SHGSHELL_ORDERING was library-config-time selected). src/configuration.cc.cmake.in src/configuration.cc @ONLY) +include(srclist.cmake) +list(LENGTH LIBINT2_LIBRARY_CXX_SRC _source_count) +message(STATUS "Loading ${_source_count} library source files from LIBINT2_LIBRARY_CXX_SRC") +message(DEBUG "LIBINT2_LIBRARY_CXX_SRC=${LIBINT2_LIBRARY_CXX_SRC}") + +# Notes +# * __COMPILING_LIBINT2 is needed whenever using libint targets in the build tree +# * MSVC does not include constants, unless _USE_MATH_DEFINES is defined +# * /EHsc sets the exception handling model (allows "throw") + +add_library( + int-obj + OBJECT + "${LIBINT2_LIBRARY_CXX_SRC}" + "src/configuration.cc" + ) +target_compile_definitions( + int-obj + PRIVATE + -D__COMPILING_LIBINT2=1 + ) +target_compile_features( + int-obj + PUBLIC + "cxx_std_11" + # N.B. PUBLIC to make int-{static/shared} require C++11? + ) +set_target_properties( + int-obj + PROPERTIES + UNITY_BUILD TRUE # always use unity build for int-obj + ) +target_include_directories( + int-obj + PRIVATE + ${PROJECT_BINARY_DIR}/include/ + ${PROJECT_SOURCE_DIR}/src/ + ${PROJECT_SOURCE_DIR}/include/ + ${PROJECT_SOURCE_DIR}/include/libint2/ + ) + +if (MSVC) + set_target_properties( + int-obj + PROPERTIES + LINK_FLAGS "/STACK:4194304" + # Increase stack size from 1 MB to 4 MB + ) +endif() + + +if (BUILD_SHARED_LIBS OR LIBINT2_BUILD_SHARED_AND_STATIC_LIBS) + set(BUILD_SHARED_LIBS 1) + set_target_properties( + int-obj + PROPERTIES + POSITION_INDEPENDENT_CODE 1 + ) +endif() +if (NOT BUILD_SHARED_LIBS OR LIBINT2_BUILD_SHARED_AND_STATIC_LIBS) + set(BUILD_STATIC_LIBS 1) +endif() + +if (BUILD_SHARED_LIBS) + + add_library( + int-shared + SHARED + $ + ) + target_compile_features( + int-shared + INTERFACE + "cxx_std_11" + ) + target_compile_definitions( + int-shared + INTERFACE + $ + PUBLIC + $<$:_USE_MATH_DEFINES> + ) + target_compile_options( + int-shared + PUBLIC + $<$:/EHsc> + ) + target_include_directories( + int-shared + INTERFACE + $ + $ + $ + $ + ) + set_target_properties( + int-shared + PROPERTIES + OUTPUT_NAME "int2" + ) +endif() + +if (BUILD_STATIC_LIBS) + + add_library( + int-static + STATIC + $ + ) + target_compile_features( + int-static + INTERFACE + "cxx_std_11" + ) + target_compile_definitions( + int-static + INTERFACE + $ + PUBLIC + $<$:_USE_MATH_DEFINES> + ) + target_compile_options( + int-static + PUBLIC + $<$:/EHsc> + ) + target_include_directories( + int-static + INTERFACE + $ + $ + $ + $ + ) + set_target_properties( + int-static + PROPERTIES + OUTPUT_NAME "int2" + ) +endif() + +# Permanent aliases ============================================================= +# * used for tests + +if (BUILD_SHARED_LIBS) + add_library(${L2}::int2 ALIAS int-shared) +elseif (BUILD_STATIC_LIBS) + add_library(${L2}::int2 ALIAS int-static) +endif() + +if (BUILD_TESTING) + add_subdirectory(tests) +endif() + configure_package_config_file( cmake/${pnv}-config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${pnv}-config.cmake" diff --git a/src/lib/libint/populate.cmake b/src/lib/libint/populate.cmake index b6fb5d055..8e2b59ad5 100644 --- a/src/lib/libint/populate.cmake +++ b/src/lib/libint/populate.cmake @@ -1,5 +1,26 @@ set(LIBRARY_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src/lib/libint) +file( + INSTALL + "${LIBRARY_SOURCE_DIR}/../../../tests/" + DESTINATION "${EXPORT_STAGE_DIR}/tests" + FILES_MATCHING + PATTERN "*.c" + PATTERN "*.cc" + PATTERN "*.h" + PATTERN "*.hpp" + PATTERN "*.py" + PATTERN "*.xyz" + PATTERN "CMakeLists.txt" + ) + +file( + INSTALL + "${PROJECT_SOURCE_DIR}/src/bin/test_eri/eri.h" + "${PROJECT_SOURCE_DIR}/src/bin/test_eri/prep_libint2.h" + DESTINATION "${EXPORT_STAGE_DIR}/tests/eri" + ) + file( INSTALL "${PROJECT_SOURCE_DIR}/cmake/modules/autocmake_safeguards.cmake" @@ -10,6 +31,7 @@ file( "${PROJECT_SOURCE_DIR}/cmake/modules/int_checkboost.cmake" "${PROJECT_SOURCE_DIR}/cmake/modules/FindMultiprecision.cmake" "${PROJECT_SOURCE_DIR}/cmake/modules/FindEigen3.cmake" + "${PROJECT_SOURCE_DIR}/cmake/modules/AddCustomTargetSubproject.cmake" DESTINATION "${EXPORT_STAGE_DIR}/cmake/modules" ) @@ -24,9 +46,39 @@ configure_file( "${EXPORT_STAGE_DIR}/CMakeLists.txt" COPYONLY) + +# <<< Headers >>> + +file( + INSTALL + "${PROJECT_SOURCE_DIR}/include/libint2.h" + "${PROJECT_SOURCE_DIR}/include/libint2.hpp" + DESTINATION "${EXPORT_STAGE_DIR}/include" + ) +file( + INSTALL + "${PROJECT_SOURCE_DIR}/include/libint2/" + DESTINATION "${EXPORT_STAGE_DIR}/include/libint2" + FILES_MATCHING + PATTERN "*.h" + PATTERN "*.h.cmake.in" + ) +file( + INSTALL + "${LIBRARY_SOURCE_DIR}/" + DESTINATION "${EXPORT_STAGE_DIR}/include/libint2" + FILES_MATCHING + PATTERN "*.h" + ) + + +# <<< Source >>> + file( INSTALL "${PROJECT_SOURCE_DIR}/src/lib/libint/configuration.cc.cmake.in" DESTINATION "${EXPORT_STAGE_DIR}/src" ) +file(GLOB generated_sources_list RELATIVE "${EXPORT_STAGE_DIR}" "${EXPORT_STAGE_DIR}/src/*.cc") +file(WRITE ${EXPORT_STAGE_DIR}/srclist.cmake "set(LIBINT2_LIBRARY_CXX_SRC \"${generated_sources_list}\" )") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 000000000..45a7c2ea7 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,86 @@ +include(AddCustomTargetSubproject) +add_custom_target_subproject( + libint2 check # target check-libint2 + USES_TERMINAL + COMMAND ${CMAKE_CTEST_COMMAND} -V -R "libint2/" + ) + +# Note: if forming compile line by hand rather than using targets, you'll need +# to include the header toggle if compiling within the build tree (as opposed +# to linking to installed targets): +# `target_compile_definitions(... PRIVATE -D__COMPILING_LIBINT2=1)` + +## Tests ======================================================================== + +add_executable( + eritest-libint2 + EXCLUDE_FROM_ALL + eri/test.cc + ) +target_include_directories( + eritest-libint2 + PRIVATE + eri # src/bin/test_eri/eri.h + ) +target_link_libraries( + eritest-libint2 + Libint2::int2 # N.B. plain library + ) + +add_test( # Test #1 + NAME libint2/eritest/build + COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target eritest-libint2 + ) +set_tests_properties( + libint2/eritest/build + PROPERTIES + FIXTURES_SETUP LIBINT2_ERITEST_EXEC + ) +add_test( # Test #2 + NAME libint2/eritest/run0 + COMMAND $ 0 2 + ) +add_test( # Test #3 + NAME libint2/eritest/run1 + COMMAND $ 1 1 + ) +add_test( # Test #4 + NAME libint2/eritest/run2 + COMMAND $ 2 1 + ) +add_test( # Test #5 + NAME libint2/eritest/run3 + COMMAND $ 3 1 + ) +add_test( # Test #6 + NAME libint2/eritest/run4 + COMMAND $ 4 1 + ) +set_tests_properties( + libint2/eritest/run0 + libint2/eritest/run1 + libint2/eritest/run2 + libint2/eritest/run3 + libint2/eritest/run4 + PROPERTIES + FIXTURES_REQUIRED LIBINT2_ERITEST_EXEC + ) + set(utests_src + unit/test-1body.cc + unit/test-2body.cc + unit/test-basis.cc + unit/test-core.cc + unit/test-core-ints.cc + unit/test-permute.cc + unit/test-precision.cc + unit/test-shell-order.cc + unit/test-util.cc + ) + add_executable( + unit_tests-libint2 + EXCLUDE_FROM_ALL + unit/test.cc + ${utests_src} + ) + +