@@ -310,10 +310,8 @@ target_link_libraries(
310
310
"test-drive::test-drive"
311
311
)
312
312
313
- add_test("all-tests" "${PROJECT_NAME}-tester")
314
-
315
313
foreach(t IN LISTS tests)
316
- add_test("${t}" "${PROJECT_NAME}-tester" "${t}")
314
+ add_test("${PROJECT_NAME}/${ t}" "${PROJECT_NAME}-tester" "${t}")
317
315
endforeach()
318
316
```
319
317
@@ -323,6 +321,57 @@ endforeach()
323
321
The following module allows to find or fetch an installation of this project in CMake
324
322
325
323
``` cmake
324
+ #[[.rst:
325
+ Find test-drive
326
+ ---------------
327
+
328
+ Makes the test-drive project available.
329
+
330
+ Imported Targets
331
+ ^^^^^^^^^^^^^^^^
332
+
333
+ This module provides the following imported target, if found:
334
+
335
+ ``test-drive::test-drive``
336
+ The test-drive library
337
+
338
+
339
+ Result Variables
340
+ ^^^^^^^^^^^^^^^^
341
+
342
+ This module will define the following variables:
343
+
344
+ ``TEST_DRIVE_FOUND``
345
+ True if the test-drive library is available
346
+
347
+ ``TEST_DRIVE_SOURCE_DIR``
348
+ Path to the source directory of the test-drive project,
349
+ only set if the project is included as source.
350
+
351
+ ``TEST_DRIVE_BINARY_DIR``
352
+ Path to the binary directory of the test-drive project,
353
+ only set if the project is included as source.
354
+
355
+ Cache variables
356
+ ^^^^^^^^^^^^^^^
357
+
358
+ The following cache variables may be set to influence the library detection:
359
+
360
+ ``TEST_DRIVE_FIND_METHOD``
361
+ Methods to find or make the project available. Available methods are
362
+ - ``cmake``: Try to find via CMake config file
363
+ - ``pkgconf``: Try to find via pkg-config file
364
+ - ``subproject``: Use source in subprojects directory
365
+ - ``fetch``: Fetch the source from upstream
366
+
367
+ ``TEST_DRIVE_DIR``
368
+ Used for searching the CMake config file
369
+
370
+ ``TEST_DRIVE_SUBPROJECT``
371
+ Directory to find the test-drive subproject, relative to the project root
372
+
373
+ #]]
374
+
326
375
set(_lib "test-drive")
327
376
set(_pkg "TEST_DRIVE")
328
377
set(_url "https://github.com/fortran-lang/test-drive")
@@ -343,6 +392,10 @@ foreach(method ${${_pkg}_FIND_METHOD})
343
392
344
393
if("${method}" STREQUAL "cmake")
345
394
message(STATUS "${_lib}: Find installed package")
395
+ if(DEFINED "${_pkg}_DIR")
396
+ set("_${_pkg}_DIR")
397
+ set("${_lib}_DIR" "${_pkg}_DIR")
398
+ endif()
346
399
find_package("${_lib}" CONFIG)
347
400
if("${_lib}_FOUND")
348
401
message(STATUS "${_lib}: Found installed package")
@@ -367,19 +420,24 @@ foreach(method ${${_pkg}_FIND_METHOD})
367
420
INTERFACE
368
421
"${${_pkg}_INCLUDE_DIRS}"
369
422
)
423
+
370
424
break()
371
425
endif()
372
426
endif()
373
427
374
428
if("${method}" STREQUAL "subproject")
375
- set("${_pkg}_SOURCE_DIR" "${PROJECT_SOURCE_DIR}/subprojects/${_lib}")
376
- set("${_pkg}_BINARY_DIR" "${PROJECT_BINARY_DIR}/subprojects/${_lib}")
429
+ if(NOT DEFINED "${_pkg}_SUBPROJECT")
430
+ set("_${_pkg}_SUBPROJECT")
431
+ set("${_pkg}_SUBPROJECT" "subprojects/${_lib}")
432
+ endif()
433
+ set("${_pkg}_SOURCE_DIR" "${PROJECT_SOURCE_DIR}/${${_pkg}_SUBPROJECT}")
434
+ set("${_pkg}_BINARY_DIR" "${PROJECT_BINARY_DIR}/${${_pkg}_SUBPROJECT}")
377
435
if(EXISTS "${${_pkg}_SOURCE_DIR}/CMakeLists.txt")
378
- message(STATUS "Include ${_lib} from subprojects ")
436
+ message(STATUS "Include ${_lib} from ${${_pkg}_SUBPROJECT} ")
379
437
add_subdirectory(
380
438
"${${_pkg}_SOURCE_DIR}"
381
439
"${${_pkg}_BINARY_DIR}"
382
- )
440
+ )
383
441
384
442
add_library("${_lib}::${_lib}" INTERFACE IMPORTED)
385
443
target_link_libraries("${_lib}::${_lib}" INTERFACE "${_lib}")
@@ -407,6 +465,7 @@ foreach(method ${${_pkg}_FIND_METHOD})
407
465
target_link_libraries("${_lib}::${_lib}" INTERFACE "${_lib}")
408
466
409
467
# We need the module directory in the subproject before we finish the configure stage
468
+ FetchContent_GetProperties("${_lib}" SOURCE_DIR "${_pkg}_SOURCE_DIR")
410
469
FetchContent_GetProperties("${_lib}" BINARY_DIR "${_pkg}_BINARY_DIR")
411
470
if(NOT EXISTS "${${_pkg}_BINARY_DIR}/include")
412
471
make_directory("${${_pkg}_BINARY_DIR}/include")
@@ -417,10 +476,20 @@ foreach(method ${${_pkg}_FIND_METHOD})
417
476
418
477
endforeach()
419
478
420
- if(NOT TARGET "${_lib}::${_lib}")
421
- message(FATAL_ERROR "Could not find dependency ${_lib}")
479
+ if(TARGET "${_lib}::${_lib}")
480
+ set("${_pkg}_FOUND" TRUE)
481
+ else()
482
+ set("${_pkg}_FOUND" FALSE)
422
483
endif()
423
484
485
+ if(DEFINED "_${_pkg}_SUBPROJECT")
486
+ unset("${_pkg}_SUBPROJECT")
487
+ unset("_${_pkg}_SUBPROJECT")
488
+ endif()
489
+ if(DEFINED "_${_pkg}_DIR")
490
+ unset("${_lib}_DIR")
491
+ unset("_${_pkg}_DIR")
492
+ endif()
424
493
if(DEFINED "_${_pkg}_FIND_METHOD")
425
494
unset("${_pkg}_FIND_METHOD")
426
495
unset("_${_pkg}_FIND_METHOD")
0 commit comments