Skip to content

Commit

Permalink
fix: try supporting older CMake
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Jun 26, 2024
1 parent 90e41de commit 4e9afe2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ jobs:
- python-version: "3.9"
runs-on: ubuntu-latest
cmake: "3.20.x"
- python-version: "3.10"
runs-on: ubuntu-latest
cmake: "3.15.x"

steps:
- uses: actions/checkout@v4
Expand Down
24 changes: 15 additions & 9 deletions src/cython_cmake/cmake/FindCython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# ``Cython::Cython``
# The Cython executable
#
# A range of versions is supported on CMake 3.19+.
#
# For more information on the Cython project, see https://cython.org/.
#
# *Cython is a language that makes writing C extensions for the Python language
Expand All @@ -39,10 +41,6 @@
# limitations under the License.
#=============================================================================

if(CMAKE_VERSION VERSION_LESS "3.20")
message(SEND_ERROR "CMake 3.20 required")
endif()

# Use the Cython executable that lives next to the Python executable
# if it is a local installation.
if(Python_EXECUTABLE)
Expand Down Expand Up @@ -88,11 +86,19 @@ if(CYTHON_EXECUTABLE)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Cython
REQUIRED_VARS CYTHON_EXECUTABLE
VERSION_VAR ${CYTHON_VERSION}
HANDLE_VERSION_RANGE
)

if(CMAKE_VERSION VERSION_LESS 3.19)
find_package_handle_standard_args(Cython
REQUIRED_VARS CYTHON_EXECUTABLE
VERSION_VAR ${CYTHON_VERSION}
)
else()
find_package_handle_standard_args(Cython
REQUIRED_VARS CYTHON_EXECUTABLE
VERSION_VAR ${CYTHON_VERSION}
HANDLE_VERSION_RANGE
)
endif()

if(CYTHON_FOUND)
if(NOT DEFINED Cython::Cython)
Expand Down
19 changes: 13 additions & 6 deletions src/cython_cmake/cmake/UseCython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
# limitations under the License.
#=============================================================================

if(CMAKE_VERSION VERSION_LESS "3.20")
message(FATAL_ERROR "CMake 3.20 required")
if(CMAKE_VERSION VERSION_LESS "3.7")
message(SEND_ERROR "CMake 3.7 required for DEPFILE")
endif()


Expand Down Expand Up @@ -124,14 +124,21 @@ function(Cython_compile_pyx)
endif()

# Place the cython files in the current binary dir if no path given
# Can use cmake_path for CMake 3.20+
if(NOT CYTHON_OUTPUT)
cmake_path(GET INPUT STEM basename)
cmake_path(APPEND CMAKE_CURRENT_BINARY_DIR "${basename}${langauge_ext}" OUTPUT_VARIABLE CYTHON_OUTPUT)
# cmake_path(GET INPUT STEM basename)
get_filename_component(basename "${INPUT}" NAME_WE)

# cmake_path(APPEND CMAKE_CURRENT_BINARY_DIR "${basename}${langauge_ext}" OUTPUT_VARIABLE CYTHON_OUTPUT)
set(CYTHON_OUPUT "${CMAKE_CURRENT_BINARY_DIR}/{basename}${langauge_ext}")
endif()
cmake_path(ABSOLUTE_PATH CYTHON_OUTPUT)

# cmake_path(ABSOLUTE_PATH CYTHON_OUTPUT)
get_filename_component(CYTHON_OUTPUT "${CYTHON_OUPUT}" ABSOLUTE)

# Normalize the input path
cmake_path(ABSOLUTE_PATH INPUT)
# cmake_path(ABSOLUTE_PATH INPUT)
get_filename_component(INPUT "${INPUT}" ABSOLUTE)
set_source_files_properties("${INPUT}" PROPERTIES GENERATED TRUE)

# Support
Expand Down
2 changes: 1 addition & 1 deletion tests/packages/simple/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.20...3.29)
cmake_minimum_required(VERSION 3.15...3.29)
project(${SKBUILD_PROJECT_NAME} LANGUAGES C)

find_package(
Expand Down

0 comments on commit 4e9afe2

Please sign in to comment.