aboutsummaryrefslogtreecommitdiff
path: root/Mk
diff options
context:
space:
mode:
authorAdriaan de Groot <adridg@FreeBSD.org>2021-03-30 12:08:22 +0000
committerAdriaan de Groot <adridg@FreeBSD.org>2021-03-30 12:08:22 +0000
commitd8d855472547f67f478b6ad52e5dcf4343b634a3 (patch)
tree65a7140a83c5834dfeac4762dc0fae3444be7015 /Mk
parenta097a9d779a9fcbadd578c239c0aded5f71d367a (diff)
downloadports-d8d855472547f67f478b6ad52e5dcf4343b634a3.tar.gz
ports-d8d855472547f67f478b6ad52e5dcf4343b634a3.zip
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
Notes
Notes: svn path=/head/; revision=569551
Diffstat (limited to 'Mk')
-rw-r--r--Mk/Uses/cmake.mk25
1 files changed, 23 insertions, 2 deletions
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)