3131 set (DEV_MODULE Development.Module)
3232endif ()
3333
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+
3437find_package (Python 3.8 COMPONENTS Interpreter ${DEV_MODULE} )
3538
3639# Import nanobind through CMake's find_package mechanism
@@ -48,18 +51,33 @@ execute_process(
4851 OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_ROOT )
4952find_package (nanobind CONFIG REQUIRED )
5053
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+
5168# Check the USE_ASAN environment variable, and if set to 1, enable AddressSanitizer
5269if (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 )
5572endif ()
5673
74+
5775nanobind_add_module (
5876 voyager_ext
5977 # Target the stable ABI for Python 3.12+, which reduces
6078 # the number of binary wheels that must be built. This
6179 # does nothing on older Python versions
62- NB_STATIC STABLE_ABI LTO FREE_THREADED
80+ NB_STATIC STABLE_ABI LTO FREE_THREADED NOMINSIZE
6381 # Sources:
6482 src/bindings.cpp
6583)
0 commit comments