CMake config file references files with wrong path

Bug #1799660 reported by Elvis Stansvik
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
pugixml (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

I tried to use this package when building VTK from source, by passing the flag

    -Dpugixml_DIR=/usr/share/libpugixml-dev/cmake

to the CMake configure step. This failed with

CMake Error at /usr/share/libpugixml-dev/cmake/pugixml-config.cmake:87 (message):
  The imported target "pugixml" references the file

     "/lib/x86_64-linux-gnu/libpugixml.so.1.8"

  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

     "/usr/share/libpugixml-dev/cmake/pugixml-config.cmake"

  but not all the files it references.

Call Stack (most recent call first):
  CMake/vtkModuleMacros.cmake:891 (find_package)
  ThirdParty/pugixml/CMakeLists.txt:1 (vtk_module_third_party)

Looking at /usr/share/libpugixml-dev/cmake/pugixml-config.cmake, this section of code:

# Compute the installation prefix relative to this file.
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
# Use original install prefix when loaded through a
# cross-prefix symbolic link such as /lib -> /usr/lib.
get_filename_component(_realCurr "${_IMPORT_PREFIX}" REALPATH)
get_filename_component(_realOrig "/usr/lib/x86_64-linux-gnu/cmake/pugixml" REALPATH)
if(_realCurr STREQUAL _realOrig)
  set(_IMPORT_PREFIX "/usr/lib/x86_64-linux-gnu/cmake/pugixml")
endif()
unset(_realOrig)
unset(_realCurr)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
if(_IMPORT_PREFIX STREQUAL "/")
  set(_IMPORT_PREFIX "")
endif()

seems to arrive at a ${_IMPORT_PREFIX} of "", which means e.g.

set_target_properties(pugixml PROPERTIES
  IMPORTED_LOCATION_NOCONFIG "${_IMPORT_PREFIX}/lib/x86_64-linux-gnu/libpugixml.so.1.8"
  IMPORTED_SONAME_NOCONFIG "libpugixml.so.1"
  )

in /usr/share/libpugixml-dev/cmake/pugixml-config-noconfig.cmake will become wrong ("/lib/x86_64-linux-gnu/libpugixml.so.1"), leading to config error.

Looks like the calculation of ${_IMPORT_PREFIX} is wrong, not sure if this is because of some wrong assumption that doesn't hold.

Seems to make it impossible to use this package from a CMake-using project (using -Dpugixml_DIR).

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in pugixml (Ubuntu):
status: New → Confirmed
Revision history for this message
Gianfranco Costamagna (costamagnagianfranco) wrote :

Hello, I think this bug should be reported upstream! can you please do it?

Revision history for this message
Gianfranco Costamagna (costamagnagianfranco) wrote :

This should be fixed at least in Ubuntu jammy

cat ../CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
project(test)
find_package(pugixml REQUIRED)
add_executable(test test.cpp)
target_link_libraries(test pugixml)

cat ../test.cpp
#include <pugixml.hpp>
#include <stdio.h>
int main()
{
 printf("%d\n",PUGIXML_VERSION);
}

$ cmake ..
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /foo/bar

# make VERBOSE=1
/usr/bin/cmake -S/foo -B/foo/bar --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /foo/bar/CMakeFiles /foo/bar//CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/foo/bar'
make -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/depend
make[2]: Entering directory '/foo/bar'
cd /foo/bar && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /foo /foo /foo/bar /foo/bar /foo/bar/CMakeFiles/test.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/foo/bar'
make -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/build
make[2]: Entering directory '/foo/bar'
[ 50%] Building CXX object CMakeFiles/test.dir/test.cpp.o
/usr/bin/c++ -MD -MT CMakeFiles/test.dir/test.cpp.o -MF CMakeFiles/test.dir/test.cpp.o.d -o CMakeFiles/test.dir/test.cpp.o -c /foo/test.cpp
[100%] Linking CXX executable test
/usr/bin/cmake -E cmake_link_script CMakeFiles/test.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/test.dir/test.cpp.o -o test /usr/lib/x86_64-linux-gnu/libpugixml.so.1.12
make[2]: Leaving directory '/foo/bar'
[100%] Built target test
make[1]: Leaving directory '/foo/bar'
/usr/bin/cmake -E cmake_progress_start /foo/bar/CMakeFiles 0
# ./test
1120

Changed in pugixml (Ubuntu):
status: Confirmed → Won't Fix
status: Won't Fix → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.