Modernize CMake Build System and Python Packaging Integration #365
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces a comprehensive overhaul of the NJOY CMake build system and integrates Python packaging using
scikit-build-core. The primary goals are to modernize the build process, simplify configuration, enable distribution via PyPI, and improve maintainability.Key Changes
CMake Modernization & Simplification:
GNUInstallDirs(for consistent installation paths likeCMAKE_INSTALL_BINDIR,CMAKE_INSTALL_LIBDIR,CMAKE_INSTALL_INCLUDEDIR) andFeatureSummary(for clearer configuration output).static,static_libraries,static_njoyoptions with the standardBUILD_SHARED_LIBSCMake option to control whether NJOY is built as a shared or static library.CMAKE_INTERPROCEDURAL_OPTIMIZATIONproperty, controlled by the newNJOY_ENABLE_LTOoption (default ON).NJOY_(e.g.,NJOY_STRICT,NJOY_COVERAGE) for clarity and to avoid conflicts.njoy_apply_build_optionsto encapsulate the logic for applying various compile and link options based on build type, compiler, and user-selected features. This greatly reduces redundancy.njoy_GNU_Linux_...,njoy_GNU_Windows_...are now generallyNJOY_GNU_...).CMAKE_INSTALL_RPATH,CMAKE_INSTALL_RPATH_USE_LINK_PATH.SKBUILDenvironments to ensure the Python package can find its bundled libraries (@loader_pathor$ORIGIN).NJOY_IS_SUBPROJECT.${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_PROJECT_NAME_LOWER}(e.g.,include/njoy).find_package(Python3)as Python environment is managed by the build frontend (e.g.,pip).setuptools-scm.Python Packaging with
scikit-build-core:pyproject.toml: Added to define the build system (scikit-build-core,setuptools-scm) and project metadata (name, version, author, license, etc.).scikit-build-coreIntegration: The CMake build is now driven byscikit-build-corewhen building the Python package.setuptools-scm.wheel.install-dir = "njoy"so that CMake-installed files go into annjoysubdirectory within the Python site-packages.Python Wrapper and Helper Modules:
cmake/GenerateScript.cmake:generate_and_install_python_script.njoyexecutable.pip, this wrapper is placed in the Python environment's script/bin directory, makingnjoydirectly callable from the command line and ensuring it uses the correct bundled executable.njoy/__init__.py&njoy/paths.py(New Python Package Structure):njoy.paths.pyprovides functions (get_include_path,get_core_libraries,get_extra_libraries) to locate the installed NJOY headers, libraries, and any libraries vendored byauditwheel/delocate. This allows downstream Python tools or users to easily find these components.GitHub Actions for Wheels (
.github/workflows/pypi.yml):cibuildwheel.Benefits
pip install njoy.cibuildwheelhelps create widely compatible binary wheels.njoy.pathsmodule allows Python applications to easily locate and use NJOY's compiled components.How to Test
njoyexecutable is available in your Python environment'sbin(orScripts) directory and is runnable.cmake -S . -B build -DCMAKE_INSTALL_PREFIX=./install cmake --build build cmake --install build./install.Note: The original functionality regarding subproject builds (
NJOY_IS_SUBPROJECT) and testing (enable_testing(),add_subdirectory(tests)) when not a subproject has been preserved. TheNJOY_LINK_EXECUTABLE_STATICALLYoption provides a way to attempt static linking of the executable, similar to the oldstaticoption's effect on the executable.