Skip to content

Commit 63ccdb5

Browse files
authored
Switch to cython-cmake util for scikit-build (#108)
1 parent 8034cde commit 63ccdb5

2 files changed

Lines changed: 20 additions & 19 deletions

File tree

CMakeLists.txt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
cmake_minimum_required(VERSION 3.15)
1+
cmake_minimum_required(VERSION 3.21)
22
project(${SKBUILD_PROJECT_NAME} LANGUAGES C)
33

4+
# Define source directory
5+
set(convertbng_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/convertbng")
6+
47
# Find Python
58
find_package(
69
Python
710
COMPONENTS Interpreter Development.Module NumPy
811
REQUIRED)
12+
include(UseCython)
913

1014
# Get NumPy include directory
1115
message(STATUS "NumPy include directory: ${Python_NumPy_INCLUDE_DIRS}")
1216

13-
# Cythonize the .pyx file to .c
14-
add_custom_command(
15-
OUTPUT cutil.c
16-
COMMENT "Cythonizing ${CMAKE_CURRENT_SOURCE_DIR}/src/convertbng/cutil.pyx"
17-
COMMAND Python::Interpreter -m cython
18-
"${CMAKE_CURRENT_SOURCE_DIR}/src/convertbng/cutil.pyx"
19-
--output-file cutil.c
20-
-I "${CMAKE_CURRENT_SOURCE_DIR}/src/convertbng"
21-
DEPENDS src/convertbng/cutil.pyx src/convertbng/convertbng_p.pxd
22-
VERBATIM)
17+
cython_transpile(
18+
"${convertbng_SRC_DIR}/cutil.pyx"
19+
LANGUAGE C
20+
OUTPUT_VARIABLE cutil
21+
CYTHON_ARGS -I "${convertbng_SRC_DIR}"
22+
)
2323

2424
# Create the extension module
25-
python_add_library(cutil MODULE cutil.c WITH_SOABI)
25+
python_add_library(cutil MODULE "${cutil}" WITH_SOABI)
2626

2727
# Set include directories
2828
target_include_directories(cutil PRIVATE
29-
${CMAKE_CURRENT_SOURCE_DIR}/src/convertbng
29+
${convertbng_SRC_DIR}
3030
${Python_NumPy_INCLUDE_DIRS}
3131
)
3232

3333
# Link against the Rust library
3434
# The library is pre-built and located in src/convertbng/
3535
find_library(LONLAT_BNG_LIBRARY
3636
NAMES lonlat_bng liblonlat_bng
37-
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/src/convertbng
37+
PATHS ${convertbng_SRC_DIR}
3838
NO_DEFAULT_PATH
3939
REQUIRED
4040
)
@@ -60,16 +60,16 @@ install(TARGETS cutil DESTINATION convertbng)
6060

6161
# Install the shared library
6262
if(APPLE)
63-
set(RDP_LIB_NAME "liblonlat_bng.dylib")
63+
set(LONLAT_BNG_LIB_NAME "liblonlat_bng.dylib")
6464
elseif(UNIX)
65-
set(RDP_LIB_NAME "liblonlat_bng.so")
65+
set(LONLAT_BNG_LIB_NAME "liblonlat_bng.so")
6666
elseif(WIN32)
67-
set(RDP_LIB_NAME "lonlat_bng.dll")
67+
set(LONLAT_BNG_LIB_NAME "lonlat_bng.dll")
6868
endif()
6969

70-
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/convertbng/${RDP_LIB_NAME}
70+
install(FILES ${convertbng_SRC_DIR}/${LONLAT_BNG_LIB_NAME}
7171
DESTINATION convertbng)
7272

7373
# Install header file
74-
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/convertbng/header.h
74+
install(FILES ${convertbng_SRC_DIR}/header.h
7575
DESTINATION convertbng)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ requires = [
4444
"scikit-build-core>=0.10",
4545
"numpy >= 2.0.0",
4646
"cython >= 3.1.0",
47+
"cython-cmake"
4748
]
4849
build-backend = "scikit_build_core.build"
4950

0 commit comments

Comments
 (0)