From d8d855472547f67f478b6ad52e5dcf4343b634a3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 30 Mar 2021 12:08:22 +0000 Subject: Add support for USES=cmake:testing CMake-based ports have a "standard" way of controlling whether testing should be built, by passing -DBUILD_TESTING=ON at the configure stage (with some footnotes). Add a :testing modifier for USES=cmake that enables a boilerplate do-test target that rebuilds with testing enabled, and then runs the tests. Individual ports need to buy in to this explicitly (because tests might not be non-destructive). Submitted and explained well by yuri@ PR: 249024 Submitted by: yuri --- Mk/Uses/cmake.mk | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'Mk') diff --git a/Mk/Uses/cmake.mk b/Mk/Uses/cmake.mk index 82134451317d..e5814d34a0a7 100644 --- a/Mk/Uses/cmake.mk +++ b/Mk/Uses/cmake.mk @@ -4,7 +4,7 @@ # # Feature: cmake # Usage: USES=cmake or USES=cmake:ARGS -# Valid ARGS: insource, run, noninja +# Valid ARGS: insource, run, noninja, testing # ARGS description: # insource do not perform an out-of-source build # noninja don't use ninja instead of make @@ -16,6 +16,9 @@ # 2) ports that set BUILD_- or INSTALL_WRKSRC to # something different than CONFIGURE_WRKSRC # run add a runtime dependency on cmake +# testing add the test target based on ctest +# Additionally, CMAKE_TESTING_ON, CMAKE_TESTING_OFF, CMAKE_TESTING_ARGS, CMAKE_TESTING_TARGET +# can be defined to override the default values. # # # Additional variables that affect cmake behaviour: @@ -46,7 +49,7 @@ .if !defined(_INCLUDE_USES_CMAKE_MK) _INCLUDE_USES_CMAKE_MK= yes -_valid_ARGS= insource run noninja +_valid_ARGS= insource run noninja testing # Sanity check .for arg in ${cmake_ARGS} @@ -140,4 +143,22 @@ do-configure: @cd ${CONFIGURE_WRKSRC}; ${SETENV} ${CONFIGURE_ENV} ${CMAKE_BIN} ${CMAKE_ARGS} ${CMAKE_SOURCE_PATH} .endif +.if !target(do-test) && ${cmake_ARGS:Mtesting} +CMAKE_TESTING_ON?= BUILD_TESTING +CMAKE_TESTING_TARGET?= test + +# Handle the option-like CMAKE_TESTING_ON and CMAKE_TESTING_OFF lists. +.for _bool_kind in ON OFF +. if defined(CMAKE_TESTING_${_bool_kind}) +CMAKE_TESTING_ARGS+= ${CMAKE_TESTING_${_bool_kind}:C/.*/-D&:BOOL=${_bool_kind}/} +. endif +.endfor + +do-test: + @cd ${BUILD_WRKSRC} && \ + ${SETENV} ${CONFIGURE_ENV} ${CMAKE_BIN} ${CMAKE_ARGS} ${CMAKE_TESTING_ARGS} ${CMAKE_SOURCE_PATH} && \ + ${SETENV} ${MAKE_ENV} ${MAKE_CMD} ${MAKE_ARGS} ${ALL_TARGET} && \ + ${SETENV} ${MAKE_ENV} ${MAKE_CMD} ${MAKE_ARGS} ${CMAKE_TESTING_TARGET} +.endif + .endif #!defined(_INCLUDE_USES_CMAKE_MK) -- cgit v1.2.3