Skip to content

Commit

Permalink
backport WITH_SOABI (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbachmann authored Sep 27, 2022
1 parent c45bd04 commit 6f2d5de
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ else()
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
endif()

if("${Python_INTERPRETER_ID}" STREQUAL "PyPy")
if(CMAKE_VERSION VERSION_LESS 3.17)
execute_process(
COMMAND "${Python_EXECUTABLE}" -c
"import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX').split('.')[1])"
OUTPUT_VARIABLE Python_SOABI
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ECHO STDOUT)
message(STATUS "Corrected SOABI: ${Python_SOABI}")
elseif("${Python_INTERPRETER_ID}" STREQUAL "PyPy")
message(STATUS "PyPy SOABI: ${Python_SOABI}")
execute_process(
COMMAND "${Python_EXECUTABLE}" -c
Expand Down
29 changes: 21 additions & 8 deletions src/Levenshtein/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@

function(create_cython_target _name)
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/${_name}.cxx)
set(${_name} ${CMAKE_CURRENT_LIST_DIR}/${_name}.cxx PARENT_SCOPE)
else()
find_package(Cython REQUIRED)
add_cython_target(${_name} CXX)
set(${_name} ${_name} PARENT_SCOPE)
endif()
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/${_name}.cxx)
set(${_name} ${CMAKE_CURRENT_LIST_DIR}/${_name}.cxx PARENT_SCOPE)
else()
find_package(Cython REQUIRED)
add_cython_target(${_name} CXX)
set(${_name} ${_name} PARENT_SCOPE)
endif()
endfunction(create_cython_target)

function(rf_add_library name)
if(CMAKE_VERSION VERSION_LESS 3.17)
Python_add_library(${name} MODULE ${ARGV})
get_property(suffix TARGET ${name} PROPERTY SUFFIX)
if (NOT suffix)
set (suffix "${CMAKE_SHARED_MODULE_SUFFIX}")
endif()
set_property (TARGET ${name} PROPERTY SUFFIX ".${Python_SOABI}${suffix}")
else()
Python_add_library(${name} MODULE WITH_SOABI ${ARGV})
endif()
endfunction(rf_add_library)

create_cython_target(levenshtein_cpp)
Python_add_library(levenshtein_cpp MODULE WITH_SOABI ${levenshtein_cpp} ${LEV_BASE_DIR}/Levenshtein-c/_levenshtein.cpp)
rf_add_library(levenshtein_cpp ${levenshtein_cpp} ${LEV_BASE_DIR}/Levenshtein-c/_levenshtein.cpp)
target_compile_features(levenshtein_cpp PUBLIC cxx_std_17)
target_include_directories(levenshtein_cpp PRIVATE ${LEV_BASE_DIR}/Levenshtein-c)
target_link_libraries(levenshtein_cpp PRIVATE rapidfuzz::rapidfuzz)
Expand Down

0 comments on commit 6f2d5de

Please sign in to comment.