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
Next Next commit
Fix autotools cmake package files for non-standard libdir (Debian mul…
…tiarch)

The pre-generated cmake files in build/cmake_package_files/ hard-coded a
3-level directory traversal to find the install prefix.  On Debian multiarch
systems (--libdir=lib/x86_64-linux-gnu) the files land one level deeper, so
the traversal resolved to /usr/lib instead of /usr, breaking every downstream
find_package(CppUTest) call.

Replace the three path-dependent files with *.autotools.in templates that use
%%PREFIX%% and %%LIBDIR%% placeholders.  A new install-data-hook in Makefile.am
substitutes the real $(prefix) and $(libdir) at install time via sed, so the
generated files always contain correct absolute paths regardless of --libdir.

Also add an uninstall-local hook to clean up the generated files.

Fixes: #1880
Fixes: #1563
  • Loading branch information
thetic committed Mar 3, 2026
commit e90a246ec3e116856b5f0f620f2fd90a057c0870
25 changes: 21 additions & 4 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,27 @@ cmakescripts_DATA = \

cmakedir = $(libdir)/CppUTest/cmake
cmake_DATA = \
build/cmake_package_files/CppUTestConfig.cmake \
build/cmake_package_files/CppUTestConfigVersion.cmake \
build/cmake_package_files/CppUTestTargets-relwithdebinfo.cmake \
build/cmake_package_files/CppUTestTargets.cmake
build/cmake_package_files/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).
install-data-hook:
sed -e "s|%%PREFIX%%|$(prefix)|g" \
$(srcdir)/build/cmake_package_files/CppUTestConfig.cmake.autotools.in \
> "$(DESTDIR)$(cmakedir)/CppUTestConfig.cmake"
sed -e "s|%%PREFIX%%|$(prefix)|g" \
$(srcdir)/build/cmake_package_files/CppUTestTargets.cmake.autotools.in \
> "$(DESTDIR)$(cmakedir)/CppUTestTargets.cmake"
sed -e "s|%%LIBDIR%%|$(libdir)|g" \
$(srcdir)/build/cmake_package_files/CppUTestTargets-relwithdebinfo.cmake.autotools.in \
> "$(DESTDIR)$(cmakedir)/CppUTestTargets-relwithdebinfo.cmake"

uninstall-local:
rm -f "$(DESTDIR)$(cmakedir)/CppUTestConfig.cmake"
rm -f "$(DESTDIR)$(cmakedir)/CppUTestTargets.cmake"
rm -f "$(DESTDIR)$(cmakedir)/CppUTestTargets-relwithdebinfo.cmake"

EXTRA_DIST = \
cpputest.pc.in \
Expand Down
29 changes: 29 additions & 0 deletions build/cmake_package_files/CppUTestConfig.cmake.autotools.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
####### Generated from CppUTestConfig.cmake.autotools.in during 'make install' ######

set(PACKAGE_PREFIX_DIR "%%PREFIX%%")

macro(set_and_check _var _file)
set(${_var} "${_file}")
if(NOT EXISTS "${_file}")
message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
endif()
endmacro()

macro(check_required_components _NAME)
foreach(comp ${${_NAME}_FIND_COMPONENTS})
if(NOT ${_NAME}_${comp}_FOUND)
if(${_NAME}_FIND_REQUIRED_${comp})
set(${_NAME}_FOUND FALSE)
endif()
endif()
endforeach()
endmacro()

####################################################################################

set_and_check(CppUTest_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include")
include("${CMAKE_CURRENT_LIST_DIR}/CppUTestTargets.cmake")
set(CppUTest_LIBRARIES CppUTest CppUTestExt)
include("${CMAKE_CURRENT_LIST_DIR}/Modules/CppUTestBuildTimeDiscoverTests.cmake")

check_required_components(CppUTest)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#----------------------------------------------------------------
# Generated CMake target import file for configuration "RelWithDebInfo".
#----------------------------------------------------------------

# Commands may need to know the format version.
set(CMAKE_IMPORT_FILE_VERSION 1)

# Import target "CppUTest" for configuration "RelWithDebInfo"
set_property(TARGET CppUTest APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)
set_target_properties(CppUTest PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES_RELWITHDEBINFO "CXX"
IMPORTED_LOCATION_RELWITHDEBINFO "%%LIBDIR%%/libCppUTest.a"
)

list(APPEND _IMPORT_CHECK_TARGETS CppUTest )
list(APPEND _IMPORT_CHECK_FILES_FOR_CppUTest "%%LIBDIR%%/libCppUTest.a" )

# Import target "CppUTestExt" for configuration "RelWithDebInfo"
set_property(TARGET CppUTestExt APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)
set_target_properties(CppUTestExt PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES_RELWITHDEBINFO "CXX"
IMPORTED_LOCATION_RELWITHDEBINFO "%%LIBDIR%%/libCppUTestExt.a"
)

list(APPEND _IMPORT_CHECK_TARGETS CppUTestExt )
list(APPEND _IMPORT_CHECK_FILES_FOR_CppUTestExt "%%LIBDIR%%/libCppUTestExt.a" )

# Commands beyond this point should not need to know the version.
set(CMAKE_IMPORT_FILE_VERSION)
95 changes: 95 additions & 0 deletions build/cmake_package_files/CppUTestTargets.cmake.autotools.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Generated by CMake

if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.5)
message(FATAL_ERROR "CMake >= 2.6.0 required")
endif()
cmake_policy(PUSH)
cmake_policy(VERSION 2.6)
#----------------------------------------------------------------
# Generated CMake target import file.
#----------------------------------------------------------------

# Commands may need to know the format version.
set(CMAKE_IMPORT_FILE_VERSION 1)

# Protect against multiple inclusion, which would fail when already imported targets are added once more.
set(_targetsDefined)
set(_targetsNotDefined)
set(_expectedTargets)
foreach(_expectedTarget CppUTest CppUTestExt)
list(APPEND _expectedTargets ${_expectedTarget})
if(NOT TARGET ${_expectedTarget})
list(APPEND _targetsNotDefined ${_expectedTarget})
endif()
if(TARGET ${_expectedTarget})
list(APPEND _targetsDefined ${_expectedTarget})
endif()
endforeach()
if("${_targetsDefined}" STREQUAL "${_expectedTargets}")
unset(_targetsDefined)
unset(_targetsNotDefined)
unset(_expectedTargets)
set(CMAKE_IMPORT_FILE_VERSION)
cmake_policy(POP)
return()
endif()
if(NOT "${_targetsDefined}" STREQUAL "")
message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_targetsDefined}\nTargets not yet defined: ${_targetsNotDefined}\n")
endif()
unset(_targetsDefined)
unset(_targetsNotDefined)
unset(_expectedTargets)


# Set the installation prefix from the autotools install.
set(_IMPORT_PREFIX "%%PREFIX%%")

# Create imported target CppUTest
add_library(CppUTest STATIC IMPORTED)

set_target_properties(CppUTest PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include;${_IMPORT_PREFIX}/include/CppUTest"
)

# Create imported target CppUTestExt
add_library(CppUTestExt STATIC IMPORTED)

set_target_properties(CppUTestExt PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include;${_IMPORT_PREFIX}/include/CppUTestExt"
)

# Load information for each installed configuration.
get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
file(GLOB CONFIG_FILES "${_DIR}/CppUTestTargets-*.cmake")
foreach(f ${CONFIG_FILES})
include(${f})
endforeach()

# Cleanup temporary variables.
set(_IMPORT_PREFIX)

# Loop over all imported files and verify that they actually exist
foreach(target ${_IMPORT_CHECK_TARGETS} )
foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} )
if(NOT EXISTS "${file}" )
message(FATAL_ERROR "The imported target \"${target}\" references the file
\"${file}\"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
\"${CMAKE_CURRENT_LIST_FILE}\"
but not all the files it references.
")
endif()
endforeach()
unset(_IMPORT_CHECK_FILES_FOR_${target})
endforeach()
unset(_IMPORT_CHECK_TARGETS)

# This file does not depend on other imported targets which have
# been exported from the same project but in a separate export set.

# Commands beyond this point should not need to know the version.
set(CMAKE_IMPORT_FILE_VERSION)
cmake_policy(POP)