Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all-stage CMake #148

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
a764784
this builds a library entirely with cmake
loriab Sep 27, 2019
8460bdf
build static and shared. process version and soversion.
loriab Sep 28, 2019
ed896f0
builds and works with psi4 libint2 branch
loriab Oct 2, 2019
516d6ba
more cmake tidying
loriab Oct 3, 2019
9d33d32
cmake info passing fixes
loriab Oct 3, 2019
82a1a7e
fixes
loriab Oct 3, 2019
3a302ac
cmake_module_path fix
loriab Oct 3, 2019
0ba973b
am_eri defaulting, take 4
loriab Oct 5, 2019
5af026c
opt_am fix
loriab Oct 5, 2019
02b6e43
try some gmp variations for windows
loriab Nov 26, 2019
ab73c8d
adapt for windows
loriab Nov 26, 2019
677de15
adapt for windows: srandom --> srand
loriab Nov 26, 2019
ef2b5af
adapt for windows: random --> rand
loriab Nov 27, 2019
d9a25d2
adapt for windows
loriab Nov 27, 2019
bb55f22
adapt for windows
loriab Nov 27, 2019
db785a8
adapt for windows
loriab Nov 27, 2019
c4b93fc
adapt for windows
loriab Nov 27, 2019
f2c586f
adapt for windows
loriab Nov 27, 2019
d128e48
adapt for windows
loriab Nov 27, 2019
67c853f
adapt for windows
loriab Nov 27, 2019
71fd890
adapt for windows
loriab Nov 27, 2019
41e6cfb
adapt for windows
loriab Nov 28, 2019
d6525b4
adapt for windows
loriab Nov 29, 2019
40e8477
adapt for windows
loriab Nov 29, 2019
9fb43c8
adapt for windows
loriab Nov 29, 2019
bb9b7ae
switch to generate, export, library 3-step CMake flow
loriab Dec 4, 2019
4383c6c
am component improvements
loriab Dec 7, 2019
d91fcce
debug
loriab Dec 8, 2019
cb58fdf
debug
loriab Dec 8, 2019
1dc54c9
debug
loriab Dec 8, 2019
4129968
config printing
loriab Dec 8, 2019
972a826
config printing
loriab Dec 8, 2019
ae27f7a
fpic handling
loriab Dec 8, 2019
d152bdc
fpic again
loriab Dec 8, 2019
e5f5dca
add generic code option
loriab Dec 9, 2019
6cf403b
add testing to library
loriab Dec 10, 2019
9c12cfd
more windows mods
loriab Dec 12, 2019
ee9365d
more output please
loriab Dec 12, 2019
0ab0367
more windows mods
loriab Dec 12, 2019
0c7cecd
more windows mods
loriab Dec 13, 2019
098a76e
more windows mods
loriab Dec 13, 2019
7fd4e7f
more windows mods
loriab Dec 13, 2019
958e955
win pokgin
loriab Dec 17, 2019
cbf4c5f
no more stars in basis names
loriab Dec 17, 2019
fae8caa
increase stack on win
loriab Jan 18, 2020
d5b6ee2
win stack in the right place
loriab Jan 19, 2020
ddb4361
strdup win
loriab Jan 21, 2020
ebe3fad
add libint_pragma changes, fixes #160
loriab Sep 10, 2020
5b54f6a
fix more (n2) in test. bundle boost with export. max_am[_eri3] advice…
loriab Sep 22, 2020
8ae554c
Adds eri3 and eri2 components, so if need library to compile 3-cente…
loriab Sep 28, 2020
3860201
missed a ref for export
loriab Sep 29, 2020
da780fd
Fix freeing of aligned memory on Windows
andysim Oct 21, 2020
4c5ab73
Merge pull request #1 from andysim/l2cmake
loriab Oct 22, 2020
d2843ee
boost detection for export, notes
loriab Oct 22, 2020
ed09cd1
minor notes
loriab Oct 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
308 changes: 308 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,308 @@
cmake_minimum_required(VERSION 3.8)

project(Libint2
LANGUAGES CXX)
set(Libint2_AUTHORS "Edward F. Valeev")
set(Libint2_DESCRIPTION "High-performance library for computing Gaussian integrals in quantum mechanics")
set(Libint2_URL "https://github.com/evaleev/libint")
set(Libint2_LICENSE "GPL-3.0 for generator; LGPL-3.0 for generated")

cmake_policy(SET CMP0074 NEW)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake
${PROJECT_SOURCE_DIR}/export/cmake/modules)

################################### Overview ###################################

# CMake build overview:
#
# >>> ls
# cmake/ COPYING src/ tests/ ...
# >>> cmake -H. -Bbuild -GNinja -DCMAKE_INSTALL_PREFIX=/path/to/install-libint ...
# ...
# -- Generating done
# -- Build files have been written to: /current/dir/build
# >>> cd build && cmake --build . --target install -j`getconf _NPROCESSORS_ONLN`

# The build is structured into three parts:
#
# * generator
# - build src/bin/libint/ into executable `build_libint`
# - pretty quick, runs in parallel
# - consumes all the enable/max/opt integral options and all orderings options except solid harmonic
# * export
# - run `build_libint` to generate thousands of C++ source files (that upon
# compilation can become a Libint2 library) and combine them with other
# static source files in src/lib/libint/ and general static files (e.g.,
# include/ and docs/) into an independent tarball ready for distribution.
# - really slow for non-trivial angular momenta, runs in serial
# - consumes no options
# - `cmake --build . --target export` to stop after this step and collect source tarball
# * library
# - unpack the export tarball and build the library and install into stage/
# - duration depends on number of integrals requested, runs in parallel
# - consumes solid harmonic ordering and the CMAKE_INSTALL_[DATA|INCLUDE|LIB]DIR
# - the default target `cmake --build .` includes this final library build

################################### Options ####################################
include(int_versions)
include(psi4OptionsTools)

# <<< General >>>

option_with_default(CMAKE_BUILD_TYPE "Build type (Release or Debug)" Release)
option_with_print(BUILD_SHARED "Build at least shared library" OFF)
option_with_print(BUILD_STATIC "Build at least static library (see BUILD_FPIC)" ON)
option_with_print(ENABLE_CXX11API "Build C++11 API in addition to basic library (requires Eigen)" ON)
option_with_print(ENABLE_FORTRAN "Build Fortran03+ Libint interface (requires Fortran)" OFF)
option_with_print(BUILD_TESTING "Compile the testing infrastructure" ON)

if(NOT ENABLE_CXX11API)
message(FATAL_ERROR "The plain library withough C++11 API is not hooked into this pure-CMake Libint2 buildsystem. For immediate use, switch to the original Libtool+CMake buildsystem. For help expanding this buildsystem to the plain library, raise an issue on GitHub and ping @loriab.")
endif()

if(ENABLE_FORTRAN)
message(FATAL_ERROR "The Fortran interface is not hooked into this pure-CMake Libint2 buildsystem. For immediate use, switch to the original Libtool+CMake buildsystem. For help expanding this buildsystem to the Fortran interface, raise an issue on GitHub and ping @loriab.")
endif()

# <<< Which Integrals Classes, Which Derivative Levels >>>

option_with_default(ENABLE_ONEBODY
"Compile with support for up to N-th derivatives of 1-body integrals (-1 for OFF)" 0)
option_with_default(ENABLE_ERI
"Compile with support for up to N-th derivatives of electron repulsion integrals (-1 for OFF)" 0)
option_with_default(ENABLE_ERI3
"Compile with support for up to N-th derivatives of 3-center electron repulsion integrals (-1 for OFF)" -1)
option_with_default(ENABLE_ERI2
"Compile with support for up to N-th derivatives of 2-center electron repulsion integrals (-1 for OFF)" -1)
option_with_default(ENABLE_G12
"Compile with support for N-th derivatives of MP2-F12 energies with Gaussian factors (-1 for OFF)" -1)
option_with_default(ENABLE_G12DKH
"Compile with support for N-th derivatives of DKH-MP2-F12 energies with Gaussian factors (-1 for OFF)" -1)

option_with_print(DISABLE_ONEBODY_PROPERTY_DERIVS
"Disable geometric derivatives of 1-body property integrals (all but overlap, kinetic, elecpot).
These derivatives are disabled by default to save compile time. (enable with OFF)" ON)

# <<< Ordering Conventions >>>

option_with_default(LIBINT2_SHGAUSS_ORDERING
"Ordering for shells of solid harmonic Gaussians:
standard -- standard ordering (-l, -l+1 ... l)
gaussian -- the Gaussian ordering (0, 1, -1, 2, -2, ... l, -l)" standard)
option_with_default(LIBINT2_CARTGAUSS_ORDERING
"Orderings for shells of cartesian Gaussians:
standard -- standard ordering (xxx, xxy, xxz, xyy, xyz, xzz, yyy, ...)
intv3 -- intv3 ordering (yyy, yyz, yzz, zzz, xyy, xyz, xzz, xxy, xxz, xxx)
gamess -- GAMESS ordering (xxx, yyy, zzz, xxy, xxz, yyx, yyz, zzx, zzy, xyz)
orca -- ORCA ordering (hydrid between GAMESS and standard)
bagel -- axis-permuted version of intv3 (xxx, xxy, xyy, yyy, xxz, xyz, yyz, xzz, yzz, zzz)" standard)
option_with_default(LIBINT2_SHELL_SET
"Support computation of shell sets sets subject to these restrictions:
standard -- standard ordering:
for (ab|cd):
l(a) >= l(b),
l(c) >= l(d),
l(a)+l(b) <= l(c)+l(d)
for (b|cd):
l(c) >= l(d)
orca -- ORCA ordering:
for (ab|cd):
l(a) <= l(b),
l(c) <= l(d),
l(a) < l(c) || (l(a) == l(c) && l(b) < l(d))
for (b|cd):
l(c) <= l(d)" standard)
option_with_print(ERI3_PURE_SH
"Assume the 'unpaired' center of 3-center ERIs will be transformed to pure solid harmonics" OFF)
option_with_print(ERI2_PURE_SH
"Assume the 2-center ERIs will be transformed to pure solid harmonics" OFF)

# <<< How High Angular Momentum >>>

# example for "semicolon-separated string": `-DENABLE_ERI3=2 -DWITH_ERI3_MAX_AM="5;4;3"`

# high MAX_AM generating >20k files may require `ulimit -s 65535` for linking library target on Linux to avert "ld: Argument list too long"

option_with_default(WITH_MAX_AM
"Support Gaussians of angular momentum up to N.
Can specify values for each derivative levels as a semicolon-separated string" 4)
option_with_default(WITH_OPT_AM
"Optimize maximally for up to angular momentum N (N <= max-am). (default: (libint_max_am/2)+1)" -1)

option_with_default(MULTIPOLE_MAX_ORDER
"Maximum order of spherical multipole integrals. There is no maximum" 4)
option_with_default(WITH_ONEBODY_MAX_AM
"Support 1-e ints for Gaussians of angular momentum up to N.
Can specify values for each derivative as a semicolon-separated string. (default: (libint_max_am/2)+1)" -1)
option_with_default(WITH_ONEBODY_OPT_AM
"Optimize 1-e ints maximally for up to angular momentum N (N <= max-am).
Can specify values for each derivative levels as a semicolon-separated string" -1)

option_with_default(WITH_ERI_MAX_AM
"Support ERIs for Gaussians of angular momentum up to N.
Can specify values for each derivative levels as a semicolon-separated string" -1)
option_with_default(WITH_ERI_OPT_AM
"Optimize ERIs maximally for up to angular momentum N (N <= max-am).
Can specify values for each derivative levels as a semicolon-separated string (default: (max_am/2)+1)" -1)

option_with_default(WITH_ERI3_MAX_AM
"Support 3-center ERIs for Gaussians of angular momentum up to N.
Can specify values for each derivative levels as a semicolon-separated string
Set WITH_MAX_AM to mirror this option." -1)
option_with_default(WITH_ERI3_OPT_AM
"Optimize 3-center ERIs maximally for up to angular momentum N (N <= max-am).
Can specify values for each derivative levels as a semicolon-separated string (default: (max_am/2)+1)" -1)

option_with_default(WITH_ERI2_MAX_AM
"Support 2-center ERIs for Gaussians of angular momentum up to N.
Can specify values for each derivative levels as a semicolon-separated string" -1)
option_with_default(WITH_ERI2_OPT_AM
"Optimize 2-center ERIs maximally for up to angular momentum N (N <= max-am).
Can specify values for each derivative levels as a semicolon-separated string" -1)

option_with_default(WITH_G12_MAX_AM
"Support integrals for G12 methods of angular momentum up to N." -1)
option_with_default(WITH_G12_OPT_AM
"Optimize G12 integrals for up to angular momentum N (N <= max-am)." -1)

option_with_default(WITH_G12DKH_MAX_AM
"Support integrals for relativistic G12 methods of angular momentum up to N." -1)
option_with_default(WITH_G12DKH_OPT_AM
"Optimize G12DKH integrals for up to angular momentum N (N <= max-am)." -1)

# <<< Miscellaneous >>>

option_with_print(LIBINT_CONTRACTED_INTS
"Turn on support for contracted integrals." ON)
option_with_default(LIBINT_ERI_STRATEGY
"Compute ERIs using the following strategy. This option is for experts ONLY." 1)
option_with_print(LIBINT_USE_COMPOSITE_EVALUATORS
"Libint will use composite evaluators (i.e. every evaluator will compute one integral type only)" ON)
option_with_print(LIBINT_SINGLE_EVALTYPE
"Generate single evaluator type (i.e. all tasks use the same evaluator)" ON)
option_with_default(LIBINT_ENABLE_UNROLLING
"Unroll shell sets into integrals (will unroll shell sets larger than N) (no->0, yes->1000000000)" 100)
option_with_default(LIBINT_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. LAB: LIBINT for bin, LIBINT2 for lib?" 0)
option_with_print(LIBINT_GENERATE_FMA
"Generate FMA (fused multiply-add) instructions (to benefit must have FMA-capable hardware and compiler)" OFF)
option_with_print(LIBINT_ENABLE_GENERIC_CODE
"Use manually-written generic code" OFF)
option_with_flags(ENABLE_XHOST "Enables processor-specific optimization (with MSVC, it enables AVX2 instructions)" ON
"-xHost" "-march=native" "/arch:AVX2")
option_with_default(BUILD_FPIC "Compile lone static library with position independent code (all libraries are fpic when BUILD_SHARED=ON)" OFF)
option_with_default(CMAKE_INSTALL_LIBDIR "Directory to which libraries installed" lib)

#CONFIGURE --disable-t1g12-support Libint will not support [Ti,G12] integrals
#CONFIGURE --enable-accum-ints Accumulate integrals to the buffer, rather than
#CONFIGURE copy.
#CONFIGURE --enable-flop-counter Support (approximate) FLOP counting by the library.
#CONFIGURE CXXGEN must support C++11!
#CONFIGURE --enable-profile Turn on profiling instrumentation of the library.
#CONFIGURE CXXGEN must support C++11!
#CONFIGURE --enable-mpfr Use MPFR library to test Libint integrals in high
#CONFIGURE precision.
#CONFIGURE
#CONFIGURE Optional Packages:
#CONFIGURE --with-api-prefix Prepend this string to every name in the library API
#CONFIGURE (except for the types).
#CONFIGURE --with-vector-length=N Compute integrals in vectors of length N.
#CONFIGURE --with-vector-method Specifies how to vectorize integrals. Allowed values
#CONFIGURE are 'block' (default), and 'line'.
#CONFIGURE --with-build-id Gives an identifier for the build.
#CONFIGURE --with-libint-exportdir Specifies export directory name. Default is
#CONFIGURE libint-<version>.
#CONFIGURE --with-pkgconfigdir Specifies the location to put pkg-config's data
#CONFIGURE file. Default is $(libdir)/pkgconfig.
#CONFIGURE --with-cmakedir Specifies the location to put FindLibint2.cmake
#CONFIGURE file. Default is $(libdir)/cmake/libint2.
#CONFIGURE --with-real-type Compute all integrals using the given real type LIBINT_USER_DEFINED_REAL
#CONFIGURE (default: double).
#CONFIGURE --with-real-type-includes LIBINT_USER_DEFINED_REAL_INCLUDES
#CONFIGURE Additional includes necessary to use the real type
#CONFIGURE (default: none).

######################## Process & Validate Options ###########################
include(autocmake_safeguards)
include(CheckFunctionExists)
include(int_orderings)
include(int_am)

check_function_exists(posix_memalign HAVE_POSIX_MEMALIGN)
if (HAVE_POSIX_MEMALIGN)
set(LIBINT2_ALIGN_SIZE "0" CACHE STRING "(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")
endif()

# C++11 required for now. enforced in targets
set(LIBINT_HAS_CXX11 1)
set(LIBINT_USE_TYPE_TRAITS 1)
set(LIBINT_USE_MEMORY 1)
set(LIBINT_USE_ARRAY 1)
set(LIBINT_HAS_STD_TYPE_TRAITS 1)
set(LIBINT_HAS_STD_SHARED_PTR 1)
set(LIBINT_HAS_STD_MAKE_SHARED 1)
set(LIBINT_HAS_STD_ARRAY 1)
set(LIBINT_ARRAY_HAS_FILL 1)

# req'd for now (no FindGMP.cmake, though one at Elemental project)
find_package(MPFR REQUIRED)
if (TARGET MPFR::MPFRXX)
set(LIBINT_HAS_MPFR 1)
endif()

find_package(Boost 1.57 REQUIRED)
if (TARGET Boost::boost) # the header-only target
set(LIBINT_HAS_SYSTEM_BOOST_PREPROCESSOR_VARIADICS 1)
endif()

find_package(Eigen3 REQUIRED)
if (TARGET Eigen3::Eigen)
set(LIBINT_HAS_EIGEN 1)
endif()

unset(_temp_h CACHE)
find_path(_temp_h NAMES stdint.h)
if(_temp_h)
set(HAVE_STDINT_H 1)
endif()

booleanize01(ERI3_PURE_SH)
booleanize01(ERI2_PURE_SH)
booleanize01(LIBINT_SINGLE_EVALTYPE)
booleanize01(LIBINT_USE_COMPOSITE_EVALUATORS)
booleanize01(LIBINT_CONTRACTED_INTS)
booleanize01(DISABLE_ONEBODY_PROPERTY_DERIVS)
booleanize01(LIBINT_GENERATE_FMA)
booleanize01(LIBINT_ENABLE_GENERIC_CODE)

################################# Main Project #################################
set(STAGED_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/stage)
set(EXPORT_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/export) # TODO switch to something like libint-2.7.0-beta.2

if (BUILD_TESTING)
enable_testing()
endif()
add_subdirectory(src)
include(GNUInstallDirs)

if (ENABLE_FORTRAN)
enable_language(Fortran)
endif()

set(_EXPORT_MODE 0)
configure_file(include/libint2/config.h.cmake.in include/libint2/config.h @ONLY)
set(_EXPORT_MODE 1)
configure_file(include/libint2/config.h.cmake.in export/include/libint2/config.h @ONLY)
configure_file(include/libint2/config2.h.cmake.in export/include/libint2/config2.h.cmake.in COPYONLY)

configure_file(cmake/int_computed.cmake.in cmake/int_computed.cmake @ONLY)

# <<< Install >>>

install(DIRECTORY ${STAGED_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
# BINDIR excluded b/c `build_libint` not really for distribution
${STAGED_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}
${STAGED_INSTALL_PREFIX}/share
DESTINATION ${CMAKE_INSTALL_PREFIX}
USE_SOURCE_PERMISSIONS)
Loading