### Install Target Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/broken_fallback/CMakeLists.txt Installs the 'example' target to the root of the installation directory. ```cmake install(TARGETS example DESTINATION .) ``` -------------------------------- ### Project Setup and File Creation Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/filepath_pure/CMakeLists.txt Initializes the CMake project and creates placeholder files in the binary directory. These files are then installed to different locations. ```cmake cmake_minimum_required(VERSION 3.15...3.26) project( "${SKBUILD_PROJECT_NAME}" LANGUAGES C VERSION "${SKBUILD_PROJECT_VERSION}" ) file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/in_headers.h) file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/in_scripts.py) file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/in_data.txt) file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/main.py) file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/random_file.py) ``` -------------------------------- ### Specify Install Components Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/configuration/index.md Select only specific components to install. For example, to install only the 'python' component. ```toml install.components ["python"] ``` -------------------------------- ### Install Python Extension Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/examples/getting_started/cython/CMakeLists.txt Installs the compiled 'example' extension module to the root of the Python site-packages directory. ```cmake install(TARGETS example DESTINATION .) ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/simple_pyproject_script_with_flags/CMakeLists.txt Defines the minimum CMake version, project name, languages, and version. This is a standard starting point for CMake projects. ```cmake cmake_minimum_required(VERSION 3.15...3.29) project( "${SKBUILD_PROJECT_NAME}" LANGUAGES C VERSION "${SKBUILD_PROJECT_VERSION}" ) ``` -------------------------------- ### Python Interactive Session Example Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/examples/downstream/nanobind_example/README.md After installation, you can import the library and use its functions in an interactive Python session. This example shows a simple addition function. ```pycon >>> import nanobind_example >>> nanobind_example.add(1, 2) 3 ``` -------------------------------- ### CMake Project Setup Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/sdist_config/external/dummy/CMakeLists.txt Sets the minimum CMake version and project name. Languages are set to NONE as this example focuses on configuration. ```cmake cmake_minimum_required(VERSION 3.15) project(dummy LANGUAGES NONE) ``` -------------------------------- ### Create and Install Test File Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/importlib_editable/src/pkg/CMakeLists.txt Creates a test file in the binary directory and then installs it to the 'pkg/' destination. ```cmake file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testfile" "This is the file") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile" DESTINATION pkg/) ``` -------------------------------- ### Write and Install Test File Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/importlib_editable/src/pkg/sub_b/CMakeLists.txt Creates a test file in the binary directory and then installs it to 'pkg/sub_b'. ```cmake file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testfile" "This is the file") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile" DESTINATION pkg/sub_b) ``` -------------------------------- ### Create and Install Test File Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/importlib_editable/src/pkg/sub_a/CMakeLists.txt Creates a test file in the binary directory and then installs it to the 'pkg/sub_a' destination. ```cmake file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testfile" "This is the file") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile" DESTINATION pkg/sub_a) ``` -------------------------------- ### Install Extension Module Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/examples/downstream/nanobind_example/CMakeLists.txt This install directive ensures that the compiled 'nanobind_example_ext' target is installed to the 'nanobind_example' directory when using scikit-build-core. ```cmake # Install directive for scikit-build-core install(TARGETS nanobind_example_ext LIBRARY DESTINATION nanobind_example) ``` -------------------------------- ### Installing Project Files Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/simple_setuptools_ext/CMakeLists.txt This snippet defines the installation rules for the target library and license file. ```cmake install(TARGETS cmake_example LIBRARY DESTINATION .) install(FILES LICENSE DESTINATION .) ``` -------------------------------- ### Installing the Extension Library Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/toml_setuptools_ext/CMakeLists.txt Installs the 'cmake_example' target as a library into the root of the destination directory. This makes the compiled extension available for import. ```cmake install(TARGETS cmake_example LIBRARY DESTINATION .) ``` -------------------------------- ### Install Testing Data Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/hatchling/cpp/CMakeLists.txt Writes a data file and installs it to the data directory. ```cmake # Testing data file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/data_file.txt" "Data") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/data_file.txt" DESTINATION "${SKBUILD_DATA_DIR}") ``` -------------------------------- ### Install Library and Test File Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/importlib_editable/src/pkg/sub_b/sub_c/CMakeLists.txt Installs the 'emod_d' library to the 'pkg/sub_b/sub_c' directory and a generated 'testfile' to the same location. ```cmake install(TARGETS emod_d DESTINATION pkg/sub_b/sub_c) ``` ```cmake file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testfile" "This is the file") ``` ```cmake install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile" DESTINATION pkg/sub_b/sub_c/) ``` -------------------------------- ### File Installation Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/filepath_pure/CMakeLists.txt Installs created files to specific destinations within the project structure. Ensure the destination variables are correctly defined. ```cmake install(FILES ${CMAKE_CURRENT_BINARY_DIR}/random_file.py DESTINATION ${SKBUILD_PLATLIB_DIR}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/in_headers.h DESTINATION ${SKBUILD_HEADERS_DIR}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/in_scripts.py DESTINATION ${SKBUILD_SCRIPTS_DIR}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/in_data.txt DESTINATION ${SKBUILD_DATA_DIR}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/main.py DESTINATION .) ``` -------------------------------- ### Write and Install Ignored File Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/simplest_c/CMakeLists.txt Writes content to a file and installs it to a destination without a specific component, making it part of the default installation. ```cmake file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/generated_ignored.txt "Testing") install(FILES ${CMAKE_CURRENT_BINARY_DIR}/generated_ignored.txt DESTINATION ${SKBUILD_PROJECT_NAME}) ``` -------------------------------- ### Install Testing Script Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/hatchling/cpp/CMakeLists.txt Writes a Python script and installs it to the scripts directory. ```cmake # Testing scripts file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/myscript" "#!/usr/bin/env python\nprint('Hello from myscript.py')") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/myscript" DESTINATION "${SKBUILD_SCRIPTS_DIR}") ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/importlib_editable/src/CMakeLists.txt Initializes a CMake project with a minimum version and specifies the project name and language. ```cmake cmake_minimum_required(VERSION 3.15...3.26) project(${SKBUILD_PROJECT_NAME} LANGUAGES C) ``` -------------------------------- ### Installation Rules Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/wrapper_setuptools_classic_layout/CMakeLists.txt Defines installation rules for the compiled library and header files. This specifies where the built artifacts will be placed. ```cmake install(TARGETS _core LIBRARY DESTINATION python/classic_layout_example) install(FILES data/example.h DESTINATION include/classic_layout_example) ``` -------------------------------- ### Write and Install Generated File Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/simplest_c/CMakeLists.txt Writes content to a file in the build directory and then installs it to a specific destination with a component. ```cmake file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/generated.txt "Testing") install( FILES ${CMAKE_CURRENT_BINARY_DIR}/generated.txt DESTINATION ${SKBUILD_PROJECT_NAME} COMPONENT Generated) ``` -------------------------------- ### Install Library Target Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/importlib_editable/src/pkg/sub_b/CMakeLists.txt Installs the 'emod_c' target to the 'pkg/sub_b' directory. ```cmake install(TARGETS emod_c DESTINATION pkg/sub_b) ``` -------------------------------- ### Build and Install Commands Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/guide/getting_started.md Commands to build and install a Python package using pipx or pip. ```console pipx run build ``` ```console pip install . ``` -------------------------------- ### Python Library and Installation Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/sdist_config/CMakeLists.txt Finds the Python components, adds a Python library, links it with a dependency, and installs it. This is standard for building Python extensions. ```cmake find_package( Python COMPONENTS Interpreter Development.Module REQUIRED) python_add_library(sdist_config MODULE main.c WITH_SOABI) target_link_libraries(sdist_config PRIVATE dummy_lib) install(TARGETS sdist_config DESTINATION .) ``` -------------------------------- ### Install Fortran Module Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/fortran_example/CMakeLists.txt Installs the compiled 'fibby' target to the root of the installation directory. ```cmake install(TARGETS fibby DESTINATION .) ``` -------------------------------- ### Install Library Target Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/importlib_editable/src/pkg/CMakeLists.txt Installs the 'emod_a' target to the 'pkg/' destination directory. ```cmake install(TARGETS emod_a DESTINATION pkg/) ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/dynamic_metadata/CMakeLists.txt Sets up a basic CMake project with C language support and versioning. Ensure the minimum CMake version is compatible. ```cmake cmake_minimum_required(VERSION 3.15...3.25) project( ${SKBUILD_PROJECT_NAME} LANGUAGES C VERSION ${SKBUILD_PROJECT_VERSION}) ``` -------------------------------- ### Install Library and Test File Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/importlib_editable/src/pkg/sub_b/sub_d/CMakeLists.txt Installs the built 'emod_e' target and a generated 'testfile' into the specified package destination. ```cmake install(TARGETS emod_e DESTINATION pkg/sub_b/sub_d/) ``` ```cmake file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testfile" "This is the file") ``` ```cmake install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile" DESTINATION pkg/sub_b/sub_d/) ``` -------------------------------- ### Install Metadata Files Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/simplest_c/CMakeLists.txt Writes metadata files and installs them to specific directories, including a dedicated licenses subdirectory. ```cmake file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/metadata_file.txt "Testing") file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt "Testing") install(FILES ${CMAKE_CURRENT_BINARY_DIR}/metadata_file.txt DESTINATION "${SKBUILD_METADATA_DIR}") install(FILES ${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt DESTINATION "${SKBUILD_METADATA_DIR}/licenses") ``` -------------------------------- ### Install Library Target Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/importlib_editable/src/pkg/sub_a/CMakeLists.txt Installs the 'emod_b' library target to the 'pkg/sub_a' destination. ```cmake install(TARGETS emod_b DESTINATION pkg/sub_a) ``` -------------------------------- ### Create and Install a Module Library Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/cmake_generated/CMakeLists.txt Defines a module library from a C source file and configures its properties, including export header generation and installation. ```cmake add_library(pkg MODULE src/cmake_generated/pkg.c) include(GenerateExportHeader) generate_export_header(pkg) target_include_directories(pkg PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) if(NOT WIN32) # Explicitly set the bundle extension to .so set_target_properties(pkg PROPERTIES SUFFIX ".so") endif() # Set the library name to "pkg", regardless of the OS convention. set_target_properties(pkg PROPERTIES PREFIX "") install(TARGETS pkg DESTINATION ${SKBUILD_PROJECT_NAME}) ``` -------------------------------- ### Install Testing Metadata Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/hatchling/cpp/CMakeLists.txt Writes a test metadata file and installs it to the extra metadata directory. ```cmake # Testing metadata file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/metadata_file.txt" "Testing") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/metadata_file.txt" DESTINATION "${SKBUILD_METADATA_DIR}/extra_metadata/") ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/broken_fallback/CMakeLists.txt Sets up the minimum CMake version, project name, and language. Includes a conditional fatal error for testing broken CMake configurations. ```cmake cmake_minimum_required(VERSION 3.15...3.26) project(${SKBUILD_PROJECT_NAME} LANGUAGES C) if(DEFINED BROKEN_CMAKE) message(FATAL_ERROR "Broken CMake") endif() ``` -------------------------------- ### Install Target Library Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/wrapper_setuptools_install_dir/CMakeLists.txt Installs the '_core' target as a library into the root of the installation directory. This makes the compiled module available for import in Python. ```cmake install(TARGETS _core LIBRARY DESTINATION .) ``` -------------------------------- ### Editable Install Configuration for Setuptools Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/plugins/setuptools.md Configure setuptools for PEP 660 editable installs by setting 'editable.mode' to 'inplace' in the [tool.scikit-build] section of pyproject.toml. ```toml [tool.scikit-build] editable.mode = "inplace" ``` -------------------------------- ### SWIG Interface File Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/guide/getting_started.md Example SWIG interface file for a C extension. ```swig %module example %{ int add(int i, int j); %} %include "std_string.i" int add(int i, int j); ``` -------------------------------- ### Install Python Module Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/simplest_c/CMakeLists.txt Installs the built module to the specified destination with a component name. ```cmake install( TARGETS _module DESTINATION ${SKBUILD_PROJECT_NAME} COMPONENT PythonModule) ``` -------------------------------- ### Build SDist and Wheel with pip Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/guide/build.md Install the 'build' package using pip and then run it to create your project's SDist and wheel. ```bash pip install build python -m build ``` -------------------------------- ### Write and Install No Wheel File Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/simplest_c/CMakeLists.txt Writes content to a file and installs it, similar to the ignored file, indicating it might not be included in wheel packages by default. ```cmake file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/generated_no_wheel.txt "Testing") install(FILES ${CMAKE_CURRENT_BINARY_DIR}/generated_no_wheel.txt DESTINATION ${SKBUILD_PROJECT_NAME}) ``` -------------------------------- ### Install Python Extension Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/abi3_pyproject_ext/CMakeLists.txt Installs the compiled Python extension module to the destination directory. ```cmake install(TARGETS abi3_example DESTINATION .) ``` -------------------------------- ### Install with Editable Rebuild Feature Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/configuration/index.md Use this command to enable the experimental rebuild on initial import feature for editable installs. Ensure dependencies are preinstalled and specify a build directory. ```console # Very experimental rebuild on initial import feature $ pip install --no-build-isolation --config-settings=editable.rebuild=true -Cbuild-dir=build -ve. ``` -------------------------------- ### Set custom wheel install directory Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/configuration/index.md Configure the `wheel.install-dir` option to specify a custom directory for installing wheel contents, deviating from the default site-packages. ```toml [tool.scikit-build] wheel.install-dir = "mypackage" ``` -------------------------------- ### Pybind11 CMake Integration Example Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/configuration/index.md Illustrates how to integrate pybind11 using FetchContent or add_subdirectory, conditionally based on the build state and file existence. ```cmake include(FetchContent) set(PYBIND11_FINDPYTHON ON) if(NOT SKBUILD_STATE STREQUAL "sdist" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/pybind11/CMakeLists.txt") message(STATUS "Using integrated pybind11") add_subdirectory(pybind11) else() FetchContent_Declare( pybind11 GIT_REPOSITORY https://github.com/pybind/pybind11.git GIT_TAG v2.12.0 SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/pybind11) FetchContent_MakeAvailable(pybind11) endif() ``` -------------------------------- ### Install Python Extension and Module Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/importlib_editable/src/CMakeLists.txt Installs the compiled Python extension module and a Python script to the destination directory. ```cmake install(TARGETS emod DESTINATION .) install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/pmod.py" DESTINATION .) ``` -------------------------------- ### Build SDist and Wheel with pipx Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/guide/build.md Use pipx to install and run the 'build' tool for creating an SDist and wheel from your project. ```bash pipx run build ``` -------------------------------- ### Install Python Module and Execute Command Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/dynamic_metadata/CMakeLists.txt Installs the created Python module and executes a command to print the Python version. This is useful for verification during the build process. ```cmake install(TARGETS _module DESTINATION ${SKBUILD_PROJECT_NAME}) install( CODE "execute_process(COMMAND ${Python_Executable} -V COMMAND_ECHO STDOUT)") ``` -------------------------------- ### Basic Hatchling Build Configuration Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/plugins/hatchling.md Example of a pyproject.toml file configuring Hatchling as the build backend and activating the scikit-build-core hook. ```toml [build-system] requires = ["hatchling", "scikit-build-core[hatchling]"] build-backend = "hatchling.build" [project] name = "hatchling_example" version = "0.1.0" [tool.hatch.build.targets.wheel.hooks.scikit-build] ``` -------------------------------- ### Executable Target and Installation Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/simple_pyproject_script_with_flags/CMakeLists.txt Adds an executable target, sets its properties for position-independent code, and installs it to a specified destination. Use this to build and deploy executables. ```cmake add_executable(cmake_example src/main.c) set_target_properties(cmake_example PROPERTIES POSITION_INDEPENDENT_CODE ON) install(TARGETS cmake_example DESTINATION "${SKBUILD_SCRIPTS_DIR}") ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/custom_cmake/CMakeLists.txt Sets the minimum CMake version and defines the project name, languages, and version. Ensure the CMake version is compatible with the features used. ```cmake cmake_minimum_required(VERSION 3.15...3.26) project( ${SKBUILD_PROJECT_NAME} LANGUAGES VERSION 2.3.4) ``` -------------------------------- ### Python Extension Module Setup Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/mixed_setuptools/CMakeLists.txt Finds the necessary Python components (Interpreter and Development.Module) and adds a C source file as a Python extension module library with a specific SOABI. ```cmake find_package( Python COMPONENTS Interpreter Development.Module REQUIRED) python_add_library(_core MODULE src/main.c WITH_SOABI) install(TARGETS _core LIBRARY DESTINATION mixed_setuptools) ``` -------------------------------- ### Enable Inplace Editable Install Mode Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/configuration/index.md Pass this configuration setting to enable the 'inplace' mode for editable installs. This mode performs an in-place CMake build and may require specific environment variable configurations for binaries. ```console -Ceditable.mode=inplace ``` -------------------------------- ### Create Python Extension Module Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/examples/getting_started/cython/CMakeLists.txt Adds a Python extension module named 'example' using the generated C code. The WITH_SOABI option ensures compatibility with the Python ABI. ```cmake python_add_library(example MODULE example.c WITH_SOABI) ``` -------------------------------- ### Disable Binary Stripping Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/configuration/index.md Turn off binary stripping during the installation process. ```toml install.strip false ``` -------------------------------- ### Configure Pybind11 Module Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/examples/getting_started/pybind11/CMakeLists.txt Sets up the project, finds pybind11, and adds a module. Ensure pybind11 is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.15...4.3) project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX) set(PYBIND11_FINDPYTHON ON) find_package(pybind11 CONFIG REQUIRED) pybind11_add_module(example example.cpp) install(TARGETS example LIBRARY DESTINATION .) ``` -------------------------------- ### CMake Project and Dependency Setup Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/sdist_config/CMakeLists.txt Configures the CMake project and conditionally includes a local dummy project or fetches it if not building an sdist. This ensures the dependency is bundled correctly. ```cmake cmake_minimum_required(VERSION 3.15...3.27) project( sdist_config LANGUAGES C VERSION ${SKBUILD_PROJECT_VERSION}) include(FetchContent) # The "dependency" is a tiny project committed under external/dummy; it is # "fetched" (copied) into the source tree so that sdist.cmake = true bundles it # into the sdist, where the integrated copy is used instead of re-fetching. if(NOT SKBUILD_STATE STREQUAL "sdist" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/dummy/CMakeLists.txt") message(STATUS "Using integrated dummy") add_subdirectory(dummy) else() message(STATUS "Fetching dummy project") FetchContent_Declare(dummy URL "${CMAKE_CURRENT_SOURCE_DIR}/external/dummy" SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/dummy) FetchContent_MakeAvailable(dummy) endif() ``` -------------------------------- ### Find Python Components and Add Library Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/broken_fallback/CMakeLists.txt Finds the Python interpreter and development components, then adds a Python module library named 'example' from 'main.c'. Conditional compilation definitions can be added. ```cmake find_package( Python COMPONENTS Interpreter Development.Module REQUIRED) python_add_library(example MODULE main.c WITH_SOABI) if(DEFINED BROKEN_CODE) target_compile_definitions(example PRIVATE BROKEN_CODE) endif() ``` -------------------------------- ### Basic Setuptools Build System Configuration Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/plugins/setuptools.md Configure your build system to use scikit-build-core's setuptools backend. Ensure both scikit-build-core and setuptools are listed in build-system.requires. ```toml [build-system] requires = ["scikit-build-core", "setuptools"] build-backend = "scikit_build_core.setuptools.build_meta" ``` -------------------------------- ### In-place Build Configuration Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/simplest_c/CMakeLists.txt Configures in-place builds for editable installations, ensuring correct library output directory for multi-config generators. ```cmake if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}" AND DEFINED SKBUILD) set_target_properties( _module PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/src/${SKBUILD_PROJECT_NAME}$<0:>") endif() ``` -------------------------------- ### Configure Verbosity and Logging with pip Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/configuration/index.md Use pip's --config-settings option to dynamically configure build verbosity and logging level during installation. Include the -v flag with pip to see any output. ```console $ pip install . -v --config-settings=build.verbose=true --config-settings=logging.level=INFO ``` -------------------------------- ### Configure C++ Extension Build Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/hatchling/cpp/CMakeLists.txt Sets up the minimum CMake version, project name, and language. Finds the Python interpreter and development components. Adds a C++ module library and installs it. ```cmake cmake_minimum_required(VERSION 3.15...3.29) project(extensionlib_example_cmake LANGUAGES C) find_package( Python COMPONENTS Interpreter Development.Module REQUIRED) python_add_library(_core MODULE example.c WITH_SOABI) if(SKBUILD_STATE STREQUAL "editable") # Keep multi-config generators from adding a Release/Debug subdir. set_target_properties( _core PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/../src/hatchling_example$<0:>") endif() install(TARGETS _core DESTINATION .) ``` -------------------------------- ### CMakeLists.txt for Simple Pure C Project Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/simple_pure/CMakeLists.txt This CMakeLists.txt file defines a minimal C project, creates an executable, and specifies installation targets. It also includes conditional messages based on SKBUILD environment variables. ```cmake cmake_minimum_required(VERSION 3.15...3.26) project(simple_pure LANGUAGES C) add_executable(simple_pure simple_pure.c) install(TARGETS simple_pure) if(DEFINED SKBUILD) message(STATUS "SKBUILD is defined to ${SKBUILD}") endif() if(DEFINED SKBUILD2) message(STATUS "SKBUILD2 is defined to ${SKBUILD2}") endif() ``` -------------------------------- ### Conditional Build System Requirements Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/configuration/dynamic.md Inject and manipulate additional build-system.requires conditionally. This example shows how to use a local folder as a dependency when building from source, while using a PyPI index for sdists. ```toml [project] name = "mypackage" [tool.scikit-build] build.requires = ["foo"] [[tool.scikit-build.overrides]] if.from-sdist = false build.requires = ["foo @ {root:uri}/foo"] ``` -------------------------------- ### Build SDist and Wheel with uv Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/guide/build.md Utilize uv to build your project's SDist and wheel. ```bash uv build ``` -------------------------------- ### Minimal setup.py for Setuptools Plugin Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/plugins/setuptools.md A minimal setup.py file is required to activate the scikit-build setuptools plugin. The presence of the 'cmake_source_dir' option signals the plugin to engage. ```python from setuptools import setup setup(cmake_source_dir=".") ``` -------------------------------- ### Inheriting and Appending Table/Array Configurations Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/configuration/overrides.md Use `inherit. = "append"` or `"prepend"` to modify table and array configurations. This example appends CMake defines, ensuring that existing defines are not overwritten when new ones are set. ```toml [tool.scikit-build] cmake.define.FOO = "0" cmake.define.BAR = "0" [[tool.scikit-build.overrides]] if.env.SET_FOO = "ON" inherit.cmake.define = "append" cmake.define.FOO = "1" [[tool.scikit-build.overrides]] if.env.SET_BAR = "ON" inherit.cmake.define = "append" cmake.define.BAR = "1" ``` -------------------------------- ### CMakeLists.txt Configuration and Checks Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/mixed_setuptools/CMakeLists.txt Sets up the minimum CMake version, project name, and language. Includes conditional checks that will cause a fatal error if specific defines are not set to expected values. ```cmake cmake_minimum_required(VERSION 3.15...3.26) project("${SKBUILD_PROJECT_NAME}" LANGUAGES C) if(NOT EXAMPLE_DEFINE1 EQUAL 1) message(FATAL_ERROR "Example define 1 is not set") endif() if(NOT EXAMPLE_DEFINE2 EQUAL 2) message(FATAL_ERROR "Example define 2 is not set") endif() if(NOT EXAMPLE_DEFINE3 EQUAL 3) message(FATAL_ERROR "Example define 3 is not set") endif() if(NOT EXAMPLE_DEFINE4 EQUAL 4) message(FATAL_ERROR "Example define 4 is not set") endif() if(NOT EXAMPLE_DEFINE5 EQUAL 5) message(FATAL_ERROR "Example define 5 is not set") endif() ``` -------------------------------- ### Scikit-build Builder Sysconfig Subcommand Help Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/reference/cli.md Displays help for the 'builder sysconfig' subcommand, which provides system configuration details. ```bash scikit-build builder sysconfig --help ``` -------------------------------- ### Scikit-build Main Help Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/reference/cli.md Displays the main help message for the scikit-build command, listing available subcommands. ```bash scikit-build ``` -------------------------------- ### Scikit-build Build Subcommand Help Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/reference/cli.md Shows help information for the 'build' subcommand, detailing its options and sub-options. ```bash scikit-build build --help ``` -------------------------------- ### Installing Custom Scripts with CMake Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/custom_cmake/CMakeLists.txt Installs a script file to a specified destination directory. The destination is typically defined by a CMake variable like SKBUILD_SCRIPTS_DIR. ```cmake install(PROGRAMS scripts/script1 DESTINATION "${SKBUILD_SCRIPTS_DIR}") ``` -------------------------------- ### Get Builder Information Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/reference/cli.md Retrieves information about the scikit-build builder environment. ```bash scikit-build builder ``` -------------------------------- ### Cython Source Code Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/guide/getting_started.md Example Cython source code for a Python extension. ```cython def add(int i, int j): """Adds two numbers""" return i + j ``` -------------------------------- ### Test scikit_build_example module Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/examples/downstream/pybind11_example/README.md Import and call a function from the scikit_build_example module. ```python import scikit_build_example scikit_build_example.add(1, 2) ``` -------------------------------- ### Fortran Extension Source Code Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/guide/getting_started.md Example Fortran source code for a Python extension. ```fortran subroutine add(i, j, result) integer, intent(in) :: i, j integer, intent(out) :: result result = i + j end subroutine add ``` -------------------------------- ### Scikit-build Build Project Table Subcommand Help Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/reference/cli.md Shows help for the 'build project-table' subcommand, used for displaying project information in a table format. ```bash scikit-build build project-table --help ``` -------------------------------- ### SWIG C Extension Source Code Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/guide/getting_started.md Example C source code for a SWIG extension. ```c int add(int i, int j) { return i + j; } ``` -------------------------------- ### nanobind C++ Extension Source Code Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/guide/getting_started.md Example C++ source code for a nanobind extension. ```cpp #include int add(int i, int j) { return i + j; } NB_MODULE(example, m) { m.doc() = "nanobind example plugin"; m.def("add", &add, "A function which adds two numbers"); } ``` -------------------------------- ### Add Nanobind Extension Module Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/examples/downstream/nanobind_example/CMakeLists.txt This directive defines and configures the Python extension module 'nanobind_example_ext'. It specifies build options like STABLE_ABI and NB_STATIC, and lists the source files. ```cmake # We are now ready to compile the actual extension module nanobind_add_module( # Name of the extension nanobind_example_ext # Target the stable ABI for Python 3.12+, which reduces the number of binary # wheels that must be built. This does nothing on older Python versions STABLE_ABI # Build libnanobind statically and merge it into the extension (which itself # remains a shared library) # # If your project builds multiple extensions, you can replace this flag by # NB_SHARED to conserve space by reusing a shared libnanobind across libraries NB_STATIC # Source code goes here src/nanobind_example_ext.cpp) ``` -------------------------------- ### pybind11 C++ Extension Source Code Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/guide/getting_started.md Example C++ source code for a pybind11 extension. ```cpp #include int add(int i, int j) { return i + j; } PYBIND11_MODULE(example, m) { m.doc() = "pybind11 example plugin"; // optional module docstring m.def("add", &add, "A function which adds two numbers"); } ``` -------------------------------- ### Set build.verbose via pip config-settings Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/reference/configs.md Pass the 'build.verbose' configuration setting when installing a package with pip. ```console $ pip install . --config-settings=build.verbose=true ``` -------------------------------- ### ABI3 Extension Source Code Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/guide/getting_started.md Example C source code for an ABI3 compliant Python extension. ```c #include int add(int i, int j) { return i + j; } static PyObject* py_add(PyObject* self, PyObject* args) { int i, j; if (!PyArg_ParseTuple(args, "ii", &i, &j)) { return NULL; } return PyLong_FromLong(add(i, j)); } static PyMethodDef ExampleMethods[] = { {"add", py_add, METH_VARARGS, "Add two numbers."}, {NULL, NULL, 0, NULL} /* Sentinel */ }; static struct PyModuleDef examplemodule = { PyModuleDef_HEAD_INIT, "example", /* name of module */ NULL, /* module documentation, may be NULL */ -1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */ ExampleMethods }; PyMODINIT_FUNC PyInit_example(void) { return PyModule_Create(&examplemodule); } ``` -------------------------------- ### Configure README Rendering with Fancy-PyPI-Readme Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/configuration/dynamic.md Integrate hatch-fancy-pypi-readme to render your project's README file. Specify the provider and any necessary configuration options for the hook. ```toml [project] name = "mypackage" dynamic = ["readme"] [tool.scikit-build] metadata.readme.provider = "scikit_build_core.metadata.fancy_pypi_readme" # tool.hatch.metadata.hooks.fancy-pypi-readme options here ``` -------------------------------- ### Get Wheel Tag Information Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/reference/cli.md Retrieves wheel tag information using the 'scikit-build builder wheel-tag' command. ```bash scikit-build builder wheel-tag ``` -------------------------------- ### Scikit-build Builder Subcommand Help Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/reference/cli.md Displays help for the 'builder' subcommand, which provides information about the build environment. ```bash scikit-build builder --help ``` -------------------------------- ### Build a Wheel Package Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/guide/build.md Use the 'build' tool with the --wheel flag to create a wheel package. This command reads pyproject.toml, sets up an isolated environment, and runs the build backend to produce the wheel file. ```bash pipx run build --wheel ``` -------------------------------- ### Python Module Configuration Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/wrapper_setuptools_classic_layout/CMakeLists.txt Finds the Python package and configures a C module. Ensure the Python development components are installed and available. ```cmake find_package( Python COMPONENTS Interpreter Development.Module REQUIRED) python_add_library(_core MODULE src/main.c WITH_SOABI) ``` -------------------------------- ### CMakeLists.txt for nanobind Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/guide/getting_started.md Set up your CMake build for nanobind. Requires CMake 3.15 or newer. Nanobind finds its configuration file from site-packages. ```cmake cmake_minimum_required(VERSION 3.15) project(my_package VERSION 0.0.1 LANGUAGES CXX) find_package(nanobind CONFIG REQUIRED) nanobind_add_module(my_package src/main.cpp) ``` -------------------------------- ### Adding a Python Extension Library Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/toml_setuptools_ext/CMakeLists.txt Creates a Python extension module named 'cmake_example' from the source file 'src/main.c'. The WITH_SOABI option ensures ABI compatibility. ```cmake python_add_library(cmake_example MODULE src/main.c WITH_SOABI) ``` -------------------------------- ### Configure Verbosity and Logging with build Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/configuration/index.md When using the 'build' package, pass configuration settings using the -C flag to control build verbosity and logging level. ```console $ pipx run build --wheel -Cbuild.verbose=true -Clogging.level=INFO ``` -------------------------------- ### Configure SDist Inclusion with CMake and Pybind11 Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/configuration/index.md Example configuration for including specific pybind11 directories in the sdist when CMake is enabled for sdist creation. ```toml [tool.scikit-build] sdist.cmake = true sdist.include = [ "pybind11/tools", "pybind11/include", "pybind11/CMakeLists.txt", ] ``` -------------------------------- ### Build SDist Manually without Isolation Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/guide/build.md Build an SDist directly using the 'build_sdist' function from scikit_build_core.build, bypassing the isolated environment setup. ```python python -c "from scikit_build_core.build import build_sdist; build_sdist('dist')" ``` -------------------------------- ### Example CMakeLists.txt for scikit-build-core Source: https://github.com/scikit-build/scikit-build-core/blob/main/README.md A basic CMakeLists.txt file to build a Python module using scikit-build-core. It finds the Python interpreter and adds a module library. ```cmake cmake_minimum_required(VERSION 3.15...3.30) project(${SKBUILD_PROJECT_NAME} LANGUAGES C) find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) Python_add_library(_module MODULE src/module.c WITH_SOABI) install(TARGETS _module DESTINATION ${SKBUILD_PROJECT_NAME}) ``` -------------------------------- ### CMakeLists.txt Configuration Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/simple_pyproject_source_dir/src/CMakeLists.txt Sets up the minimum CMake version, project name, language, and version. It also finds the necessary Python components for building modules. ```cmake cmake_minimum_required(VERSION 3.15...3.26) project( "${SKBUILD_PROJECT_NAME}" LANGUAGES C VERSION "${SKBUILD_PROJECT_VERSION}" ) find_package( Python COMPONENTS Interpreter Development.Module REQUIRED) python_add_library(cmake_example MODULE main.c WITH_SOABI) target_compile_definitions(cmake_example PRIVATE VERSION_INFO=${PROJECT_VERSION}) install(TARGETS cmake_example LIBRARY DESTINATION .) ``` -------------------------------- ### Check for Defined Variable Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/filepath_pure/CMakeLists.txt Checks if a variable is defined. This example specifically checks if `SOME_ARGS2` is defined and issues an error if it is, indicating an issue with argument combination. ```cmake if(DEFINED "${SOME_ARGS2}") message(FATAL_ERROR "args should not be combined, last one wins") endif() ``` -------------------------------- ### Configure Dynamic Version with Setuptools-scm Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/configuration/dynamic.md Use setuptools-scm to pull the package version from VCS. This TOML configuration sets the dynamic version and specifies the provider for scikit-build-core. ```toml [project] name = "mypackage" dynamic = ["version"] [tool.scikit-build] metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" sdist.include = ["src/package/_version.py"] [tool.setuptools_scm] # Section required write_to = "src/package/_version.py" ``` -------------------------------- ### Configure Project and Find Python Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/abi3_pyproject_ext/CMakeLists.txt Sets up the CMake project with C language support and finds the necessary Python components, including interpreter, development headers, and the SOABI component if defined. ```cmake cmake_minimum_required(VERSION 3.15...3.29) project( ${SKBUILD_PROJECT_NAME} LANGUAGES C VERSION ${SKBUILD_PROJECT_VERSION}) find_package( Python COMPONENTS Interpreter Development.Module ${SKBUILD_SABI_COMPONENT} REQUIRED) ``` -------------------------------- ### Get F2PY Include Directory Source: https://github.com/scikit-build/scikit-build-core/blob/main/tests/packages/fortran_example/CMakeLists.txt Executes a Python command to find the include directory for NumPy's F2PY headers, which are needed for Fortran-Python integration. ```cmake execute_process( COMMAND "${Python_EXECUTABLE}" -c "import numpy.f2py; print(numpy.f2py.get_include())" OUTPUT_VARIABLE F2PY_INCLUDE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) ``` -------------------------------- ### Build Both SDist and Wheel Packages Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/guide/build.md To build both a source distribution (SDist) and a wheel package directly from the source, use the --sdist --wheel flags with the 'build' tool. ```bash pipx run build --sdist --wheel ``` -------------------------------- ### Configure CMake Package Config for Export Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/configuration/search_paths.md This CMakeLists.txt snippet configures the package configuration file to be installed, enabling other projects to find this package using find_package. ```cmake include(CMakePackageConfigHelpers) include(GNUInstallDirs) write_basic_package_version_file( MyProjectConfigVersion.cmake VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion ) configure_package_config_file( cmake/MyProjectConfig.cmake.in MyProjectConfig.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/MyProject ) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/MyProjectConfigVersion.cmake ${CMAKE_CURRENT_BINARY_DIR}/MyProjectConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/MyProject ) ``` -------------------------------- ### CMakeLists.txt for SWIG Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/guide/getting_started.md Set up your CMake build for SWIG. Requires CMake 3.15 or newer. You will need to manage SWIG file generation separately. ```cmake cmake_minimum_required(VERSION 3.15) project(my_package VERSION 0.0.1 LANGUAGES CXX) # SWIG generation needs to be handled manually ``` -------------------------------- ### Scikit-build Builder Wheel Tag Subcommand Help Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/reference/cli.md Shows help for the 'builder wheel-tag' subcommand, used for determining wheel compatibility tags. ```bash scikit-build builder wheel-tag --help ``` -------------------------------- ### Disable Python file inclusion Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/configuration/index.md Set `wheel.packages` to an empty list to disable automatic Python file inclusion and rely solely on CMake's install mechanism. ```toml [tool.scikit-build] wheel.packages = [] ``` -------------------------------- ### Configure pyproject.toml for CMake Root Export Source: https://github.com/scikit-build/scikit-build-core/blob/main/docs/configuration/search_paths.md This pyproject.toml configuration sets the wheel install directory and defines the 'cmake.root' entry-point, allowing dependent projects to use find_package. ```toml [tool.scikit-build] wheel.install-dir = "myproject" [project.entry-points."cmake.root"] MyProject = "myproject" ```