Skip to content

Commit ca5d208

Browse files
committed
refactor: address feedback
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 1941770 commit ca5d208

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ given with `CYTHON_ARGS`, and if this is not set, it will take a default from a
4444

4545
If the `LANGUAGE` is not given, and both `C` and `CXX` are enabled globally,
4646
then the language will try to be deduced from a `# distutils: language=...`
47-
comment in the source file. It is an error if it cannot be deduced.
47+
comment in the source file, and C will be used if not found.
4848

4949
This utility relies on the `DEPFILE` feature introduced for Ninja in CMake 3.7,
5050
and added for Make in CMake 3.20, and Visual Studio & Xcode in CMake 3.21.

src/cython_cmake/cmake/UseCython.cmake

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919
# ``LANGUAGE [C | CXX]``
2020
# Force the generation of either a C or C++ file. Recommended; will attempt
21-
# to be deduced if not specified.
21+
# to be deduced if not specified, defaults to C unless only CXX is enabled.
2222
#
2323
# ``CYTHON_ARGS <args>``
2424
# Specify additional arguments for the cythonization process. Will default to
@@ -94,26 +94,29 @@ function(Cython_compile_pyx)
9494

9595
# Set target language
9696
if(NOT CYTHON_LANGUAGE)
97-
get_property(_languages GLOBAL PROPERTY ENABLED_LANGUAGES)
97+
get_property(_langauges GLOBAL PROPERTY ENABLED_LANGUAGES)
9898

99-
if("C" IN_LIST _langauges AND "CXX" IN_LIST _languages)
99+
if("C" IN_LIST _langauges AND "CXX" IN_LIST _langauges)
100100
# Try to compute language. Returns falsy if not found.
101101
_cython_compute_language(CYTHON_LANGUAGE ${INPUT})
102102
message(STATUS "${CYTHON_LANGUAGE}")
103-
elseif("C" IN_LIST _languages)
103+
elseif("C" IN_LIST _langauges)
104104
# If only C is enabled globally, assume C
105105
set(CYTHON_LANGUAGE C)
106-
elseif("CXX" IN_LIST _languages)
106+
elseif("CXX" IN_LIST _langauges)
107107
# Likewise for CXX
108-
set(CYTHON_LANGUAGE "CXX")
108+
set(CYTHON_LANGUAGE CXX)
109109
else()
110110
message(FATAL_ERROR "LANGUAGE keyword required if neither C nor CXX enabled globally")
111111
endif()
112112
endif()
113113

114+
# Default to C if not found
114115
if(NOT CYTHON_LANGUAGE)
115-
message(FATAL_ERROR "LANGUAGE keyword or `# distutils: language=...` required if C and CXX are enabled globally")
116-
elseif(CYTHON_LANGUAGE STREQUAL C)
116+
set(CYTHON_LANGUAGE C)
117+
endif()
118+
119+
if(CYTHON_LANGUAGE STREQUAL C)
117120
set(language_arg "")
118121
set(langauge_ext ".c")
119122
elseif(CYTHON_LANGUAGE STREQUAL CXX)
@@ -126,18 +129,14 @@ function(Cython_compile_pyx)
126129
# Place the cython files in the current binary dir if no path given
127130
# Can use cmake_path for CMake 3.20+
128131
if(NOT CYTHON_OUTPUT)
129-
# cmake_path(GET INPUT STEM basename)
130132
get_filename_component(basename "${INPUT}" NAME_WE)
131133

132-
# cmake_path(APPEND CMAKE_CURRENT_BINARY_DIR "${basename}${langauge_ext}" OUTPUT_VARIABLE CYTHON_OUTPUT)
133134
set(CYTHON_OUPUT "${CMAKE_CURRENT_BINARY_DIR}/${basename}${langauge_ext}")
134135
endif()
135136

136-
# cmake_path(ABSOLUTE_PATH CYTHON_OUTPUT)
137137
get_filename_component(CYTHON_OUTPUT "${CYTHON_OUPUT}" ABSOLUTE)
138138

139139
# Normalize the input path
140-
# cmake_path(ABSOLUTE_PATH INPUT)
141140
get_filename_component(INPUT "${INPUT}" ABSOLUTE)
142141
set_source_files_properties("${INPUT}" PROPERTIES GENERATED TRUE)
143142

0 commit comments

Comments
 (0)