Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add INTERFACE_COMPILE_OPTIONS for memory leak detection to autotools …
…cmake package

The cmake install sets INTERFACE_COMPILE_OPTIONS on CppUTest::CppUTest to
force-include MemoryLeakDetectorForceInclude.h, wiring up leak detection
automatically for downstream cmake consumers. The autotools cmake package
was missing this, requiring consumers to add the force-include manually.

Add the same property to the autotools targets template, conditioned on
whether memory leak detection was enabled at configure time (it is also
implicitly disabled by --disable-std-c). The memory_leak_detection
configure variable is AC_SUBST'd so its value is baked into the Makefile
and passed to sed as a literal string at install time.
  • Loading branch information
thetic committed Mar 4, 2026
commit 8a685a12023051374a94ee87bfd90670a8ceb507
10 changes: 6 additions & 4 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,18 @@ cmakedir = $(libdir)/CppUTest/cmake
cmake_DATA = \
pkg/CppUTestConfigVersion.cmake

# The three cmake files below embed the install prefix and libdir, so they must
# be generated from templates at install time rather than copied as static files.
# This ensures the correct paths are used even when --libdir differs from the
# default (e.g. Debian multiarch: lib/x86_64-linux-gnu instead of lib).
# Generate cmake package files at install time. AC_CONFIG_FILES cannot be used
# because @libdir@ expands to ${exec_prefix}/lib rather than an absolute path
# (valid in pkg-config, not in cmake). $(prefix) and $(libdir) are make
# variables fully resolved at install time. @memory_leak_detection@ is a
# configure-time substitution baked into the Makefile as a literal value.
install-data-hook:
sed -e "s|%%PREFIX%%|$(prefix)|g" \
$(srcdir)/pkg/CppUTestConfig.cmake.autotools.in \
> "$(DESTDIR)$(cmakedir)/CppUTestConfig.cmake"
sed -e "s|%%PREFIX%%|$(prefix)|g" \
-e "s|%%LIBDIR%%|$(libdir)|g" \
-e "s|%%MEMORY_LEAK_DETECTION%%|@memory_leak_detection@|g" \
$(srcdir)/pkg/CppUTestTargets.cmake.autotools.in \
> "$(DESTDIR)$(cmakedir)/CppUTestTargets.cmake"

Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ fi
# Variables to substitute

AC_SUBST([CPP_PLATFORM])
AC_SUBST([memory_leak_detection])

AC_SUBST([INCLUDE_CPPUTEST_EXT])

Expand Down
7 changes: 7 additions & 0 deletions pkg/CppUTestTargets.cmake.autotools.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ set_target_properties(CppUTest::CppUTestExt PROPERTIES
IMPORTED_LOCATION "%%LIBDIR%%/libCppUTestExt.a"
)

if(NOT "%%MEMORY_LEAK_DETECTION%%" STREQUAL "no")
set_target_properties(CppUTest::CppUTest PROPERTIES
INTERFACE_COMPILE_OPTIONS
"$<$<COMPILE_LANGUAGE:C,CXX>:-includeCppUTest/MemoryLeakDetectorForceInclude.h>"
)
endif()

# Cleanup temporary variables.
set(_IMPORT_PREFIX)

Expand Down
Loading