Fix header file installation to respect CMAKE_INSTALL_INCLUDEDIR
#1125
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When
CMAKE_INSTALL_INCLUDEDIR
are set to absolute path or relative path, the header files is installed in unspecifed places. This leads to incorrect paths that prevent the compiler from locating necessary header files.How to reproduce
Configure msgpack-c with
-DCMAKE_INSTALL_PREFIX=/tmp/local
and-DCMAKE_INSTALL_INCLUDEDIR=specified-include
And then build and install msgpack-c.
Compile
example/simple_c.c
using installed msgpack-c. The following error happens because the linker cannot find header files.Expected
Successfully compile
example/simple_c.c
using installed msgpack-c. We can execute simple_c like the following.Explain the problem in detail
The issue was caused by header files being installed under a uniform include directory, ignoring the specified
CMAKE_INSTALL_INCLUDEDIR
path. This resulted in incorrect paths during the installation process, causing the compiler to be unable to locate the necessary header files.For example, in the
How to reproduce
case, we expected that header files would be installed at/tmp/local/specified-include
because we passed-DCMAKE_INSTALL_PREFIX=/tmp/local
and-DCMAKE_INSTALL_INCLUDEDIR=specified-include
. And also, pkg-config expected this path too.However, these header files are installed under
/tmp/local/include/
, which is why the compiler cannot find the header files.Solution
The solution involves modifying the
CMakeLists.txt
to ensure that the header files are installed in the directories specified byCMAKE_INSTALL_INCLUDEDIR
.