Relocate all test and ctest executables to bin/unit-test

Test binaries (naming: test_* | *_test | *_smoke | *Tests - 26 targets
incl. the ctest-registered ones and pdmTests) now build into
<build>/bin/unit-test/ instead of <build>/bin/.

- CMakeLists: post-processing pass after all add_subdirectory calls sets
  RUNTIME_OUTPUT_DIRECTORY (overrides the legacy EXECUTABLE_OUTPUT_PATH)
  plus a 5-level $ORIGIN BUILD_RPATH entry (from bin/unit-test the RTI
  libs are one level further away than from bin/). Targets are collected
  by walking the SUBDIRECTORIES tree - the global TARGETS property is
  empty under CMake 4.x, which silently broke the first attempt.
- add_test() uses $<TARGET_FILE:...>, so the ctest registry follows the
  new location without changes.
- rpmbuild/make_rpm_ubuntu26*.py: test discovery points at
  build/bin/unit-test; the release2 runtime DEB mirrors the layout into
  usr/bin/unit-test/ so the test binaries stay in the package.
- README: bin/unit-test/ documented in the output list and snippets.

Verified (fresh /workspace-mount build): all 26 test executables in
bin/unit-test/, ctest 20/22 (same 2 pre-existing out-of-scope failures),
RUNPATH carries the 5-level $ORIGIN RTI entry and ddscore_unit_test runs
from bin/unit-test with no LD_LIBRARY_PATH / RTI_LICENSE; app binaries in
bin/ keep their 4-level entry.
This commit is contained in:
berrux-dev committed 2026-11-17 00:48:34 +01:00
1 parent dc2c3e358b
commit 9d0403817e
4 files changed
+63 -12

No files matched your search

@@ -1121,6 +1121,43 @@ NGL_ADD_SUBDIR_GUARDED(Lts)
# were removed from this branch; their add_subdirectory calls are gone with them.)
#-----------------------------------------------------------------------------------------------------
#
# --- Relayout: all test / ctest executables go to bin/unit-test --------------
#
# Naming convention: test_* | *_test | *_smoke | *Tests (module test apps
# such as pdmTests). The target property overrides the global
# EXECUTABLE_OUTPUT_PATH (bin/) set above. add_test() entries use
# $<TARGET_FILE:...>, so the ctest registry follows the new location
# automatically.
#
# The global RTI RUNPATH $ORIGIN entry (4 levels up) is correct for bin/
# artifacts; from bin/unit-test/ the RTI libs are 5 levels up, so test
# executables additionally get a target-specific BUILD_RPATH entry. (Dead
# entries pointing at nonexistent dirs are harmless - the loader skips them.)
FILE(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/bin/unit-test")
# Collect the targets defined in this directory and all of its subdirectories.
# (The global property TARGETS is empty in CMake 4.x, so walk the directory
# tree instead. The macro expands in the caller's scope, so the list
# accumulates across the recursion.)
MACRO(_NGL_COLLECT_TARGETS _nngl_dir)
GET_PROPERTY(_nngl_dir_targets DIRECTORY ${_nngl_dir} PROPERTY BUILDSYSTEM_TARGETS)
LIST(APPEND _NGL_ALL_TARGETS ${_nngl_dir_targets})
GET_PROPERTY(_nngl_subdirs DIRECTORY ${_nngl_dir} PROPERTY SUBDIRECTORIES)
FOREACH(_nngl_sub ${_nngl_subdirs})
_NGL_COLLECT_TARGETS(${_nngl_sub})
ENDFOREACH()
ENDMACRO()
SET(_NGL_ALL_TARGETS "")
_NGL_COLLECT_TARGETS(${CMAKE_SOURCE_DIR})
FOREACH(_NGL_T ${_NGL_ALL_TARGETS})
GET_TARGET_PROPERTY(_NGL_T_TYPE ${_NGL_T} TYPE)
IF(_NGL_T_TYPE STREQUAL "EXECUTABLE" AND
_NGL_T MATCHES "^(test_.*|.*(_test|_smoke|Tests))$")
SET_TARGET_PROPERTIES(${_NGL_T} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/unit-test"
BUILD_RPATH "$ORIGIN/../../../../../external/rti_connext_dds-7.7.0/resource/app/lib/x64Linux4gcc8.5.0")
ENDIF()
ENDFOREACH()
# QAV analysis script dir (qav/) is not part of this branch.
OPTION(BUILD_QAV "Build script for local QAV analysis" OFF)