# CMake generated Targerts file and staging areas

**URL:** https://discourse.cmake.org/t/cmake-generated-targerts-file-and-staging-areas/6873
**Category:** Usage
**Created:** [November 15, 2022, 2:47pm UTC](https://discourse.cmake.org/t/cmake-generated-targerts-file-and-staging-areas/6873 "2022-11-15T14:47:22Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![JanWielemaker](https://discourse.cmake.org/user_avatar/discourse.cmake.org/janwielemaker/32/438_2.png) [@JanWielemaker](https://discourse.cmake.org/u/JanWielemaker)
#### Post date: [November 15, 2022, 2:47pm UTC](https://discourse.cmake.org/t/cmake-generated-targerts-file-and-staging-areas/6873/1 "2022-11-15T14:47:22Z")

</div>

When I look at a `<Project>Targets.cmake` generated by CMake 22.1, I see that it compensates for the fact that the file may not be in its final destination (e.g., it may be in some _staging_ area). Here is the relevant snippet from SWIPLTargets.cmake, normally located in `/usr/lib/cmake/swipl/SWIPLTargets.cmake`.

```auto
# Compute the installation prefix relative to this file.
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" 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()

# Create imported target swipl::swipl
add_executable(swipl::swipl IMPORTED)

# Create imported target swipl::libswipl
add_library(swipl::libswipl SHARED IMPORTED)

set_target_properties(swipl::libswipl PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/lib/swipl/include"
)

```

This adjust the location of the include directory, but when I use this for building a snap, where system is installed in the staging area `/root/stage/usr/`, I get the error below. It seems the location of the library is _not_ updated.

```auto
CMake Error at /root/stage/usr/lib/cmake/swipl/SWIPLTargets.cmake:87 (message):
  The imported target "swipl::libswipl" references the file

     "/usr/lib/libswipl.so.8.5.20"

  but this file does not exist. Possible reasons include:

```

Is this a bug?

**edit** This is getting a little weird. I see this is intended to work because the build-type specific Targets files use e.g.

```
 IMPORTED_LOCATION_RELWITHDEBINFO "${_IMPORT_PREFIX}/lib/swipl/lib/x86_64-linux/libswipl.so.8.5.20"

```

In the version that is build as part of building a [snap](https://snapcraft.io/) however, the import for the executable uses `IMPORTED_LOCATION_PGO "${_IMPORT_PREFIX}/lib/swipl/bin/x86_64-linux/swipl"`, but the one for the library uses simply `IMPORTED_LOCATION_PGO "/usr/lib/libswipl.so.8.5.20"` That seems wrong to me, but this is from the same source, both running in Ubuntu 22.04 using CMake 22.1. Only, the good one on bare metal and the bad one as part of a snap build process in an LXD container.

I’ll keep digging. Hints are welcome 🙂
