Skip to content

Commit

Permalink
Fix naming of ABI3 extension libraries on Windows
Browse files Browse the repository at this point in the history
This commit fixes the naming conventions of ABI3 builds on Windows. It
also adopts a recent CMake/FindPython interface whenever available.
  • Loading branch information
wjakob committed May 31, 2023
1 parent e08d161 commit ae87fe8
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions cmake/nanobind-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,34 @@ if (NOT TARGET Python::Module)
message(FATAL_ERROR "You must invoke 'find_package(Python COMPONENTS Interpreter Development REQUIRED)' prior to including nanobind.")
endif()

# Determine the Python extension suffix and stash in the CMake cache
execute_process(
COMMAND "${Python_EXECUTABLE}" "-c"
"import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"
RESULT_VARIABLE NB_SUFFIX_RET
OUTPUT_VARIABLE NB_SUFFIX
OUTPUT_STRIP_TRAILING_WHITESPACE)

if (NB_SUFFIX_RET AND NOT NB_SUFFIX_RET EQUAL 0)
message(FATAL_ERROR "nanobind: Python sysconfig query to "
"find 'EXT_SUFFIX' property failed!")
# Determine the the right suffix for ordinary and stable ABI extensions
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.26)
set(NB_SUFFIX ${Python_SOABI})
set(NB_SUFFIX_S ${Python_SOSABI})
else()
# Determine the Python extension suffix and stash in the CMake cache
execute_process(
COMMAND "${Python_EXECUTABLE}" "-c"
"import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"
RESULT_VARIABLE NB_SUFFIX_RET
OUTPUT_VARIABLE NB_SUFFIX
OUTPUT_STRIP_TRAILING_WHITESPACE)

if (NB_SUFFIX_RET AND NOT NB_SUFFIX_RET EQUAL 0)
message(FATAL_ERROR "nanobind: Python sysconfig query to "
"find 'EXT_SUFFIX' property failed!")
endif()

get_filename_component(NB_SUFFIX_EXT "${NB_SUFFIX}" LAST_EXT)
if (WIN32)
set(NB_SUFFIX_S ".${NB_SUFFIX_EXT}")
else()
set(NB_SUFFIX_S ".abi3${NB_SUFFIX_EXT}")
endif()
endif()

set(NB_SUFFIX ${NB_SUFFIX} CACHE INTERNAL "")
set(NB_SUFFIX ${NB_SUFFIX} CACHE INTERNAL "")
set(NB_SUFFIX_S ${NB_SUFFIX_S} CACHE INTERNAL "")

get_filename_component(NB_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(NB_DIR "${NB_DIR}" PATH)
Expand Down Expand Up @@ -194,8 +208,7 @@ function(nanobind_extension name)
endfunction()

function(nanobind_extension_abi3 name)
get_filename_component(ext "${NB_SUFFIX}" LAST_EXT)
set_target_properties(${name} PROPERTIES PREFIX "" SUFFIX ".abi3${ext}")
set_target_properties(${name} PROPERTIES PREFIX "" SUFFIX "${NB_SUFFIX_S}")
endfunction()

function (nanobind_lto name)
Expand Down

0 comments on commit ae87fe8

Please sign in to comment.