This patch fixes Capstone 5 build on NixOS.
NixOS's build infrastructure sets CMAKE_INSTALL_{LIB,INCLUDE}DIR to
absolute paths. If you append it to ${prefix}, you get the wrong path.
NixOS automatically detects it and links this issue:
https://github.com/NixOS/nixpkgs/issues/144170
CMake installs the "common headers" for Capstone into a capstone/
subdirectory of the system's includedir:
install(
FILES ${HEADERS_COMMON}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/capstone
)
The pkg-config file, on the other hand, omits the subdirectory:
includedir=${prefix}/include
Cflags: -I${includedir}
This means that consumers of the library would need to include the
"capstone/" prefix when including those headers. For example,
#include <capstone/capstone.h>
rather than
#include <capstone.h>
Neither is "wrong" -- it's a design choice, but one that breaks the
public API when it changes. This has happened before:
https://github.com/capstone-engine/capstone/commit/0a39b785https://github.com/capstone-engine/capstone/commit/02e33f8b
And (for example) PHP was updated to reflect that, i.e. to work with
capstone-4.x:
https://github.com/php/php-src/commit/ffc2a53a
But now in the 5.x series of Capstone, the path (or the -I flag,
relative to that path) has reverted,
https://github.com/capstone-engine/capstone/commit/6656bcb6
breaking PHP once again. This commit re-fixes it by updating the
directory passed via Cflags.
Closes: https://github.com/capstone-engine/capstone/issues/1982
On x86_64-linux gentoo system capstone was installing
it's files to 'lib64' libdir, but was referring 'lib' libdir:
```
$ cat /usr/lib64/pkgconfig/capstone.pc
...
libdir=${prefix}/lib
...
```
On radare2 built it means injecting -L/usr/lib into a 64-build
and pulling in 32-bit libraries. 'ld.lld' is not able to resolve
the ambiguity.
It happens because @LIBSUFFIX@ is not present in cmake-3.17.3.
Let's fix the paths by using @CMAKE_INSTALL_LIBDIR@.
This variable is already used in capstone's build system,
thus should be safe to rely on.
Reported-by: Agostino Sarubbo
Bug: https://bugs.gentoo.org/730722
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
* fixed hardcoded paths with variables.
cmake pkg-config file fixed hardcoded paths with variables. CMakeLists.txt line 394 needs to be modified
> configure_file("capstone.pc.in" "capstone.pc" @ONLY)
* forgot to add 64bit support variable.