-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
60 lines (47 loc) · 2.16 KB
/
CMakeLists.txt
File metadata and controls
60 lines (47 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Set the minimum CMake version and policies for highest tested version
cmake_minimum_required(VERSION 3.15...3.27)
# Set default build type in CMake if skbuild is set
message(STATUS "CMAKE_BUILD_TYPE set to '${CMAKE_BUILD_TYPE}'")
# Set up the project and ensure there is a working C++ compiler
project(varipeps_extensions LANGUAGES CXX)
# Try to import all Python components potentially needed by nanobind
find_package(Python 3.11
REQUIRED COMPONENTS Interpreter Development.Module
OPTIONAL_COMPONENTS Development.SABIModule)
# Import nanobind through CMake's find_package mechanism
execute_process(
COMMAND /usr/bin/env python3 -m nanobind --cmake_dir
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_ROOT)
find_package(nanobind CONFIG REQUIRED)
# Find jaxlib include dir
IF (WIN32)
execute_process(
COMMAND python -c "import inspect; import jaxlib; import pathlib; p = pathlib.Path(inspect.getfile(jaxlib)); print(p.parent / 'include')"
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE jaxlib_INCLUDE_DIR)
ELSE()
execute_process(
COMMAND /usr/bin/env python3 -c "import inspect; import jaxlib; import pathlib; p = pathlib.Path(inspect.getfile(jaxlib)); print(p.parent / 'include')"
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE jaxlib_INCLUDE_DIR)
ENDIF()
# We are now ready to compile the actual extension module
nanobind_add_module(
# Name of the extension
_svd_only_u_vt
# 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
varipeps/utils/extensions/svd_ffi.cpp
)
target_include_directories(_svd_only_u_vt PRIVATE "${jaxlib_INCLUDE_DIR}")
# target_link_libraries(_svd_only_vt PRIVATE lapack)
# Install directive for scikit-build-core
install(TARGETS _svd_only_u_vt LIBRARY DESTINATION varipeps/utils/extensions)