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

cmake: Fix paths in pkg-config file #563

Closed
wants to merge 1 commit into from

Conversation

jtojnar
Copy link
Contributor

@jtojnar jtojnar commented Jul 6, 2020

It is not generally true that CMAKE_INSTALL_<dir> variables are relative paths:

https://github.com/jtojnar/cmake-snips#concatenating-paths-when-building-pkg-config-files

Absolute paths will cause things like this appear:

includedir=${prefix}//nix/store/87zhscw1p08nqm73ls2sd82zmr1a8rni-libiio-0.21-dev/include

Signed-off-by: Jan Tojnar [email protected]

It is not generally true that `CMAKE_INSTALL_<dir>` variables are relative paths:

https://github.com/jtojnar/cmake-snips#concatenating-paths-when-building-pkg-config-files

Absolute paths will cause things like this appear:

    includedir=${prefix}//nix/store/87zhscw1p08nqm73ls2sd82zmr1a8rni-libiio-0.21-dev/include

Signed-off-by: Jan Tojnar <[email protected]>
@@ -1,7 +1,7 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
libdir=@libdir_for_pc_file@
Copy link
Contributor

Choose a reason for hiding this comment

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

what if we do:

libdir=@CMAKE_INSTALL_LIBDIR@
includedir=@CMAKE_INSTALL_INCLUDEDIR@

and make sure that CMAKE_INSTALL_xxxx are absolute paths?
and if they aren't absolute maybe we cal do CMAKE_INSTALL_LIBDIR=CMAKE_INSTALL_PREFIX/CMAKE_INSTALL_LIBDIR

the overall join_paths() looks nice, but it's a bit more logic than is required to solve the actual problem;
and it looks to me that CMAKE_INSTALL_LIBDIR (and includedir) is used in CMakeLists.txt as well;
so there can be a minor inconsistency between the values of CMAKE_INSTALL_LIBDIR use in libiio.pc.cmakein and the ones used in CMakeLists.txt

so, maybe something like?:

if(NOT IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
CMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
endif

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and make sure that CMAKE_INSTALL_xxxx are absolute paths?

There are FULL variants of the variables, see the docs so that could be used if we decide to go that way.

The reason why there is ${prefix} is to make it overridable (at least in the cases when it is not absolute), see https://www.bassi.io/articles/2018/03/15/pkg-config-and-paths/.

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, you are right;
i am just a bit hesitant about having an extra level of indirection for changing from includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ to constructing ${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ in CMake via some function;

if libiio.pc.cmakein will only be generated from CMake, then this code seems a bit much;
i'm not fully against it, i just prefer something simpler to read/review

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess the absolute paths are fine if libiio does not expect other software to ever install to their libdir or includedir.

Copy link
Contributor

Choose a reason for hiding this comment

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

if this would fix your case as well, i would prefer to do it simpler for now;
if we need to add the complexity of join_paths() we can add it later;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Depends on whether libiio is extensible and the extension points are the installation paths. If not, I was not able to come up with a reason #564 should fail.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh; i did not notice the other PR;
too many emails i think

include(cmake/JoinPaths.cmake)

join_paths(libdir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
Copy link
Contributor

Choose a reason for hiding this comment

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

continuing from comment 48e1606#r449998108
this is where we could do:

if(NOT IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
CMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
endif

@commodo
Copy link
Contributor

commodo commented Jul 6, 2020

thanks for the find :)

jtojnar added a commit to jtojnar/libiio that referenced this pull request Jul 6, 2020
Alternative fix for: analogdevicesinc#563

It is not generally true that `CMAKE_INSTALL_<dir>` variables are relative paths:

https://github.com/jtojnar/cmake-snips#concatenating-paths-when-building-pkg-config-files

Absolute paths will cause things like this to appear:

    includedir=${prefix}//nix/store/87zhscw1p08nqm73ls2sd82zmr1a8rni-libiio-0.21-dev/include

It would be best if the paths were relative to `${prefix}` pkg-config variable so that they could be overridden:

https://www.bassi.io/articles/2018/03/15/pkg-config-and-paths/

but since that is not easy to do in CMake, we will just use absolute paths.

libiio does not expect other project to install artefacts to its installation paths so non-overriddable paths should no do much harm.

Signed-off-by: Jan Tojnar <[email protected]>
@rgetz
Copy link
Contributor

rgetz commented Jul 7, 2020

#564 was merged instead of this - so closing.

@rgetz rgetz closed this Jul 7, 2020
@jtojnar jtojnar deleted the fix-pc branch December 10, 2023 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants