From ebe422ceaf44c240bfc8e43a7e1dc023d9d584ba Mon Sep 17 00:00:00 2001 From: dofuuz <8174871+dofuuz@users.noreply.github.com> Date: Fri, 30 Aug 2024 20:48:54 +0900 Subject: [PATCH] Skip stub gen when cross-compiling, Find system libsoxr properly --- CMakeLists.txt | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2348636..eb701aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,22 +65,35 @@ nanobind_add_module(soxr_ext STABLE_ABI NB_STATIC ${CSOXR_VER_C} ) -nanobind_add_stub(soxr_ext_stub - MODULE soxr_ext - OUTPUT soxr_ext.pyi - PYTHON_PATH $ - DEPENDS soxr_ext -) +if (NOT CMAKE_CROSSCOMPILING) + # nanobind's stub generation requires importing the module, so skip it when cross-compiling + nanobind_add_stub(soxr_ext_stub + MODULE soxr_ext + OUTPUT soxr_ext.pyi + PYTHON_PATH $ + DEPENDS soxr_ext + ) -target_link_libraries(soxr_ext PRIVATE - soxr -) + install(FILES ${CMAKE_BINARY_DIR}/soxr_ext.pyi DESTINATION soxr) +endif () # Install directive for scikit-build-core install(TARGETS soxr_ext LIBRARY DESTINATION soxr) -install(FILES ${CMAKE_BINARY_DIR}/soxr_ext.pyi DESTINATION soxr) -if (NOT USE_SYSTEM_LIBSOXR) +if (USE_SYSTEM_LIBSOXR) + # Find system libsoxr + find_library(SOXR_LIBRARY NAMES soxr) + find_path(SOXR_INCLUDE_DIR soxr.h) + + message (STATUS "Building with external libsoxr") + message(SOXR_LIBRARY="${SOXR_LIBRARY}") + message(SOXR_INCLUDE_DIR="${SOXR_INCLUDE_DIR}") + + target_link_libraries(soxr_ext PRIVATE ${SOXR_LIBRARY}) + target_include_directories(soxr_ext PRIVATE ${SOXR_INCLUDE_DIR}) + +else () + target_link_libraries(soxr_ext PRIVATE soxr) target_include_directories(soxr_ext PRIVATE src libsoxr/src