git: fc999570716f - main - Mk/Uses/cmake.mk: Add CMAKE_TESTING_SETENV

From: Jason E. Hale <jhale_at_FreeBSD.org>
Date: Tue, 26 Nov 2024 16:45:54 UTC
The branch main has been updated by jhale:

URL: https://cgit.FreeBSD.org/ports/commit/?id=fc999570716fed53681c943136e8f3f674631326

commit fc999570716fed53681c943136e8f3f674631326
Author:     Jason E. Hale <jhale@FreeBSD.org>
AuthorDate: 2024-11-26 09:10:17 +0000
Commit:     Jason E. Hale <jhale@FreeBSD.org>
CommitDate: 2024-11-26 16:45:47 +0000

    Mk/Uses/cmake.mk: Add CMAKE_TESTING_SETENV
    
    Defining this variable in an individual port Makefile sets the
    environment for building and, more importantly, running the target
    defined by CMAKE_TESTING_TARGET with SETENV instead of SETENVI.
    
    Certain tests may require a running X or Wayland session to function
    and SETENVI discards important environment variables like DISPLAY and
    XAUTHORITY that cause these tests to fail or segfault.
---
 Mk/Uses/cmake.mk | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/Mk/Uses/cmake.mk b/Mk/Uses/cmake.mk
index d1d1eb1057d3..1a4bf338b456 100644
--- a/Mk/Uses/cmake.mk
+++ b/Mk/Uses/cmake.mk
@@ -53,6 +53,10 @@
 #			Default: BUILD_TESTING
 # CMAKE_TESTING_OFF	Appends -D<var>:bool=OFF to the CMAKE_TESTING_ARGS.
 #			Default: empty
+# CMAKE_TESTING_SETENV	- Use SETENV instead of SETENVI to run the tests.
+#			Useful for tests that require a running X or Wayland
+#			session to keep enviroment variables like DISPLAY.
+#			Default: undefined, set to any value to enable.
 # CMAKE_TESTING_TARGET	- Name of the test target. Default: test
 #
 # MAINTAINER: kde@FreeBSD.org
@@ -185,6 +189,13 @@ CMAKE_TESTING_ON?=		BUILD_TESTING
 CMAKE_TESTING_PARALLEL_LEVEL?=	${MAKE_JOBS_NUMBER}
 CMAKE_TESTING_TARGET?=		test
 
+# Use SETENV instead of SETENVI if CMAKE_TESTING_SETENV is defined
+.      if defined(CMAKE_TESTING_SETENV)
+_CMAKE_TESTING_SETENV=	${SETENV}
+.      else
+_CMAKE_TESTING_SETENV=	${SETENVI}
+.      endif
+
 # Handle the option-like CMAKE_TESTING_ON and CMAKE_TESTING_OFF lists.
 .      for _bool_kind in ON OFF
 .        if defined(CMAKE_TESTING_${_bool_kind})
@@ -196,7 +207,7 @@ do-test:
 	@cd ${BUILD_WRKSRC} && \
 		${SETENVI} ${WRK_ENV} ${CONFIGURE_ENV} ${CMAKE_BIN} ${CMAKE_ARGS} ${CMAKE_TESTING_ARGS} ${CMAKE_SOURCE_PATH} && \
 		${SETENVI} ${WRK_ENV} ${MAKE_ENV} ${MAKE_CMD} ${_MAKE_JOBS} ${MAKE_ARGS} ${ALL_TARGET} && \
-		${SETENVI} ${WRK_ENV} ${TEST_ENV} CTEST_PARALLEL_LEVEL=${CMAKE_TESTING_PARALLEL_LEVEL} ${MAKE_CMD} ${MAKE_ARGS} ${CMAKE_TESTING_TARGET}
+		${_CMAKE_TESTING_SETENV} ${WRK_ENV} ${TEST_ENV} CTEST_PARALLEL_LEVEL=${CMAKE_TESTING_PARALLEL_LEVEL} ${MAKE_CMD} ${MAKE_ARGS} ${CMAKE_TESTING_TARGET}
 .    endif
 .  endif