1- project (nanobind_example)
21cmake_minimum_required (VERSION 3.18...3.22)
32
3+ project (nanobind_example)
4+
45if (NOT SKBUILD)
56 message (WARNING "\
67 This CMake file is meant to be executed using 'scikit-build'. Running
@@ -20,40 +21,26 @@ if (NOT SKBUILD)
2021 =====================================================================" )
2122endif ()
2223
23- # The following boilerplate code configures CMake so that it finds the right
24- # Python version (in particular, when it is run as part of 'scikit-build' using
25- # the GitHub Actions continuous integration server)
26- if (SKBUILD)
27- # Fix missing shared library name for cibuildwheel+windows+pypy3.9
28- if (MSVC AND NOT PYTHON_LIBRARY AND (${PYTHON_VERSION_STRING} MATCHES "3.9." ))
29- get_filename_component (PYTHON_LIBRARY ${PYTHON_INCLUDE_DIR} DIRECTORY )
30- set (PYTHON_LIBRARY "${PYTHON_LIBRARY} /libs/python39.lib" )
31- endif ()
32-
33- set (Python_VERSION "${PYTHON_VERSION_STRING} " )
34- set (Python_EXECUTABLE "${PYTHON_EXECUTABLE} " )
35- set (Python_INCLUDE_DIR "${PYTHON_INCLUDE_DIR} " )
36- set (Python_LIBRARY "${PYTHON_LIBRARY} " )
37- elseif (MSVC )
38- # MSVC needs a little extra help finding the Python library
39- find_package (PythonInterp)
40- find_package (Python)
24+ # Perform a release build by default
25+ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
26+ set (CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
27+ set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo" )
4128endif ()
4229
4330# Create CMake targets for all Python components needed by nanobind
44- if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.26)
31+ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.26 AND Python_INTERPRETER_ID STREQUAL "Python" )
4532 find_package (Python 3.8 COMPONENTS Interpreter Development.Module Development.SABIModule REQUIRED)
4633else ()
4734 find_package (Python 3.8 COMPONENTS Interpreter Development.Module REQUIRED)
4835endif ()
4936
50- # Run ` nanobind.cmake_dir()` from Python to detect where nanobind is installed
37+ # Determine the nanobind CMake include path and register it
5138execute_process (
52- COMMAND "${Python_EXECUTABLE} " -c "import nanobind; print(nanobind. cmake_dir())"
39+ COMMAND "${Python_EXECUTABLE} " -m nanobind -- cmake_dir
5340 OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE NB_DIR)
5441list (APPEND CMAKE_PREFIX_PATH "${NB_DIR} " )
5542
56- # Now, import nanobind through CMake's find_package mechanism
43+ # Import nanobind through CMake's find_package mechanism
5744find_package (nanobind CONFIG REQUIRED)
5845
5946# We are now ready to compile the actual extension module
0 commit comments