Skycoder42 / QHotkey

A global shortcut/hotkey for Desktop Qt-Applications
BSD 3-Clause "New" or "Revised" License
548 stars 161 forks source link

CMake: honor CMAKE_INSTALL_INCLUDEDIR in exported target #52

Closed dbermond closed 2 years ago

dbermond commented 2 years ago

Currently, when a user/packager builds and installs QHotkey system-wide with a custom CMAKE_INSTALL_INCLUDEDIR, the headers are in fact installed to the correct path chosen by CMAKE_INSTALL_INCLUDEDIR, but the CMake exported target becomes broken.

This is happening because the include directory is hardcoded in CMakeLists.txt. As a consequence, when a client application tries to access QHotkey by find_package(), the imported CMake target will tell that headers are installed at <prefix>/include due to the include hardcode, while in fact the headers will be installed at <prefix>/CMAKE_INSTALL_INCLUDEDIR.

In such explained situation, this will lead to the following compile error:

fatal error: QHotkey: No such file or directory

This commit removes the hardcode to the include directory in the CMake exported target, replacing it with CMAKE_INSTALL_INCLUDEDIR as the CMake exporting documentation recommends. This will let the user correctly access the headers when building a client application with a QHotkey package that is installed with a CMAKE_INSTALL_INCLUDEDIR different than include.

I think it's also a good idea to remove the ending slash from the install(FILES <...>) statement, as it should match exactly the same path that is being exported by $<INSTALL_INTERFACE:CMAKE_INSTALL_INCLUDEDIR>, as also shown on the same pointed documentation above.

dbermond commented 2 years ago

Thank you for merging this.

Skycoder42 commented 2 years ago

@Shatur done