Skip to content

Commit dc6f901

Browse files
committed
feat: Add support for using genex in CYTHON_ARGS
1 parent 492f4dd commit dc6f901

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

src/cython_cmake/cmake/UseCython.cmake

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@
7070
# limitations under the License.
7171
#=============================================================================
7272

73-
if(CMAKE_VERSION VERSION_LESS "3.7")
74-
message(FATAL_ERROR "CMake 3.7 required for DEPFILE")
73+
if(CMAKE_VERSION VERSION_LESS "3.8")
74+
# CMake 3.7 required for DEPFILE
75+
# CMake 3.8 required for COMMAND_EXPAND_LISTS
76+
message(FATAL_ERROR "CMake 3.8 required for COMMAND_EXPAND_LISTS")
7577
endif()
7678

7779
function(Cython_compile_pyx)
@@ -148,10 +150,11 @@ function(Cython_compile_pyx)
148150
COMMAND
149151
${_cython_command}
150152
${_language_arg}
151-
${_args_CYTHON_ARGS}
153+
"${_args_CYTHON_ARGS}"
152154
${_depfile_arg}
153155
${pyx_location}
154156
--output-file ${generated_file}
157+
COMMAND_EXPAND_LISTS
155158
MAIN_DEPENDENCY
156159
${_source_file}
157160
DEPFILE

tests/packages/simple/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ include(UseCython)
1010

1111
cython_compile_pyx(simple.pyx
1212
LANGUAGE C
13-
# OUTPUT_ARG
13+
# PLACEHOLDER
1414
OUTPUT_VARIABLE simple_c
1515
)
1616

tests/test_package.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_output_argument(monkeypatch, tmp_path, output_arg):
5050

5151
cmakelists = Path("CMakeLists.txt")
5252
txt = cmakelists.read_text().replace(
53-
"# OUTPUT_ARG", f'OUTPUT "{output_values[output_arg]}"'
53+
"# PLACEHOLDER", f'OUTPUT "{output_values[output_arg]}"'
5454
)
5555
cmakelists.write_text(txt)
5656

@@ -133,6 +133,7 @@ def test_multiple_packages(monkeypatch, tmp_path):
133133
package_dir = tmp_path / "pkg5"
134134
shutil.copytree(DIR / "packages/multiple_packages", package_dir)
135135
monkeypatch.chdir(package_dir)
136+
136137
build_dir = tmp_path / "build"
137138

138139
wheel = build_wheel(
@@ -158,3 +159,39 @@ def test_multiple_packages(monkeypatch, tmp_path):
158159
package3_build_files = {x.name for x in (build_dir / "__").iterdir()}
159160
assert "module.c.dep" in package3_build_files
160161
assert "module.c" in package3_build_files
162+
163+
164+
def test_genex_cython_args(monkeypatch, tmp_path, capfd):
165+
package_dir = tmp_path / "pkg6"
166+
shutil.copytree(DIR / "packages/simple", package_dir)
167+
monkeypatch.chdir(package_dir)
168+
169+
build_dir = tmp_path / "build"
170+
171+
cmakelists = Path("CMakeLists.txt")
172+
txt = (
173+
cmakelists.read_text()
174+
.replace("LANGUAGE C", "")
175+
.replace("LANGUAGES C", "LANGUAGES CXX")
176+
.replace("# PLACEHOLDER", 'CYTHON_ARGS "$<1:--verbose;--annotate>"')
177+
)
178+
cmakelists.write_text(txt)
179+
180+
wheel = build_wheel(
181+
str(tmp_path), {"build-dir": str(build_dir), "wheel.license-files": []}
182+
)
183+
184+
with zipfile.ZipFile(tmp_path / wheel) as f:
185+
file_names = set(f.namelist())
186+
assert len(file_names) == 4
187+
188+
build_files = {x.name for x in build_dir.iterdir()}
189+
assert "simple.cxx.dep" in build_files
190+
assert "simple.cxx" in build_files
191+
192+
# Check side-effect of "--annotate"
193+
assert "simple.html" in build_files
194+
195+
# Check side-effect of "--verbose"
196+
captured = capfd.readouterr()
197+
assert "Compiling " in captured.out or "Compiling " in captured.err

0 commit comments

Comments
 (0)