31
31
set (DEV_MODULE Development.Module )
32
32
endif ()
33
33
34
+ set (IS_UNIX ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" )
35
+ set (IS_WINDOWS ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" )
36
+
34
37
find_package (Python 3.8 COMPONENTS Interpreter ${DEV_MODULE} )
35
38
36
39
# Import nanobind through CMake's find_package mechanism
@@ -48,18 +51,33 @@ execute_process(
48
51
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_ROOT )
49
52
find_package (nanobind CONFIG REQUIRED )
50
53
54
+ # Allow for some math optimization on unix but not -ffast-math
55
+ # See: https://simonbyrne.github.io/notes/fastmath/#flushing_subnormals_to_zero
56
+ if (IS_UNIX )
57
+ add_compile_options (-fassociative-math -fno-signaling-nans -fno-trapping-math -fno-signed-zeros -freciprocal-math -fno-math-errno )
58
+ endif ()
59
+
60
+ # Relase build with all optimizations
61
+ if (CMAKE_BUILD_TYPE STREQUAL "Release" AND IS_UNIX )
62
+ add_compile_options (-O3 )
63
+ elseif (CMAKE_BUILD_TYPE STREQUAL "Release" AND IS_WINDOWS )
64
+ add_compile_options (/Ox )
65
+ endif ()
66
+
67
+
51
68
# Check the USE_ASAN environment variable, and if set to 1, enable AddressSanitizer
52
69
if (DEFINED ENV{USE_ASAN} AND "$ENV{USE_ASAN} " STREQUAL "1" )
53
- set ( CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer" )
54
- set ( CMAKE_EXE_LINKER_FLAGS " ${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address" )
70
+ add_compile_options ( -fsanitize=address -fno-omit-frame-pointer )
71
+ add_link_options ( -fsanitize=address )
55
72
endif ()
56
73
74
+
57
75
nanobind_add_module (
58
76
voyager_ext
59
77
# Target the stable ABI for Python 3.12+, which reduces
60
78
# the number of binary wheels that must be built. This
61
79
# does nothing on older Python versions
62
- NB_STATIC STABLE_ABI LTO FREE_THREADED
80
+ NB_STATIC STABLE_ABI LTO FREE_THREADED NOMINSIZE
63
81
# Sources:
64
82
src/bindings.cpp
65
83
)
0 commit comments