Skip to content

Commit b5e0e64

Browse files
henryiiijcfr
andcommitted
feat: Simplify expecting only one input file
Co-authored-by: Jean-Christophe Fillion-Robin <[email protected]>
1 parent 8b256d5 commit b5e0e64

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

src/cython_cmake/cmake/UseCython.cmake

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Create custom rules to generate the source code for a Python extension module
88
# using cython.
99
#
10-
# Cython_compile_pyx(<pyx_file1> [<pyx_file2> ...]
10+
# Cython_compile_pyx(<pyx_file>
1111
# [LANGUAGE C | CXX]
1212
# [CYTHON_ARGS <args> ...]
1313
# [OUTPUT_VARIABLE <OutputVariable>])
@@ -77,8 +77,13 @@ function(Cython_compile_pyx)
7777
${ARGN}
7878
)
7979

80-
# Get source file location
81-
set(_source_files ${_args_UNPARSED_ARGUMENTS})
80+
# Get input
81+
set(all_intput ${_args_UNPARSED_ARGUMENTS})
82+
list(LENGTH all_intput input_length)
83+
if(NOT input_length EQUAL 1)
84+
message(FATAL_ERROR "One and only one input file must be specified, got '${all_intput}'")
85+
endif()
86+
list(GET all_intput 0 _source_file)
8287

8388
# Set target language
8489
get_property(_languages GLOBAL PROPERTY ENABLED_LANGUAGES)
@@ -108,43 +113,38 @@ function(Cython_compile_pyx)
108113
set(_depfile ${generated_file}.dep)
109114
set(_depfile_arg "-M")
110115

111-
set(generated_files)
112-
113-
foreach(_source_file IN LISTS _source_files)
114-
cmake_path(GET _source_file STEM _name)
115-
set(generated_file "${CMAKE_CURRENT_BINARY_DIR}/${_name}.${_language_extension}")
116-
set_source_files_properties(${generated_file} PROPERTIES GENERATED TRUE)
117-
118-
file(RELATIVE_PATH generated_file_relative
119-
${CMAKE_BINARY_DIR} ${generated_file})
120-
121-
set(comment "Generating ${_language} source ${generated_file_relative}")
122-
123-
get_source_file_property(pyx_location ${_source_file} LOCATION)
124-
125-
# Add the command to run the compiler.
126-
add_custom_command(
127-
OUTPUT ${generated_file}
128-
COMMAND ${CYTHON_EXECUTABLE}
129-
ARGS
130-
${_language_arg}
131-
${_args_CYTHON_ARGS}
132-
${_depfile_arg}
133-
${pyx_location}
134-
--output-file ${generated_file}
135-
DEPENDS
136-
${_source_file}
137-
DEPFILE
138-
${_cython_depfile}
139-
VERBATIM
140-
COMMENT ${comment}
141-
)
142-
list(APPEND generated_files ${generated_file})
143-
endforeach()
116+
cmake_path(GET _source_file STEM _name)
117+
set(generated_file "${CMAKE_CURRENT_BINARY_DIR}/${_name}.${_language_extension}")
118+
set_source_files_properties(${generated_file} PROPERTIES GENERATED TRUE)
119+
120+
file(RELATIVE_PATH generated_file_relative
121+
${CMAKE_BINARY_DIR} ${generated_file})
122+
123+
set(comment "Generating ${_language} source ${generated_file_relative}")
124+
125+
get_source_file_property(pyx_location ${_source_file} LOCATION)
126+
127+
# Add the command to run the compiler.
128+
add_custom_command(
129+
OUTPUT ${generated_file}
130+
COMMAND ${CYTHON_EXECUTABLE}
131+
ARGS
132+
${_language_arg}
133+
${_args_CYTHON_ARGS}
134+
${_depfile_arg}
135+
${pyx_location}
136+
--output-file ${generated_file}
137+
DEPENDS
138+
${_source_file}
139+
DEPFILE
140+
${_cython_depfile}
141+
VERBATIM
142+
COMMENT ${comment}
143+
)
144144

145145
if(_args_OUTPUT_VARIABLE)
146146
set(_output_variable ${_args_OUTPUT_VARIABLE})
147-
set(${_output_variable} ${generated_files} PARENT_SCOPE)
147+
set(${_output_variable} ${generated_file} PARENT_SCOPE)
148148
endif()
149149

150150
endfunction()

0 commit comments

Comments
 (0)