Skip to content

Commit 888f5e5

Browse files
committed
refactor: Add helper functions and differentiate processing of one vs multiple input
1 parent bb683a3 commit 888f5e5

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

src/cython_cmake/cmake/UseCython.cmake

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,9 @@ function(Cython_compile_pyx)
127127
set(_language_arg ${_language_${_language}_arg})
128128
set(_language_extension ${_language_${_language}_extension})
129129

130-
set(generated_files)
131-
132-
foreach(_source_file IN LISTS _source_files)
130+
function(_compile_pyx _source_file generated_file)
133131

134-
# Can use cmake_path for CMake 3.20+
135-
# cmake_path(GET _source_file STEM _name)
136-
get_filename_component(_name "${_source_file}" NAME_WE)
137132

138-
set(generated_file "${CMAKE_CURRENT_BINARY_DIR}/${_name}.${_language_extension}")
139133
set_source_files_properties(${generated_file} PROPERTIES GENERATED TRUE)
140134

141135
# Generated depfile is expected to have the ".dep" extension and be located along
@@ -167,9 +161,34 @@ function(Cython_compile_pyx)
167161
VERBATIM
168162
COMMENT ${comment}
169163
)
164+
endfunction()
165+
166+
function(_set_output _input_file _output_var)
167+
# Can use cmake_path for CMake 3.20+
168+
# cmake_path(GET _input_file STEM basename)
169+
get_filename_component(_basename "${_input_file}" NAME_WE)
170+
171+
set(${_output_var} "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.${_language_extension}" PARENT_SCOPE)
172+
endfunction()
173+
174+
set(generated_files)
175+
176+
if(input_length EQUAL 1)
177+
list(GET_source_files 0 _source_file)
178+
_set_output(${_source_file} generated_file)
179+
_compile_pyx(${_source_file} ${generated_file})
170180
list(APPEND generated_files ${generated_file})
171-
endforeach()
172181

182+
else()
183+
foreach(_source_file IN LISTS _source_files)
184+
_set_output(${_source_file} generated_file)
185+
_compile_pyx(${_source_file} ${generated_file})
186+
list(APPEND generated_files ${generated_file})
187+
endforeach()
188+
189+
endif()
190+
191+
# Output variable only if set
173192
if(_args_OUTPUT_VARIABLE)
174193
set(_output_variable ${_args_OUTPUT_VARIABLE})
175194
set(${_output_variable} ${generated_files} PARENT_SCOPE)

0 commit comments

Comments
 (0)