Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Mar 2021 12:08:23 +0000 (UTC)
From:      Adriaan de Groot <adridg@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r569551 - head/Mk/Uses
Message-ID:  <202103301208.12UC8N2P038784@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: adridg
Date: Tue Mar 30 12:08:22 2021
New Revision: 569551
URL: https://svnweb.freebsd.org/changeset/ports/569551

Log:
  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

Modified:
  head/Mk/Uses/cmake.mk

Modified: head/Mk/Uses/cmake.mk
==============================================================================
--- head/Mk/Uses/cmake.mk	Tue Mar 30 11:47:01 2021	(r569550)
+++ head/Mk/Uses/cmake.mk	Tue Mar 30 12:08:22 2021	(r569551)
@@ -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}
@@ -138,6 +141,24 @@ do-configure:
 	@${ECHO_MSG} ${_CMAKE_MSG}
 	${MKDIR} ${CONFIGURE_WRKSRC}
 	@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)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202103301208.12UC8N2P038784>