-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
115 lines (103 loc) · 4.35 KB
/
Copy pathCMakeLists.txt
File metadata and controls
115 lines (103 loc) · 4.35 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2026 Fernando Sahmkow
#
# Native Python bindings for whiteout_lib via pybind11.
#
# Activated by `-DWHITEOUT_BUILD_PYTHON_BINDINGS=ON`. Requires Python +
# pybind11 (auto-detected via the active venv or the system installation).
if(NOT WHITEOUT_BUILD_PYTHON_BINDINGS)
return()
endif()
# Find a Python interpreter and the pybind11 it ships, in that order:
# 1. The active virtualenv (resolved via Python_EXECUTABLE).
# 2. Whatever Python_FIND_VIRTUALENV/Python_FIND_REGISTRY pick up.
find_package(Python 3.10 REQUIRED COMPONENTS Interpreter Development.Module)
# Locate pybind11's CMake helpers via the Python package itself —
# avoids needing pybind11 installed system-wide.
execute_process(
COMMAND "${Python_EXECUTABLE}" -c
"import pybind11, sys; sys.stdout.write(pybind11.get_cmake_dir())"
OUTPUT_VARIABLE pybind11_DIR
RESULT_VARIABLE _pybind11_exit
)
if(NOT _pybind11_exit EQUAL 0)
message(FATAL_ERROR "pybind11 not found in ${Python_EXECUTABLE}; "
"install it with `pip install pybind11`")
endif()
find_package(pybind11 CONFIG REQUIRED)
pybind11_add_module(whiteout MODULE
module.cpp
mdx_bindings.cpp
m2_bindings.cpp
m3_bindings.cpp
textures_bindings.cpp
utils_bindings.cpp
host_bindings.cpp
$<$<BOOL:${WHITEOUT_ENABLE_MPQ}>:${CMAKE_CURRENT_SOURCE_DIR}/mpq_bindings.cpp>
$<$<BOOL:${WHITEOUT_ENABLE_CASC}>:${CMAKE_CURRENT_SOURCE_DIR}/casc_bindings.cpp>
)
target_link_libraries(whiteout PRIVATE whiteout_lib)
if(WHITEOUT_ENABLE_MPQ)
target_link_libraries(whiteout PRIVATE whiteout_mpq)
target_compile_definitions(whiteout PRIVATE WHITEOUT_HAS_MPQ=1)
endif()
if(WHITEOUT_ENABLE_CASC)
target_link_libraries(whiteout PRIVATE whiteout_casc)
target_compile_definitions(whiteout PRIVATE WHITEOUT_HAS_CASC=1)
endif()
target_include_directories(whiteout PRIVATE
${CMAKE_SOURCE_DIR}/include
)
# Match the rest of the project's C++ standard.
target_compile_features(whiteout PRIVATE cxx_std_20)
# Stage the resulting .pyd / .so into a flat directory next to the source
# so a Python user can `sys.path.insert(0, '<repo>/bindings/python')` and
# `import whiteout` without an install step.
set_target_properties(whiteout PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/python-dist"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/python-dist"
)
# When building a wheel via scikit-build-core, also generate Python type
# stubs and install everything (extension + stubs) into the wheel layout.
if(WHITEOUT_BUILD_PYTHON_WHEEL)
set(_stubs_dir "${CMAKE_CURRENT_BINARY_DIR}/whiteout-stubs")
file(MAKE_DIRECTORY ${_stubs_dir})
# Codegen: produce <stub>.pyi for every module. Runs at configure time
# so the generated files are present when install() rules fire below.
foreach(_mod IN ITEMS mdx m2 m3 textures)
execute_process(
COMMAND ${Python_EXECUTABLE} -m tools.codegen.codegen ${_mod}
--backend pyi
--repo-root ${CMAKE_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE _codegen_out
ERROR_VARIABLE _codegen_err
RESULT_VARIABLE _codegen_rc
)
if(NOT _codegen_rc EQUAL 0)
message(FATAL_ERROR
"pyi codegen for '${_mod}' failed (exit ${_codegen_rc}):\n"
"${_codegen_err}")
endif()
# Codegen emits to packages/python/whiteout-stubs/<mod>.pyi by
# default — pull it into the build dir for install().
configure_file(
"${CMAKE_SOURCE_DIR}/packages/python/whiteout-stubs/${_mod}.pyi"
"${_stubs_dir}/${_mod}.pyi"
COPYONLY
)
endforeach()
# Hand-written stub package files (tracked in templates/).
file(COPY
"${CMAKE_SOURCE_DIR}/bindings/templates/python/whiteout-stubs/__init__.pyi"
"${CMAKE_SOURCE_DIR}/bindings/templates/python/whiteout-stubs/py.typed"
DESTINATION ${_stubs_dir}
)
# Install rules — scikit-build-core picks these up to assemble the wheel:
#
# site-packages/whiteout.cp<ver>-<plat>.pyd
# site-packages/whiteout-stubs/{__init__.pyi, py.typed, mdx.pyi, ...}
install(TARGETS whiteout LIBRARY DESTINATION . RUNTIME DESTINATION .)
install(DIRECTORY ${_stubs_dir}/
DESTINATION whiteout-stubs)
endif()