@@ -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} " )
@@ -167,10 +179,11 @@ string(REPLACE ".cpp" ".py" PYBIND11_PYTEST_FILES "${PYBIND11_TEST_FILES}")
167
179
# Contains the set of test files that require pybind11_cross_module_tests to be
168
180
# built; if none of these are built (i.e. because TEST_OVERRIDE is used and
169
181
# doesn't include them) the second module doesn't get built.
170
- set ( PYBIND11_CROSS_MODULE_TESTS test_exceptions.py test_local_bindings.py test_stl.py
171
- test_stl_binders.py )
182
+ tests_extra_targets ( " test_exceptions.py; test_local_bindings.py; test_stl.py;test_stl_binders.py"
183
+ "pybind11_cross_module_tests" )
172
184
173
- set (PYBIND11_CROSS_MODULE_GIL_TESTS test_gil_scoped.py )
185
+ # And add additional targets for other tests.
186
+ tests_extra_targets ("test_gil_scoped.py" "cross_module_gil_utils" )
174
187
175
188
set (PYBIND11_EIGEN_REPO
176
189
"https://gitlab.com/libeigen/eigen.git"
@@ -350,21 +363,17 @@ endfunction()
350
363
351
364
set (test_targets pybind11_tests )
352
365
353
- # Build pybind11_cross_module_tests if any test_whatever.py are being built that require it
354
- foreach (t ${PYBIND11_CROSS_MODULE_TESTS} )
355
- list (FIND PYBIND11_PYTEST_FILES ${t} i )
356
- if (i GREATER -1 )
357
- list (APPEND test_targets pybind11_cross_module_tests )
358
- break ()
359
- endif ()
360
- endforeach ()
361
-
362
- foreach (t ${PYBIND11_CROSS_MODULE_GIL_TESTS} )
363
- list (FIND PYBIND11_PYTEST_FILES ${t} i )
364
- if (i GREATER -1 )
365
- list (APPEND test_targets cross_module_gil_utils )
366
- break ()
367
- endif ()
366
+ # Check if any tests need extra targets by iterating through the mappings registered.
367
+ foreach (i ${PYBIND11_TEST_EXTRA_TARGETS} )
368
+ foreach (needle ${PYBIND11_TEST_EXTRA_TARGETS_NEEDLES_${i}} )
369
+ if (${needle} IN_LIST PYBIND11_PYTEST_FILES )
370
+ # Add all the additional targets to the test list. List join in newer cmake.
371
+ foreach (extra_target ${PYBIND11_TEST_EXTRA_TARGETS_ADDITION_${i}} )
372
+ list (APPEND test_targets ${extra_target} )
373
+ endforeach ()
374
+ break () # Breaks out of the needle search, continues with the next mapping.
375
+ endif ()
376
+ endforeach ()
368
377
endforeach ()
369
378
370
379
# Support CUDA testing by forcing the target file to compile with NVCC
0 commit comments