Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for absolute CMAKE_INSTALL_*DIR #1

Draft
wants to merge 1 commit into
base: c_master
Choose a base branch
from

Conversation

otegami
Copy link
Owner

@otegami otegami commented Apr 24, 2024

Problem

The Current CMakeLists incorrectly configures libdir and includedir when CMAKE_INSTALL_LIBDIR and CMAKE_INSTALL_INCLUDEDIR are absolute paths. And then it leads to incorrect paths in the generated pkg-config file.
This misconfiguration prevents the compiler from finding necessary header files and library files.

How to reproduce

% git switch -c c_master
% cmake -S . -B ../msgpack-c.build -DCMAKE_INSTALL_PREFIX=/tmp/local
% cmake --build ../msgpack-c.build
% cmake --install ../msgpack-c.build
% export PKG_CONFIG_PATH=/tmp/local/lib/pkgconfig:$PKG_CONFIG_PATH
% gcc -o simple_c example/simple_c.c $(pkg-config --cflags --libs msgpack-c)
In file included from include/msgpack/object.h:13,
                 from include/msgpack.h:17,
                 from example/simple_c.c:1:
include/msgpack/zone.h:13:10: fatal error: sysdep.h: No such file or directory
   13 | #include "sysdep.h"
      |          ^~~~~~~~~~
compilation terminated.`

Expected

% gcc -o simple_c example/simple_c.c $(pkg-config --cflags --libs msgpack-c)
% ./simple_c
93 01 c3 a7 65 78 61 6d 70 6c 65
[1, true, "example"]

Solution

Adjust the CMakeLists.txt to correctly handle both relative and absolute paths for library and include directories. Update the msgpack-c.pc.in file to use proper variables that respect the absolute path settings.

@@ -1,7 +1,6 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exec_prefix は利用されていないかつ、どちらもCMAKE_INSTALL_PREFIXを参照ているので必要ないと判断しました。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kou
Copy link

kou commented Apr 25, 2024

自分で「How to reproduce」にまとめている通り、CMAKE_INSTALL_LIBDIRとかに絶対パスを指定していなくても壊れています。
pkg-config --cflags --libs msgpack-cで出てくるパスが相対パスになっているからです。

@kou
Copy link

kou commented Apr 25, 2024

まずは、以下のケースに対応して

  • 何も指定しない
  • CMAKE_INSTALL_INCLUDEDIR/CMAKE_INSTALL_LIBDIRに相対パスを指定(-DCMAKE_INSTALL_LIBDIR=lib64とか)

それが終わってから以下のケースに対応するのがいいんじゃないかな。

  • CMAKE_INSTALL_INCLUDEDIR/CMAKE_INSTALL_LIBDIRに絶対パスを指定(-DCMAKE_INSTALL_LIBDIR=/tmp/local/lib/x86_64-linux-gnuとか)

@kou
Copy link

kou commented Apr 25, 2024

前者は↓で動くようになりませんか?

diff --git a/msgpack-c.pc.in b/msgpack-c.pc.in
index 20806625..14806b7b 100644
--- a/msgpack-c.pc.in
+++ b/msgpack-c.pc.in
@@ -1,7 +1,7 @@
 prefix=@prefix@
 exec_prefix=@exec_prefix@
-libdir=@libdir@
-includedir=@includedir@
+libdir=${prefix}/@libdir@
+includedir=${prefix}/@includedir@
 
 Name: MessagePack
 Description: Binary-based efficient object serialization library

@otegami
Copy link
Owner Author

otegami commented Apr 25, 2024

レビューありがとうございます。
確かにいきなり絶対パスを指定対応するのも唐突なので分けて対応していきたいと思います。

  • 何も指定しない && 相対パスの対応
  • 絶対パスの対応

@otegami
Copy link
Owner Author

otegami commented Apr 26, 2024

何も指定しない && 相対パスの対応

下記で完了したので、次は、絶対パスの対応をしたい。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants