Skip to content

Commit

Permalink
cmake tweaks to help with Windows and Conda packaging (#16)
Browse files Browse the repository at this point in the history
* simpler

* add lic

* upstream libefp

* release qcel

* suppress qcel detection

* new upstream

* usual pb11 module

* revert

* flex cmakeconfig

* add path

* printing

* heal

* upstream checking

* unwind
  • Loading branch information
loriab authored Feb 17, 2023
1 parent f8d934f commit 48f063f
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 28 deletions.
16 changes: 14 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
cmake_minimum_required(VERSION 3.8 FATAL_ERROR) # 3.3: EP_add(DEPENDS interfacelib
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
cmake_policy(SET CMP0135 NEW)
endif()
# project_VERSION* variables undefined, handled in primary EP

project(pylibefp
Expand Down Expand Up @@ -43,6 +47,8 @@ option_with_default(CMAKE_INSTALL_LIBDIR "Directory to which libraries installed
option_with_default(PYMOD_INSTALL_LIBDIR "Location within CMAKE_INSTALL_LIBDIR to which python modules are installed" /)
option_with_default(ENABLE_GENERIC "Enables mostly static linking of system libraries for shared library" OFF)
option_with_default(pylibefp_CXX_STANDARD "Specify C++ standard for core pylibefp" 11)
option_with_default(PYLIBEFP_CMAKECONFIG_INSTALL_DIR "Directory within CMAKE_INSTALL_PREFIX to which CMake configuration files installed" "share/cmake/pylibefp")
option_with_default(LIBEFP_CMAKECONFIG_INSTALL_DIR "Directory within CMAKE_INSTALL_PREFIX to which CMake configuration files installed" "share/cmake/libefp")

######################## Process & Validate Options ##########################
include(GNUInstallDirs)
Expand Down Expand Up @@ -72,9 +78,10 @@ ExternalProject_Add(pylibefp-core
DEPENDS #lapack_external
libefp_external
pybind11_external
qcelemental_external
#qcelemental_external
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/pylibefp
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
CMAKE_ARGS -G${CMAKE_GENERATOR}
-DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
Expand All @@ -87,7 +94,12 @@ ExternalProject_Add(pylibefp-core
-DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR}
-DCMAKE_INSTALL_DATADIR=${CMAKE_INSTALL_DATADIR}
-DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR}
-DPYLIBEFP_CMAKECONFIG_INSTALL_DIR=${PYLIBEFP_CMAKECONFIG_INSTALL_DIR}
-DPYMOD_INSTALL_LIBDIR=${PYMOD_INSTALL_LIBDIR}
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
-DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=${CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS}
-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
-DPYTHON_INCLUDE_DIR=${PYTHON_INCLUDE_DIR}
-DPYTHON_LIBRARY=${PYTHON_LIBRARY}
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2017, Lori A. Burns
Copyright (c) 2017-2023, Lori A. Burns
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
23 changes: 23 additions & 0 deletions LICENSE_libefp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright (c) 2012-2017 Ilya Kaliman

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
| **Foundation** | [![license](https://img.shields.io/github/license/loriab/pylibefp.svg)](https://opensource.org/licenses/BSD-3-Clause) [![platforms](https://img.shields.io/conda/pn/psi4/pylibefp.svg)](https://anaconda.org/psi4/pylibefp) [![python](https://img.shields.io/badge/python-3.6+-blue.svg)](http://python3statement.org/) |
| **Installation** | [![Conda](https://img.shields.io/conda/v/psi4/pylibefp.svg)](https://anaconda.org/psi4/pylibefp) [![Anaconda-Server Badge](https://anaconda.org/psi4/pylibefp/badges/latest_release_relative_date.svg)](https://anaconda.org/psi4/pylibefp) |

python wrapper to I. Kaliman's [libefp](https://libefp.github.io/) for effective fragment potentials
python wrapper to I. Kaliman and L. Slipchenko's [libefp](https://libefp2.github.io/) for effective fragment potentials
2 changes: 1 addition & 1 deletion doc/source/conf.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('@PROJECT_BINARY_DIR@/stage/@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@@PYMOD_INSTALL_LIBDIR@'))
sys.path.insert(0, os.path.abspath('@PROJECT_BINARY_DIR@/stage/@CMAKE_INSTALL_LIBDIR@@PYMOD_INSTALL_LIBDIR@'))

# Import Sphinx themes
import sphinx_psi_theme
Expand Down
2 changes: 1 addition & 1 deletion external/upstream/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
foreach(dir libefp
pybind11
qcelemental
#qcelemental
)
add_subdirectory(${dir})
endforeach()
Expand Down
15 changes: 10 additions & 5 deletions external/upstream/libefp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,23 @@ else()
message(STATUS "Suitable libefp could not be located, ${Magenta}Building libefp${ColourReset} instead.")
ExternalProject_Add(libefp_external
#DEPENDS lapack_external
URL https://github.com/ilyak/libefp/archive/15cd7ce.tar.gz # v1.5.0 + 10 (docs and a cmake lapack patch)
# DOWNLOAD_COMMAND ""
# SOURCE_DIR "/home/psilocaluser/gits/libefp"
#URL https://github.com/libefp2/libefp/archive/15cd7ce.tar.gz # v1.5.0 + 10 (docs and a cmake lapack patch) (longstanding; present on master branch in both GH:ilyak/libefp and GH:libefp2/libefp)
URL https://github.com/loriab/libefp/archive/14f8594.tar.gz # v1.5.0 + 13 (above plus some cmake patches for windows) (head of patched_v150 branch only at GH:loriab/libefp)
URL_HASH SHA256=26026fc3f9bae4715fe06113a53908f3602127398bb219fce4e8b3750f2a05e0
UPDATE_COMMAND ""
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
CMAKE_ARGS -G${CMAKE_GENERATOR}
-DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
-DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR}
-DCMAKE_INSTALL_DATADIR=${CMAKE_INSTALL_DATADIR}
-DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR}
-DLIBEFP_CMAKECONFIG_INSTALL_DIR=${LIBEFP_CMAKECONFIG_INSTALL_DIR}
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
-DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=${CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS}
-DENABLE_OPENMP=${ENABLE_OPENMP}
-DENABLE_XHOST=${ENABLE_XHOST}
-DBUILD_FPIC=${BUILD_FPIC}
Expand All @@ -38,5 +43,5 @@ else()
#-DTargetLAPACK_DIR=${STAGED_INSTALL_PREFIX}/share/cmake/TargetLAPACK
CMAKE_CACHE_ARGS -DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS})

set(libefp_DIR ${STAGED_INSTALL_PREFIX}/share/cmake/libefp CACHE PATH "path to internally built libefpConfig.cmake" FORCE)
set(libefp_DIR ${STAGED_INSTALL_PREFIX}/${LIBEFP_CMAKECONFIG_INSTALL_DIR} CACHE PATH "path to internally built libefpConfig.cmake" FORCE)
endif()
31 changes: 14 additions & 17 deletions pylibefp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ list(APPEND CMAKE_MODULE_PATH ${PYLIBEFP_ROOT}/cmake)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(custom_color_messages)
# GNUInstallDirs "DATADIR" wrong here; CMake search path wants "share".
set(CMAKECONFIG_INSTALL_DIR "share/cmake/pylibefp")

# <<< Marshal Dependencies & Add-ons >>>

Expand All @@ -19,8 +17,7 @@ set(CMAKECONFIG_INSTALL_DIR "share/cmake/pylibefp")
#message(STATUS "${Cyan}Using LAPACK${_isMKL}${ColourReset}: ${_ill0};...")

# << Pybind11 & Python >>
set(PYBIND11_CPP_STANDARD "-std=c++${CMAKE_CXX_STANDARD}")
find_package(pybind11 2.3.0 CONFIG REQUIRED)
find_package(pybind11 2.6.2 CONFIG REQUIRED)
message(STATUS "${Cyan}Using pybind11${ColourReset}: ${pybind11_INCLUDE_DIR} (version ${pybind11_VERSION} for Py${PYTHON_VERSION_STRING} and ${PYBIND11_CPP_STANDARD})")
message(STATUS "${Cyan}Using Python ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}${ColourReset}: ${PYTHON_EXECUTABLE}")

Expand All @@ -34,10 +31,9 @@ message(STATUS "${Cyan}Using libefp${ColourReset}: ${_loc} (version ${libefp_VER

# <<< Build >>>

pybind11_add_module(core NO_EXTRAS core.cc)
pybind11_add_module(core MODULE core.cc)
target_link_libraries(core PRIVATE libefp::efp)
target_link_libraries(core PRIVATE ${LIBC_INTERJECT})
target_link_libraries(core PUBLIC pybind11::module)
target_link_libraries(core PRIVATE Threads::Threads)

set(PN pylibefp)
Expand All @@ -46,7 +42,7 @@ install(TARGETS core
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${PYMOD_INSTALL_LIBDIR}/pylibefp)
install(EXPORT "${PN}Targets"
NAMESPACE "${PN}::"
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
DESTINATION ${PYLIBEFP_CMAKECONFIG_INSTALL_DIR})

set_target_properties(core PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}" # for python module
OUTPUT_NAME core
Expand All @@ -55,23 +51,24 @@ set_target_properties(core PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}" # for py
INSTALL_RPATH "${psi4_RPATH}"
BUILD_WITH_INSTALL_RPATH ON)


# <<< Version >>>

add_custom_target(update_version ALL
COMMAND ${PYTHON_EXECUTABLE} versioner.py --metaout ${CMAKE_CURRENT_BINARY_DIR}/metadata.py
--cmakeout ${CMAKE_CURRENT_BINARY_DIR}/metadata.cmake
COMMAND ${CMAKE_COMMAND} -DWTO="${CMAKE_CURRENT_BINARY_DIR}/${CMAKECONFIG_INSTALL_DIR}"
COMMAND ${CMAKE_COMMAND} -DWTO="${CMAKE_CURRENT_BINARY_DIR}/${PYLIBEFP_CMAKECONFIG_INSTALL_DIR}"
-DPN="pylibefp"
-P ${CMAKE_CURRENT_BINARY_DIR}/metadata.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating version info")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/metadata.py
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}${PYMOD_INSTALL_LIBDIR}/pylibefp)
DESTINATION ${CMAKE_INSTALL_LIBDIR}${PYMOD_INSTALL_LIBDIR}/pylibefp)

# <<< Install >>>

install(FILES __init__.py extras.py exceptions.py psiutil.py
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}${PYMOD_INSTALL_LIBDIR}/pylibefp)
DESTINATION ${CMAKE_INSTALL_LIBDIR}${PYMOD_INSTALL_LIBDIR}/pylibefp)

install(FILES ../tests/addons.py
../tests/conftest.py
Expand All @@ -83,19 +80,19 @@ install(FILES ../tests/addons.py
../tests/test_scf.py
../tests/test_psi.py
../tests/test_libefp.py
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}${PYMOD_INSTALL_LIBDIR}/pylibefp/tests/)
DESTINATION ${CMAKE_INSTALL_LIBDIR}${PYMOD_INSTALL_LIBDIR}/pylibefp/tests/)

configure_file(wrapper.py wrapper.py @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/wrapper.py
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}${PYMOD_INSTALL_LIBDIR}/pylibefp)
DESTINATION ${CMAKE_INSTALL_LIBDIR}${PYMOD_INSTALL_LIBDIR}/pylibefp)

# <<< Export Config >>>

configure_package_config_file(
${PN}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${CMAKECONFIG_INSTALL_DIR}/${PN}Config.cmake
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKECONFIG_INSTALL_DIR}/${PN}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${CMAKECONFIG_INSTALL_DIR}/${PN}ConfigVersion.cmake
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
${CMAKE_CURRENT_BINARY_DIR}/${PYLIBEFP_CMAKECONFIG_INSTALL_DIR}/${PN}Config.cmake
INSTALL_DESTINATION ${PYLIBEFP_CMAKECONFIG_INSTALL_DIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PYLIBEFP_CMAKECONFIG_INSTALL_DIR}/${PN}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PYLIBEFP_CMAKECONFIG_INSTALL_DIR}/${PN}ConfigVersion.cmake
DESTINATION ${PYLIBEFP_CMAKECONFIG_INSTALL_DIR})

1 change: 1 addition & 0 deletions pylibefp/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def add_potential(efpobj, potential, fragpath='LIBRARY', duplicates_ok=False):
if pth == 'LIBRARY':
paths.append('@libefp_FRAGLIB_DIRS@')
paths.append('/opt/anaconda1anaconda2anaconda3/share/libefp/fraglib')
paths.append('/opt/anaconda1anaconda2anaconda3/Library/share/libefp/fraglib')
else:
paths.append(os.path.expandvars(os.path.expanduser(pth)))
paths = os.pathsep.join(paths)
Expand Down

0 comments on commit 48f063f

Please sign in to comment.