Skip to content

Commit 12074df

Browse files
jcfrvyasr
andcommitted
wip(UseCython): Update Cython_compile_pyx to support multiple inputs
Co-authored-by: Vyas Ramasubramani <[email protected]>
1 parent 4fc068b commit 12074df

File tree

1 file changed

+43
-44
lines changed

1 file changed

+43
-44
lines changed

src/cython_cmake/cmake/UseCython.cmake

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
#
55
# .. cmake:command:: Cython_compile_pyx
66
#
7-
# Create a custom rule to generate the source code for a Python extension module
7+
# Create custom rules to generate the source code for a Python extension module
88
# using cython.
99
#
10-
# Cython_compile_pyx(<CythonInput>
10+
# Cython_compile_pyx(<pyx_file1> [<pyx_file2> ...]
1111
# [TARGET_LANGUAGE C | CXX]
1212
# [LANGUAGE_LEVEL 2 | 3 | 3str]
1313
# [OUTPUT_VAR <OutputVar>])
@@ -45,11 +45,11 @@
4545
# find_package(Cython)
4646
#
4747
# Cython_compile_pyx(_hello.pyx
48-
# OUTPUT_VAR _hello_source_file
48+
# OUTPUT_VAR _hello_source_files
4949
# )
5050
#
5151
# Python_add_library(_hello
52-
# MODULE ${_hello_source_file}
52+
# MODULE ${_hello_source_files}
5353
# WITH_SOABI
5454
# )
5555
#
@@ -241,11 +241,6 @@ function(Cython_compile_pyx)
241241

242242
# Get source file location
243243
set(_source_files ${_args_UNPARSED_ARGUMENTS})
244-
list(GET _source_files 0 _source_file)
245-
list(LENGTH _source_files _source_file_count)
246-
if (_source_file_count GREATER 1)
247-
message(AUTHOR_WARNING "Cython_compile_pyx supports compiling only one file: ${_source_files}")
248-
endif()
249244

250245
# Set target language
251246
get_property(_languages GLOBAL PROPERTY ENABLED_LANGUAGES)
@@ -286,45 +281,49 @@ function(Cython_compile_pyx)
286281

287282
set(_language_level_arg "${_language_level_${_language_level}_arg}")
288283

289-
cmake_path(GET _source_file STEM _name)
290-
set(generated_file "${CMAKE_CURRENT_BINARY_DIR}/${_name}.${_target_language_extension}")
291-
set_source_files_properties(${generated_file} PROPERTIES GENERATED TRUE)
292-
293-
set(_output_var ${_name})
294-
if(_args_OUTPUT_VAR)
295-
set(_output_var ${_args_OUTPUT_VAR})
296-
endif()
297-
set(${_output_var} ${generated_file} PARENT_SCOPE)
298-
299-
file(RELATIVE_PATH generated_file_relative
300-
${CMAKE_BINARY_DIR} ${generated_file})
301-
302-
set(comment "Generating ${_target_language} source ${generated_file_relative}")
303-
304-
get_source_file_property(pyx_location ${_source_file} LOCATION)
305-
306284
# Generated depfile is expected to have the ".dep" extension and be located along
307285
# side the generated source file.
308286
set(_depfile ${generated_file}.dep)
309287
set(_depfile_arg "-M")
310288

311-
# Add the command to run the compiler.
312-
add_custom_command(
313-
OUTPUT ${generated_file}
314-
COMMAND ${CYTHON_EXECUTABLE}
315-
ARGS
316-
${_target_language_arg}
317-
${_language_level_arg}
318-
${_args_CYTHON_ARGS}
319-
${_depfile_arg}
320-
${pyx_location}
321-
--output-file ${generated_file}
322-
DEPENDS
323-
${_source_file}
324-
DEPFILE
325-
${_cython_depfile}
326-
VERBATIM
327-
COMMENT ${comment}
328-
)
289+
set(generated_files)
290+
291+
foreach(_source_file IN LISTS _source_files)
292+
cmake_path(GET _source_file STEM _name)
293+
set(generated_file "${CMAKE_CURRENT_BINARY_DIR}/${_name}.${_target_language_extension}")
294+
set_source_files_properties(${generated_file} PROPERTIES GENERATED TRUE)
295+
296+
file(RELATIVE_PATH generated_file_relative
297+
${CMAKE_BINARY_DIR} ${generated_file})
298+
299+
set(comment "Generating ${_target_language} source ${generated_file_relative}")
300+
301+
get_source_file_property(pyx_location ${_source_file} LOCATION)
302+
303+
# Add the command to run the compiler.
304+
add_custom_command(
305+
OUTPUT ${generated_file}
306+
COMMAND ${CYTHON_EXECUTABLE}
307+
ARGS
308+
${_target_language_arg}
309+
${_language_level_arg}
310+
${_args_CYTHON_ARGS}
311+
${_depfile_arg}
312+
${pyx_location}
313+
--output-file ${generated_file}
314+
DEPENDS
315+
${_source_file}
316+
DEPFILE
317+
${_cython_depfile}
318+
VERBATIM
319+
COMMENT ${comment}
320+
)
321+
list(APPEND generated_files ${generated_file})
322+
endforeach()
323+
324+
if(_args_OUTPUT_VAR)
325+
set(_output_var ${_args_OUTPUT_VAR})
326+
set(${_output_var} ${generated_files} PARENT_SCOPE)
327+
endif()
329328

330329
endfunction()

0 commit comments

Comments
 (0)