@@ -47,6 +47,18 @@ macro(possibly_uninitialized)
47
47
endforeach ()
48
48
endmacro ()
49
49
50
+ # Function to add additional targets if any of the provided tests are found.
51
+ # Needles; Specifies the test names to look for.
52
+ # Additions; Specifies the additional test targets to add when any of the needles are found.
53
+ macro (tests_extra_targets needles additions)
54
+ # Add the index for this relation to the index extra targets map.
55
+ list (LENGTH PYBIND11_TEST_EXTRA_TARGETS PYBIND11_TEST_EXTRA_TARGETS_LEN)
56
+ list (APPEND PYBIND11_TEST_EXTRA_TARGETS ${PYBIND11_TEST_EXTRA_TARGETS_LEN} )
57
+ # Add the test names to look for, and the associated test target additions.
58
+ set (PYBIND11_TEST_EXTRA_TARGETS_NEEDLES_${PYBIND11_TEST_EXTRA_TARGETS_LEN} ${needles} )
59
+ set (PYBIND11_TEST_EXTRA_TARGETS_ADDITION_${PYBIND11_TEST_EXTRA_TARGETS_LEN} ${additions} )
60
+ endmacro ()
61
+
50
62
# New Python support
51
63
if (DEFINED Python_EXECUTABLE)
52
64
set (PYTHON_EXECUTABLE "${Python_EXECUTABLE} " )
@@ -183,12 +195,13 @@ list(SORT PYBIND11_PYTEST_FILES)
183
195
# Contains the set of test files that require pybind11_cross_module_tests to be
184
196
# built; if none of these are built (i.e. because TEST_OVERRIDE is used and
185
197
# doesn't include them) the second module doesn't get built.
186
- set (PYBIND11_CROSS_MODULE_TESTS test_exceptions.py test_local_bindings.py test_stl.py
187
- test_stl_binders.py )
198
+ tests_extra_targets( " test_exceptions.py; test_local_bindings.py; test_stl.py;test_stl_binders.py"
199
+ "pybind11_cross_module_tests" )
188
200
189
- set (PYBIND11_CROSS_MODULE_GIL_TESTS test_gil_scoped.py)
190
-
191
- set (PYBIND11_CLASS_SH_MODULE_LOCAL_TESTS test_class_sh_module_local.py)
201
+ # And add additional targets for other tests.
202
+ tests_extra_targets("test_gil_scoped.py" "cross_module_gil_utils" )
203
+ tests_extra_targets("test_class_sh_module_local.py"
204
+ "class_sh_module_local_0;class_sh_module_local_1;class_sh_module_local_2" )
192
205
193
206
set (PYBIND11_EIGEN_REPO
194
207
"https://gitlab.com/libeigen/eigen.git"
@@ -368,31 +381,17 @@ endfunction()
368
381
369
382
set (test_targets pybind11_tests)
370
383
371
- # Build pybind11_cross_module_tests if any test_whatever.py are being built that require it
372
- foreach (t ${PYBIND11_CROSS_MODULE_TESTS} )
373
- list (FIND PYBIND11_PYTEST_FILES ${t} i)
374
- if (i GREATER -1)
375
- list (APPEND test_targets pybind11_cross_module_tests)
376
- break ()
377
- endif ()
378
- endforeach ()
379
-
380
- foreach (t ${PYBIND11_CROSS_MODULE_GIL_TESTS} )
381
- list (FIND PYBIND11_PYTEST_FILES ${t} i)
382
- if (i GREATER -1)
383
- list (APPEND test_targets cross_module_gil_utils)
384
- break ()
385
- endif ()
386
- endforeach ()
387
-
388
- foreach (t ${PYBIND11_CLASS_SH_MODULE_LOCAL_TESTS} )
389
- list (FIND PYBIND11_PYTEST_FILES ${t} i)
390
- if (i GREATER -1)
391
- list (APPEND test_targets class_sh_module_local_0)
392
- list (APPEND test_targets class_sh_module_local_1)
393
- list (APPEND test_targets class_sh_module_local_2)
394
- break ()
395
- endif ()
384
+ # Check if any tests need extra targets by iterating through the mappings registered.
385
+ foreach (i ${PYBIND11_TEST_EXTRA_TARGETS} )
386
+ foreach (needle ${PYBIND11_TEST_EXTRA_TARGETS_NEEDLES_${i} })
387
+ if (${needle} IN_LIST PYBIND11_PYTEST_FILES)
388
+ # Add all the additional targets to the test list. List join in newer cmake.
389
+ foreach (extra_target ${PYBIND11_TEST_EXTRA_TARGETS_ADDITION_${i} })
390
+ list (APPEND test_targets ${extra_target} )
391
+ endforeach ()
392
+ break () # Breaks out of the needle search, continues with the next mapping.
393
+ endif ()
394
+ endforeach ()
396
395
endforeach ()
397
396
398
397
# Support CUDA testing by forcing the target file to compile with NVCC
0 commit comments