|
| 1 | +cmake_minimum_required(VERSION 3.15...3.27) |
| 2 | +project(${SKBUILD_PROJECT_NAME} LANGUAGES C) |
| 3 | + |
| 4 | +# Find Python |
| 5 | +find_package( |
| 6 | + Python |
| 7 | + COMPONENTS Interpreter Development.Module NumPy |
| 8 | + REQUIRED) |
| 9 | + |
| 10 | +# Get NumPy include directory |
| 11 | +message(STATUS "NumPy include directory: ${Python_NumPy_INCLUDE_DIRS}") |
| 12 | + |
| 13 | +# Cythonize the .pyx file to .c |
| 14 | +add_custom_command( |
| 15 | + OUTPUT cutil.c |
| 16 | + COMMENT "Cythonizing ${CMAKE_CURRENT_SOURCE_DIR}/src/simplification/cutil.pyx" |
| 17 | + COMMAND Python::Interpreter -m cython |
| 18 | + "${CMAKE_CURRENT_SOURCE_DIR}/src/simplification/cutil.pyx" |
| 19 | + --output-file cutil.c |
| 20 | + -I "${CMAKE_CURRENT_SOURCE_DIR}/src/simplification" |
| 21 | + DEPENDS src/simplification/cutil.pyx src/simplification/rdp_p.pxd |
| 22 | + VERBATIM) |
| 23 | + |
| 24 | +# Create the extension module |
| 25 | +python_add_library(cutil MODULE cutil.c WITH_SOABI) |
| 26 | + |
| 27 | +# Set include directories |
| 28 | +target_include_directories(cutil PRIVATE |
| 29 | + ${CMAKE_CURRENT_SOURCE_DIR}/src/simplification |
| 30 | + ${Python_NumPy_INCLUDE_DIRS} |
| 31 | +) |
| 32 | + |
| 33 | +# Link against the rdp library |
| 34 | +# The library is pre-built and located in src/simplification/ |
| 35 | +find_library(RDP_LIBRARY |
| 36 | + NAMES rdp librdp |
| 37 | + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/src/simplification |
| 38 | + NO_DEFAULT_PATH |
| 39 | + REQUIRED |
| 40 | +) |
| 41 | +message(STATUS "Found RDP library: ${RDP_LIBRARY}") |
| 42 | + |
| 43 | +target_link_libraries(cutil PRIVATE ${RDP_LIBRARY}) |
| 44 | + |
| 45 | +# Set RPATH for different platforms |
| 46 | +if(APPLE) |
| 47 | + set_target_properties(cutil PROPERTIES |
| 48 | + INSTALL_RPATH "@loader_path" |
| 49 | + BUILD_WITH_INSTALL_RPATH TRUE |
| 50 | + ) |
| 51 | +elseif(UNIX) |
| 52 | + set_target_properties(cutil PROPERTIES |
| 53 | + INSTALL_RPATH "$ORIGIN" |
| 54 | + BUILD_WITH_INSTALL_RPATH TRUE |
| 55 | + ) |
| 56 | +endif() |
| 57 | + |
| 58 | +# Install the extension module |
| 59 | +install(TARGETS cutil DESTINATION simplification) |
| 60 | + |
| 61 | +# Install the shared library |
| 62 | +if(APPLE) |
| 63 | + set(RDP_LIB_NAME "librdp.dylib") |
| 64 | +elseif(UNIX) |
| 65 | + set(RDP_LIB_NAME "librdp.so") |
| 66 | +elseif(WIN32) |
| 67 | + set(RDP_LIB_NAME "rdp.dll") |
| 68 | +endif() |
| 69 | + |
| 70 | +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/simplification/${RDP_LIB_NAME} |
| 71 | + DESTINATION simplification) |
| 72 | + |
| 73 | +# Install header file |
| 74 | +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/simplification/header.h |
| 75 | + DESTINATION simplification) |
0 commit comments