# install(EXPORT) does not properly take into account of paths containing '..'

**URL:** https://discourse.cmake.org/t/install-export-does-not-properly-take-into-account-of-paths-containing/14408
**Category:** Code
**Tags:** os:linux
**Created:** [July 22, 2025, 12:50am UTC](https://discourse.cmake.org/t/install-export-does-not-properly-take-into-account-of-paths-containing/14408 "2025-07-22T00:50:11Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![WildCard65](https://discourse.cmake.org/user_avatar/discourse.cmake.org/wildcard65/32/5681_2.png) [@WildCard65](https://discourse.cmake.org/u/WildCard65)
#### Post date: [July 22, 2025, 12:50am UTC](https://discourse.cmake.org/t/install-export-does-not-properly-take-into-account-of-paths-containing/14408/1 "2025-07-22T00:50:11Z")

</div>

The command install(EXPORT) in its current state is vastly incompatible with making packages with non-standard install directories (for example /lib instead of /usr/lib) resulting in extra `get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)` being generated for every ‘..’ used instead of correctly calculating the appropriate path.

For example: If its installed to /lib/cmake//.cmake and the install prefix is /usr, it will generate an extra `get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)` for the ‘..’ inside of CMAKE\_INSTALL\_LIBDIR.

Why does this matter to me? Well I’m trying my hand of making my own Linux OS that uses a seperated /lib and /usr/lib instead of the standard symlink of /lib → /usr/lib.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [July 22, 2025, 5:44am UTC](https://discourse.cmake.org/t/install-export-does-not-properly-take-into-account-of-paths-containing/14408/2 "2025-07-22T05:44:38Z")

</div>

I can’t understand what you try to do?

You may always install to any prefix independent of the default settings:

```bash
bash-5.2$ cmake --install . --prefix /tmp
-- Install configuration: "RelWithDebInfo"
-- Installing: /tmp/lib/libbeman.exemplar.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /tmp/lib/libbeman.exemplar.a(identity.cpp.o) has no symbols
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: /tmp/lib/libbeman.exemplar.a the table of contents is empty (no object file members in the library define global symbols)
-- Installing: /tmp/include/beman/exemplar/identity.hpp
-- Installing: /tmp/lib/cmake/beman.exemplar/beman.exemplar-config.cmake
-- Installing: /tmp/lib/cmake/beman.exemplar/beman.exemplar-config-version.cmake
-- Installing: /tmp/lib/cmake/beman.exemplar/beman.exemplar-targets.cmake
-- Installing: /tmp/lib/cmake/beman.exemplar/beman.exemplar-targets-relwithdebinfo.cmake
bash-5.2$ cmake --install . 
-- Install configuration: "RelWithDebInfo"
-- Installing: /Users/clausklein/Workspace/cpp/beman-project/exemplar/stagedir/lib/libbeman.exemplar.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/clausklein/Workspace/cpp/beman-project/exemplar/stagedir/lib/libbeman.exemplar.a(identity.cpp.o) has no symbols
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: /Users/clausklein/Workspace/cpp/beman-project/exemplar/stagedir/lib/libbeman.exemplar.a the table of contents is empty (no object file members in the library define global symbols)
-- Up-to-date: /Users/clausklein/Workspace/cpp/beman-project/exemplar/stagedir/include/beman/exemplar/identity.hpp
-- Up-to-date: /Users/clausklein/Workspace/cpp/beman-project/exemplar/stagedir/lib/cmake/beman.exemplar/beman.exemplar-config.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/beman-project/exemplar/stagedir/lib/cmake/beman.exemplar/beman.exemplar-config-version.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/beman-project/exemplar/stagedir/lib/cmake/beman.exemplar/beman.exemplar-targets.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/beman-project/exemplar/stagedir/lib/cmake/beman.exemplar/beman.exemplar-targets-relwithdebinfo.cmake
bash-5.2$ 

```

---

<div class="post-metadata">

### Author: ![WildCard65](https://discourse.cmake.org/user_avatar/discourse.cmake.org/wildcard65/32/5681_2.png) [@WildCard65](https://discourse.cmake.org/u/WildCard65)
#### Post date: [July 22, 2025, 12:59pm UTC](https://discourse.cmake.org/t/install-export-does-not-properly-take-into-account-of-paths-containing/14408/3 "2025-07-22T12:59:50Z")

</div>

GNUInstallDirs normalizes the variable CMAKE\_INSTALL\_LIBDIR to be under /usr/, I have to force it to go to / by using ../ which results in an extra get\_filename\_componet() call for \_IMPORT\_PREFIX resulting in the final import prefix being outside of where “root” is.

This also results in /usr being dropped from the final auto determined import prefix as well.

---

<div class="post-metadata">

### Author: ![vito.gamberini](https://discourse.cmake.org/user_avatar/discourse.cmake.org/vito.gamberini/32/4376_2.png) [@vito.gamberini](https://discourse.cmake.org/u/vito.gamberini)
#### Post date: [July 22, 2025, 1:18pm UTC](https://discourse.cmake.org/t/install-export-does-not-properly-take-into-account-of-paths-containing/14408/4 "2025-07-22T13:18:10Z")

</div>

> [@WildCard65](#):
>
> GNUInstallDirs normalizes the variable CMAKE\_INSTALL\_LIBDIR to be under /usr/

This is the real bug, and the documentation added in CMake 3.4 to justify it is wrong:

```log
  /

  For <dir> other than the SYSCONFDIR, LOCALSTATEDIR and
  RUNSTATEDIR, the value of CMAKE_INSTALL_<dir> is prefixed
  with usr/ if it is not user-specified as an absolute path.

```

It justifies this with:

```log
  This is required by the GNU Coding Standards, which state:

    When building the complete GNU system, the prefix will be empty
    and /usr will be a symbolic link to /.

```

But that’s just, not what that sentence says at all? It’s saying if the prefix is _empty_ (not `"/"`), then everything should be installed to `/`, and anything that is installed to `/usr` should instead end up in `/`.

I would open up an issue. CMake should absolutely support the old-school usage of root as the “essentials” install tree.
