-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
72 lines (62 loc) · 2.67 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 3.26...3.27)
project(fastwave LANGUAGES CXX)
# Warn if the user invokes CMake directly
if (NOT SKBUILD)
message(WARNING "\
This CMake file is meant to be executed using 'scikit-build-core'.
Running it directly will almost certainly not produce the desired
result. If you are a user trying to install this package, use the
command below, which will install all necessary build dependencies,
compile the package in an isolated environment, and then install it.
=====================================================================
$ pdm install --no-lock
=====================================================================
If you are a software developer, you need to rerun the above after
editing C++ files.")
endif()
find_package(Python 3.9
REQUIRED COMPONENTS Interpreter Development.Module
OPTIONAL_COMPONENTS Development.SABIModule)
# Force Release build
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
# Compiler flags
# Set default compile flags for GCC
if(CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
set(CMAKE_CXX_FLAGS "-Wall -Wextra")
endif()
set(CMAKE_CXX_FLAGS_RELEASE "-O3") # is -O3 worth it? -O2
# Find libs nanobind
# Detect the installed nanobind package and import it into CMake
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/nanobind)
find_package(nanobind CONFIG REQUIRED)
# https://nanobind.readthedocs.io/en/latest/api_cmake.html#low-level-interface
# nanobind_add_module(
# # Name of the extension
# _fastwave
# # 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
# # Source code goes here
# src/_fastwave.cpp
# )
# https://nanobind.readthedocs.io/en/latest/faq.html#importing-fails-due-to-missing-lib-nanobind-dylib-so-dll
# ^ need to add -static to WA @rpath on MacOS
nanobind_build_library(nanobind-static-abi3 STATIC)
add_library(_fastwave MODULE src/_fastwave.cpp)
target_link_libraries(_fastwave PRIVATE nanobind-static-abi3)
nanobind_opt_size(_fastwave)
nanobind_lto(_fastwave)
nanobind_set_visibility(_fastwave)
nanobind_strip(_fastwave)
nanobind_disable_stack_protector(_fastwave)
nanobind_extension_abi3(_fastwave) # with nanobind-abi3
nanobind_extension(_fastwave)
nanobind_compile_options(_fastwave)
nanobind_link_options(_fastwave)
nanobind_musl_static_libcpp(_fastwave)
# Install directive for scikit-build-core
install(TARGETS _fastwave LIBRARY DESTINATION fastwave)