Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
96 changes: 36 additions & 60 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,56 +1,42 @@
cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.22)
project(diffpy_srreal LANGUAGES NONE)

# Keep this aligned with the pinned libdiffpy's src/SConscript.
# Keep this aligned with the pinned libdiffpy's CMakeLists.txt.
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(LIBDIFFPY_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/extern/libdiffpy")
if(NOT EXISTS "${LIBDIFFPY_SOURCE_DIR}/src/diffpy/version.tpl")
if(NOT EXISTS "${LIBDIFFPY_SOURCE_DIR}/CMakeLists.txt")
message(FATAL_ERROR
"Missing libdiffpy sources. Initialize the submodule with "
"'git submodule update --init --recursive', or use a source distribution "
"that includes extern/libdiffpy."
)
endif()

# Read version information from the submodule; sdists carry the generated header.
set(LIBDIFFPY_VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/include/diffpy/version.hpp")
set(LIBDIFFPY_SDIST_VERSION_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/_build/libdiffpy-version.hpp")
if(EXISTS "${LIBDIFFPY_SOURCE_DIR}/.git")
file(STRINGS "${LIBDIFFPY_SOURCE_DIR}/site_scons/fallback_version.py"
LIBDIFFPY_FALLBACK_VERSION REGEX "^FALLBACK_VERSION =")
if(NOT LIBDIFFPY_FALLBACK_VERSION MATCHES "([0-9]+)\\.([0-9]+)\\.([0-9]+)")
message(FATAL_ERROR "Cannot read the libdiffpy base version.")
endif()
set(DIFFPY_VERSION_MAJOR "${CMAKE_MATCH_1}")
set(DIFFPY_VERSION_MINOR "${CMAKE_MATCH_2}")
set(DIFFPY_VERSION_MICRO "${CMAKE_MATCH_3}")
set(DIFFPY_VERSION_PATCH 0)
set(DIFFPY_VERSION_STR "${DIFFPY_VERSION_MAJOR}.${DIFFPY_VERSION_MINOR}.${DIFFPY_VERSION_MICRO}")
math(EXPR DIFFPY_VERSION "${DIFFPY_VERSION_MAJOR} * 1000000000 + ${DIFFPY_VERSION_MINOR} * 1000000 + ${DIFFPY_VERSION_MICRO} * 1000")
set(DIFFPY_VERSION "${DIFFPY_VERSION}LL")
find_package(Git REQUIRED)
execute_process(
COMMAND "${GIT_EXECUTABLE}" -C "${LIBDIFFPY_SOURCE_DIR}" log -1 "--format=%H;%ci"
OUTPUT_VARIABLE LIBDIFFPY_COMMIT_INFO
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY
)
list(GET LIBDIFFPY_COMMIT_INFO 0 DIFFPY_GIT_SHA)
list(GET LIBDIFFPY_COMMIT_INFO 1 DIFFPY_VERSION_DATE)
configure_file("${LIBDIFFPY_SOURCE_DIR}/src/diffpy/version.tpl"
"${LIBDIFFPY_VERSION_HEADER}")
else()
configure_file("${LIBDIFFPY_SDIST_VERSION_HEADER}"
"${LIBDIFFPY_VERSION_HEADER}" COPYONLY)
endif()
# libdiffpy resolves its version from git unless src/diffpy/version.hpp exists,
# as in its own source distribution. The srreal sdist has no git, so write that
# header here and ship it.
set(LIBDIFFPY_SDIST_VERSION_HEADER "${LIBDIFFPY_SOURCE_DIR}/src/diffpy/version.hpp")
if(SKBUILD_STATE STREQUAL "sdist")
configure_file("${LIBDIFFPY_VERSION_HEADER}"
"${LIBDIFFPY_SDIST_VERSION_HEADER}" COPYONLY)
# Refresh git checkouts; preserve the header when repacking an sdist.
if(EXISTS "${LIBDIFFPY_SOURCE_DIR}/.git" OR
NOT EXISTS "${LIBDIFFPY_SDIST_VERSION_HEADER}")
include("${LIBDIFFPY_SOURCE_DIR}/cmake/LibdiffpyVersion.cmake")
libdiffpy_resolve_version()
libdiffpy_write_version_header(
"${LIBDIFFPY_SOURCE_DIR}/src/diffpy/version.tpl"
"${LIBDIFFPY_SDIST_VERSION_HEADER}")
endif()
return()
endif()
# A header left over from a local sdist build would freeze the git checkout's
# version, so remove it.
if(EXISTS "${LIBDIFFPY_SOURCE_DIR}/.git" AND EXISTS "${LIBDIFFPY_SDIST_VERSION_HEADER}")
message(STATUS "Removing stale ${LIBDIFFPY_SDIST_VERSION_HEADER}")
file(REMOVE "${LIBDIFFPY_SDIST_VERSION_HEADER}")
endif()
enable_language(CXX)

# Conda is optional; system packages and CMAKE_PREFIX_PATH work as well.
Expand Down Expand Up @@ -95,40 +81,30 @@ if(DEFINED _srreal_saved_suffixes)
endforeach()
endif()

set(DIFFPY_HAS_OBJCRYST 0)
configure_file("${LIBDIFFPY_SOURCE_DIR}/src/diffpy/features.tpl"
"include/diffpy/features.hpp")

file(GLOB LIBDIFFPY_SOURCES CONFIGURE_DEPENDS
"${LIBDIFFPY_SOURCE_DIR}/src/diffpy/*.cpp"
"${LIBDIFFPY_SOURCE_DIR}/src/diffpy/srreal/*.cpp"
)
# Embed libdiffpy as an OBJECT library: every object is linked, so its static
# factory/serialization registrars are kept.
set(LIBDIFFPY_BUILD_OBJECT_LIB ON)
set(LIBDIFFPY_INSTALL OFF)
# ObjCryst conversion uses the public Python API, so it does not depend on
# pyobjcryst's private static library, compiler, REAL precision, or nanobind ABI.
list(FILTER LIBDIFFPY_SOURCES EXCLUDE REGEX "ObjCryst")
# Include every object: libdiffpy has static factory/serialization registrars
# that an ordinary static archive link can otherwise discard.
add_library(diffpy_core OBJECT ${LIBDIFFPY_SOURCES})
set_target_properties(diffpy_core PROPERTIES
set(LIBDIFFPY_ENABLE_OBJCRYST OFF)
set(LIBDIFFPY_BUILD_TESTS OFF)
# Runtime data installs next to the extension, in diffpy/srreal/data.
set(LIBDIFFPY_RUNTIME_RELPATH data)
add_subdirectory("${LIBDIFFPY_SOURCE_DIR}" libdiffpy EXCLUDE_FROM_ALL)
set_target_properties(diffpy PROPERTIES
POSITION_INDEPENDENT_CODE ON
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
)
target_include_directories(diffpy_core PUBLIC
"${CMAKE_CURRENT_BINARY_DIR}/include"
"${LIBDIFFPY_SOURCE_DIR}/src"
)
target_compile_definitions(diffpy_core PRIVATE DIFFPYRUNTIMERELPATH=data)
if(WIN32)
# libdiffpy and its Python wrappers are compiled into the same extension.
target_compile_definitions(diffpy_core PUBLIC BUILD_DLL _USE_MATH_DEFINES NOMINMAX)
endif()
target_link_libraries(diffpy_core PUBLIC Boost::serialization GSL::gsl GSL::gslcblas ${CMAKE_DL_LIBS})

file(GLOB SRREAL_SOURCES CONFIGURE_DEPENDS "src/extensions/*.cpp")
# Retain CPython-specific wheels; stable-ABI packaging is a separate change.
nanobind_add_module(srreal_ext NB_STATIC ${SRREAL_SOURCES})
target_link_libraries(srreal_ext PRIVATE diffpy_core)
target_link_libraries(srreal_ext PRIVATE libdiffpy::diffpy)
if(WIN32)
target_compile_definitions(srreal_ext PRIVATE NOMINMAX)
endif()
set_target_properties(srreal_ext PROPERTIES INSTALL_RPATH_USE_LINK_PATH ON)
install(TARGETS srreal_ext LIBRARY DESTINATION diffpy/srreal)
install(DIRECTORY "${LIBDIFFPY_SOURCE_DIR}/src/runtime/"
Expand Down
136 changes: 0 additions & 136 deletions devutils/generate_legacy_pickle_fixtures.py

This file was deleted.

2 changes: 1 addition & 1 deletion extern/libdiffpy
Submodule libdiffpy updated 90 files
+0 −4 .codecov.yml
+2 −2 .github/ISSUE_TEMPLATE/release_checklist.md
+0 −7 .github/actions/setup-tests/action.yml
+2 −33 .github/scripts/configure-tests.py
+24 −6 .github/workflows/matrix-and-codecov.yml
+5 −2 .github/workflows/tests-on-pr.yml
+2 −5 .gitignore
+1 −2 .pre-commit-config.yaml
+3 −0 .readthedocs.yaml
+388 −0 CMakeLists.txt
+89 −0 CMakePresets.json
+15 −9 README.rst
+0 −150 SConstruct
+8 −0 cmake/FallbackVersion.cmake
+62 −0 cmake/FindObjCryst.cmake
+222 −0 cmake/LibdiffpyVersion.cmake
+54 −0 cmake/MakeSdist.cmake
+13 −0 cmake/ZeroCounters.cmake
+0 −0 cmake/gitarchive.cfg
+34 −0 cmake/libdiffpyConfig.cmake.in
+10 −5 docs/source/conf.py
+76 −44 docs/source/development.rst
+17 −0 news/cmake-build.rst
+2 −1 requirements/build.txt
+1 −1 requirements/tests.txt
+0 −11 site_scons/fallback_version.py
+0 −112 site_scons/libdiffpybuildutils.py
+0 −396 site_scons/site_tools/cxxtest.py
+0 −271 src/SConscript
+0 −64 src/SConscript.configure
+0 −71 src/SConscript.sdist
+1 −1 src/diffpy/Export.hpp
+0 −23 src/diffpy/SConscript
+0 −96 src/diffpy/SConscript.version
+0 −11 src/diffpy/srreal/SConscript
+0 −6 src/runtime/SConscript
+104 −0 src/tests/CMakeLists.txt
+0 −71 src/tests/SConscript
+119 −0 src/tests/TestAtomRadiiTable.cpp
+0 −107 src/tests/TestAtomRadiiTable.hpp
+147 −0 src/tests/TestAtomicStructureAdapter.cpp
+0 −144 src/tests/TestAtomicStructureAdapter.hpp
+23 −22 src/tests/TestAttributes.cpp
+210 −0 src/tests/TestBVParametersTable.cpp
+0 −197 src/tests/TestBVParametersTable.hpp
+156 −0 src/tests/TestBVSCalculator.cpp
+0 −150 src/tests/TestBVSCalculator.hpp
+62 −0 src/tests/TestBVSObjCryst.cpp
+0 −66 src/tests/TestBVSObjCryst.hpp
+355 −0 src/tests/TestDebyePDFCalculator.cpp
+0 −313 src/tests/TestDebyePDFCalculator.hpp
+71 −0 src/tests/TestEmptyStructureAdapter.cpp
+0 −70 src/tests/TestEmptyStructureAdapter.hpp
+79 −0 src/tests/TestHasClassRegistry.cpp
+0 −74 src/tests/TestHasClassRegistry.hpp
+153 −0 src/tests/TestLattice.cpp
+0 −149 src/tests/TestLattice.hpp
+103 −0 src/tests/TestNoMetaStructureAdapter.cpp
+0 −99 src/tests/TestNoMetaStructureAdapter.hpp
+637 −0 src/tests/TestObjCrystStructureAdapter.cpp
+0 −605 src/tests/TestObjCrystStructureAdapter.hpp
+355 −0 src/tests/TestOverlapCalculator.cpp
+0 −322 src/tests/TestOverlapCalculator.hpp
+89 −0 src/tests/TestPDFBaseline.cpp
+0 −88 src/tests/TestPDFBaseline.hpp
+265 −0 src/tests/TestPDFCalculator.cpp
+0 −239 src/tests/TestPDFCalculator.hpp
+278 −0 src/tests/TestPQEvaluator.cpp
+0 −264 src/tests/TestPQEvaluator.hpp
+139 −0 src/tests/TestPairCounter.cpp
+0 −137 src/tests/TestPairCounter.hpp
+153 −0 src/tests/TestPeakProfile.cpp
+0 −143 src/tests/TestPeakProfile.hpp
+193 −0 src/tests/TestPeakWidthModel.cpp
+0 −182 src/tests/TestPeakWidthModel.hpp
+385 −0 src/tests/TestPeriodicStructureAdapter.cpp
+0 −371 src/tests/TestPeriodicStructureAdapter.hpp
+190 −0 src/tests/TestPointsInSphere.cpp
+0 −186 src/tests/TestPointsInSphere.hpp
+105 −0 src/tests/TestR3linalg.cpp
+0 −98 src/tests/TestR3linalg.hpp
+28 −26 src/tests/TestRuntimePath.cpp
+206 −0 src/tests/TestScatteringFactorTable.cpp
+0 −185 src/tests/TestScatteringFactorTable.hpp
+88 −0 src/tests/TestSphericalShapeEnvelope.cpp
+0 −72 src/tests/TestSphericalShapeEnvelope.hpp
+83 −0 src/tests/TestStepCutEnvelope.cpp
+0 −73 src/tests/TestStepCutEnvelope.hpp
+21 −7 src/tests/objcryst_helpers.cpp
+1 −0 src/tests/objcryst_helpers.hpp
24 changes: 24 additions & 0 deletions news/cmake-libdiffpy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
**Added:**

* <news item>

**Changed:**

* Build the embedded libdiffpy through its own CMake project
(``add_subdirectory``) instead of duplicating its build logic.

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ cmake.build-type = "Release"
wheel.packages = ["src/diffpy"]
sdist.cmake = true
sdist.include = [
"_build/libdiffpy-version.hpp",
"extern/libdiffpy/CMakeLists.txt",
"extern/libdiffpy/cmake/**",
"extern/libdiffpy/src/diffpy/**",
"extern/libdiffpy/src/runtime/**",
"extern/libdiffpy/LICENSE.rst",
Expand Down
Loading
Loading