From f97781c76e94d0f3967e1b5885f942a818068fd6 Mon Sep 17 00:00:00 2001
From: Pascal Palenda <pascal.palenda@akustik.rwth-aachen.de>
Date: Wed, 15 Feb 2023 10:50:06 +0100
Subject: [PATCH] Add output option for the test executable target

---
 src/IhtaAddLibrary.cmake | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/IhtaAddLibrary.cmake b/src/IhtaAddLibrary.cmake
index 4959d2e..235f319 100644
--- a/src/IhtaAddLibrary.cmake
+++ b/src/IhtaAddLibrary.cmake
@@ -73,7 +73,7 @@ include_guard ()
 		If not specified, the install expects the same include folder structure as in the
 		libraries include folder.
 
-	.. variable:: OUT_VAR
+	.. variable:: OUT_LIB
 
 		Variable name into which the library target name will be set.
 
@@ -99,6 +99,12 @@ include_guard ()
 		Default is `${CMAKE_CURRENT_SOURCE_DIR}/src`.
 		This should be given if TEST_INTERNALS is given and one wants to test the internals.
 
+	.. variable:: OUT_TEST
+
+		Variable name into which the test target name will be set.
+
+		This can be useful when further settings must be applied to the test target.
+
 	.. variable:: OBJECT_LIB_POSTFIX
 
 		Optionally specify a postfix for the object library if TEST_INTERNALS is specified.
@@ -117,7 +123,8 @@ macro (ihta_add_library)
 		INSTALL_INCLUDE_DIR
 		IDE_FOLDER
 		OBJECT_LIB_POSTFIX
-		OUT_VAR
+		OUT_LIB
+		OUT_TEST
 	)
 	set (multiValueArgs SOURCES TEST_SOURCES)
 	cmake_parse_arguments (IHTA_ADD_LIB "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
@@ -219,8 +226,8 @@ macro (ihta_add_library)
 	GroupSourcesByFolder (${IHTA_ADD_LIB_TARGET})
 
 	if (IHTA_ADD_LIB_TEST_SOURCES)
+		set (IHTA_ADD_LIB_TEST_TARGET ${IHTA_ADD_LIB_NAME}UnitTest)
 		if (IHTA_ADD_LIB_TEST_INTERNALS)
-			set (IHTA_ADD_LIB_TEST_TARGET ${IHTA_ADD_LIB_NAME}UnitTest)
 			ihta_add_test (
 				NAME ${IHTA_ADD_LIB_TEST_TARGET}
 				IDE_FOLDER ${IHTA_ADD_LIB_IDE_FOLDER}
@@ -235,14 +242,19 @@ macro (ihta_add_library)
 			)
 		else ()
 			ihta_add_test (
+				NAME ${IHTA_ADD_LIB_TEST_TARGET}
 				TEST_TARGET ${IHTA_ADD_LIB_TARGET}
 				IDE_FOLDER ${IHTA_ADD_LIB_IDE_FOLDER}
 				SOURCES ${IHTA_ADD_LIB_TEST_SOURCES}
 			)
 		endif ()
+
+		if (IHTA_ADD_LIB_OUT_TEST)
+			set (${IHTA_ADD_LIB_OUT_TEST} ${IHTA_ADD_LIB_TEST_TARGET})
+		endif ()
 	endif ()
 
-	if (IHTA_ADD_LIB_OUT_VAR)
-		set (${IHTA_ADD_LIB_OUT_VAR} ${IHTA_ADD_LIB_TARGET})
+	if (IHTA_ADD_LIB_OUT_LIB)
+		set (${IHTA_ADD_LIB_OUT_LIB} ${IHTA_ADD_LIB_TARGET})
 	endif ()
 endmacro ()
-- 
GitLab