Incorrect installation directory for pkg-config files.
envgap__SFML__SFML-2778
01 / FAILURE SIGNATURE
As reported upstream
No identifying execution failure has been captured.
Not a benchmark task.
- In a clean container the reported failure did not reproduce, or the known fix did not make the project run.
02 / ENVIRONMENT RECIPE
- Base commit
69ea0cd863aed1d4092b970b676924a716ff718b- Manifest
CMakeLists.txt- Reproduce
Awaiting issue-specific recipe- Run under trace
Awaiting a meaningful runtime command
03 / ORIGINAL ISSUE TEXT
SFML/SFML #2778 · read the original issue
### Prerequisite Checklist
- [X] I searched for [existing issues](https://github.com/search?q=repo%3ASFML%2FSFML&type=issues) to prevent duplicates
- [X] I searched for [existing discussions on the forum](https://www.google.com/search?q=site%3Ahttps%3A%2F%2Fen.sfml-dev.org) to prevent duplicates
- [X] I am here to report an issue and not to just ask a question or look for help (use the [forum](https://en.sfml-dev.org/forums/index.php#c3) or [Discord](https://discord.gg/nr4X7Fh) instead)
### Describe your issue here
The pkg-config scripts (`tools/pkg-config/*.pc`) are always installed in the wrong location. This led to all Linux distros trying different tricks to override the wrong installation.
This happens because `SFML_PKGCONFIG_DIR` is not being expanded correctly.
In `Config.cmake`:
```cmake
set(SFML_PKGCONFIG_DIR "/${CMAKE_INSTALL_LIBDIR}/pkgconfig")
```
After the **first** `cmake` run, this variable expands to
```
//pkgconfig
```
After the **second** `cmake` run, it changes to:
```
/lib64/pkgconfig
```
It appears that `CMAKE_INSTALL_LIBDIR` is set AFTER it's used to set `SFML_PKGCONFIG_DIR`.
I think the problem is caused by the wrong order of inclusion in `CMakeLists.txt`:
```cmake
# include the configuration file
include(cmake/Config.cmake)
# we use the paths from the cmake GNUInstallDirs module as defaults
# you can override these if you like
# https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
include(GNUInstallDirs)
```
If I change it to include `GNUInstallDirs` before `cmake/Config.cmake`, the value seems to be set correctly.
### Your Environment
- OS / distro / window manager: Fedora 39, Mageia 9, Ubuntu Mantic, Debian Bookworm, Arch Linux (latest stable releases of all of them)
- SFML version: 2.6.1
- Compiler / toolchain: GCC
- Special compiler / CMake flags: none
### Steps to reproduce
1. Edit `cmake/Config.cmake`, appending these lines at the bottom:
```cmake
message(STATUS ":::: CMAKE_INSTALL_LIBDIR = ${CMAKE_INSTALL_LIBDIR}")
message(STATUS ":::: SFML_PKGCONFIG_DIR = ${SFML_PKGCONFIG_DIR}")
```
2. `mkdir build`
3. `cd build`
4. `cmake ..`
5. `cmake ..`
### Expected behavior
It should always print
```
-- :::: CMAKE_INSTALL_LIBDIR = lib64
-- :::: SFML_PKGCONFIG_DIR = /lib64/pkgconfig
```
each time `cmake` is run.
### Actual behavior
First `cmake` run prints:
```
-- :::: CMAKE_INSTALL_LIBDIR =
-- :::: SFML_PKGCONFIG_DIR = //pkgconfig
```
The second run prints:
```
-- :::: CMAKE_INSTALL_LIBDIR = lib64
-- :::: SFML_PKGCONFIG_DIR = /lib64/pkgconfig
```04 / LABELS
Labels from the report text only; not yet run
No supported category has been assigned.
Label rules and the text that matched
[]