|
7 | 7 | # Create custom rules to generate the source code for a Python extension module |
8 | 8 | # using cython. |
9 | 9 | # |
10 | | -# Cython_compile_pyx(<pyx_file1> [<pyx_file2> ...] |
| 10 | +# Cython_compile_pyx(<pyx_file> |
11 | 11 | # [LANGUAGE C | CXX] |
12 | 12 | # [CYTHON_ARGS <args> ...] |
13 | 13 | # [OUTPUT_VARIABLE <OutputVariable>]) |
@@ -77,8 +77,13 @@ function(Cython_compile_pyx) |
77 | 77 | ${ARGN} |
78 | 78 | ) |
79 | 79 |
|
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) |
82 | 87 |
|
83 | 88 | # Set target language |
84 | 89 | get_property(_languages GLOBAL PROPERTY ENABLED_LANGUAGES) |
@@ -108,43 +113,38 @@ function(Cython_compile_pyx) |
108 | 113 | set(_depfile ${generated_file}.dep) |
109 | 114 | set(_depfile_arg "-M") |
110 | 115 |
|
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 | + ) |
144 | 144 |
|
145 | 145 | if(_args_OUTPUT_VARIABLE) |
146 | 146 | set(_output_variable ${_args_OUTPUT_VARIABLE}) |
147 | | - set(${_output_variable} ${generated_files} PARENT_SCOPE) |
| 147 | + set(${_output_variable} ${generated_file} PARENT_SCOPE) |
148 | 148 | endif() |
149 | 149 |
|
150 | 150 | endfunction() |
0 commit comments