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

Switch to GNUInstallDirs [v2] #1424

Merged
merged 14 commits into from
Aug 7, 2022
Merged

Conversation

laumann
Copy link
Contributor

@laumann laumann commented May 24, 2022

Rebase of #1165 on the current master, plus an attempt at moving docs $DATAROOTDIR/doc/{OPENJPEG -> openjpeg}. I considered alternatively to mangle CMAKE_INSTALL_DOCDIR directly, but I think that could cause other problems.

a17r and others added 13 commits May 24, 2022 19:42
Distributions are given standard variables for already existing hooks.
Multiarch libdirs is taken care of automagically.
Raises minimum cmake version by a little.
CMAKE_INSTALL_FULL_LIBDIR contains absolute path with CMAKE_INSTALL_PREFIX
CMAKE_INSTALL_FULL_INCLUDEDIR contains absolute path with CMAKE_INSTALL_PREFIX
This changes the default doc installdir to DATAROOTDIR/doc/PROJECT_NAME
Should be ported to CMakePackageConfigHelpers in the future,
but this will do for now.
These files are not typically installed by the build system. Instead,
distributions may or may not manually add them to their packaging (wrt
standard licenses, it makes no sense to duplicate them all over the FS).

CHANGES has not existed since 2012.
As PROJECT_NAME = OPENJPEG the generated value for CMAKE_INSTALL_DOCDIR
becomes $DATAROOTDIR/doc/OPENJPEG. Fix by lowercasing PROJECT_NAME
immediately before including GNUInstallDirs.
@laumann
Copy link
Contributor Author

laumann commented May 24, 2022

cc @a17r @thesamesam

@laumann laumann changed the title [v2] Switch to GNUInstallDirs Switch to GNUInstallDirs [v2] May 24, 2022
@laumann
Copy link
Contributor Author

laumann commented Jul 3, 2022

@rouault ping, just to follow up on this, are you interested in this change?

@rouault
Copy link
Collaborator

rouault commented Jul 3, 2022

just to follow up on this, are you interested in this change?

yes, but there are likely subtelies. In other projects where I'm involved with, it has been raised that sometimes CMAKE_INSTALL_{foo} is an absolute directory and not a relative directory (cf OSGeo/gdal#6004 or OSGeo/PROJ#3206), so I suspect that in your pull request CMAKE_INSTALL_FULL_{foo} should be used, at least for .pc file generation

@laumann
Copy link
Contributor Author

laumann commented Jul 3, 2022

just to follow up on this, are you interested in this change?

yes, but there are likely subtelies. In other projects where I'm involved with, it has been raised that sometimes CMAKE_INSTALL_{foo} is an absolute directory and not a relative directory (cf OSGeo/gdal#6004 or OSGeo/PROJ#3206), so I suspect that in your pull request CMAKE_INSTALL_FULL_{foo} should be used, at least for .pc file generation

Sure, I'll look into it - it would make sense, in Gentoo's patching to use GNUInstallDirs the values for mandir and docdir omit the ${prefix} as they already have the prefix. See: https://gitweb.gentoo.org/repo/gentoo.git/tree/media-libs/openjpeg/files/openjpeg-2.5.0-gnuinstalldirs.patch#n287

Would you prefer that ${prefix} is removed from all the generated .pc entries? Ie, drop ${prefix} and use the CMAKE_INSTALL_FULL_{foo} variants?

@rouault
Copy link
Collaborator

rouault commented Jul 3, 2022

Ie, drop ${prefix} and use the CMAKE_INSTALL_FULL_{foo} variants?

yes, my understanding is that it is the correct way

@laumann
Copy link
Contributor Author

laumann commented Jul 3, 2022

Ie, drop ${prefix} and use the CMAKE_INSTALL_FULL_{foo} variants?

yes, my understanding is that it is the correct way

OK, thanks for pointing it out. I'll make those changes (tomorrow probably, getting late here).

@rouault
Copy link
Collaborator

rouault commented Jul 5, 2022

OK, thanks for pointing it out.

actually taking inspiration from OSGeo/PROJ@ab25e4b which tests if CMAKE_INSTALL_{foo} is relative or not might better. The idea is to still use ${prefix}/${CMAKE_INSTALL_{foo}} when it is relative, so that packages can be relocated

@laumann
Copy link
Contributor Author

laumann commented Jul 8, 2022

actually taking inspiration from OSGeo/PROJ@ab25e4b which tests if CMAKE_INSTALL_{foo} is relative or not might better. The idea is to still use

Thanks @rouault - this is primarily for .pc file generation, right?

@laumann
Copy link
Contributor Author

laumann commented Jul 8, 2022

The reason I ask is that I'm considering one of two approaches:

  • Set variables like ${libdir}, ${includedir}, etc and replace all occurrences of ${CMAKE_INSTALL_LIBDIR} with ${libdir}, etc.
  • Focus on .pc file generation working correctly, where it takes into account whether or not CMAKE_INSTALL_LIBDIR (and others) are relative or full paths

I'm leaning towards the latter approach as it's less work. But I'd like to know which you prefer.

@rouault
Copy link
Collaborator

rouault commented Jul 8, 2022

But I'd like to know which you prefer.

I'm not completely sure to have understood your first option. But IMHO ${libdir} shouldn't be used outside of .pc generation. ${CMAKE_INSTALL_LIBDIR} is idiomatic in all other places such as install() CMake function.
So your second point is more what I've in mind

@laumann
Copy link
Contributor Author

laumann commented Jul 8, 2022

So your second point is more what I've in mind

Excellent, thanks! I'll go with that then.

In some cases the CMAKE_INSTAL_{BIN,MAN,DOC,LIB,INCLUDE}DIR variables
may turn out to be absolute paths in which case prepending ${prefix} in
the pkg-config .pc files will result in incorrect values.

For .pc file generation, figure out if these variables are absolute and
omit the prefix in the configured file when so.

See: OSGeo/PROJ@ab25e4b
@laumann
Copy link
Contributor Author

laumann commented Jul 15, 2022

@rouault Sorry for taking a while to get back to this, I've implemented it now, let me know what you think. I had to use \\\${prefix} instead of $\{prefix\} not exactly sure why. I got an invalid escape sequence \{ error with the latter format.

@laumann
Copy link
Contributor Author

laumann commented Aug 6, 2022

@rouault Gentle ping on this, I think I've implemented what you requested.

@rouault rouault mentioned this pull request Aug 7, 2022
@rouault rouault merged commit c7bccf0 into uclouvain:master Aug 7, 2022
@rouault
Copy link
Collaborator

rouault commented Aug 7, 2022

merged. thanks!

@laumann
Copy link
Contributor Author

laumann commented Aug 7, 2022

Yay! Thank you!

@laumann laumann deleted the gnuinstalldirs branch August 7, 2022 19:04
@arichardson
Copy link
Contributor

This broke cross-compilation of downstream projects (poppler) for me, I've submitted #1439 to fix this.

@SoapGentoo
Copy link

How does this break cross-compilation?

@arichardson
Copy link
Contributor

How does this break cross-compilation?

I am installing using CMAKE_INSTALL_PREFIX=/usr/local and DESTDIR=/path/to/my/sysroot. Without the relocatable change, downstream projects will add -I/usr/local instead of -I/path/to/my/sysroot/usr/local and will not find the headers.

@SoapGentoo
Copy link

That is correct, which is why cross-compilation generally expects CMAKE_FIND_ROOT_PATH or CMAKE_SYSROOT. We use the former in Gentoo, and it works just fine. Said differently, if all cmake-based projects used garden path GNUInstallDirs as intended, none of them could be cross-compiled, which sounds counter-intuitive to what it tries to achieve?

@arichardson
Copy link
Contributor

That is correct, which is why cross-compilation generally expects CMAKE_FIND_ROOT_PATH or CMAKE_SYSROOT. We use the former in Gentoo, and it works just fine. Said differently, if all cmake-based projects used garden path GNUInstallDirs as intended, none of them could be cross-compiled, which sounds counter-intuitive to what it tries to achieve?

Yes, I set all of those, and that works fine for almost all projects (the ones that don't include those paths in the Config.cmake file, and instead use configure_package_config_file with PATH_VARS) or just link against the CMake targets instead of relying on FOO_INCS/FOO_LIBS (i.e. modern CMake).

@SoapGentoo
Copy link

wouldn't it then make more sense to move to modern CMake where the user has to use target_link_libraries to pull in the correct target?

@autoantwort
Copy link
Contributor

This did not replace all usages of OPENJPEG_INSTALL_INCLUDE_DIR and breaks the generated cmake config files.

target_include_directories(${OPENJPEG_LIBRARY_NAME} PUBLIC $<INSTALL_INTERFACE:${OPENJPEG_INSTALL_INCLUDE_DIR}>)

@thesamesam
Copy link

Please file a new bug then.

autoantwort added a commit to autoantwort/openjpeg that referenced this pull request Feb 6, 2023
Comment on lines -130 to -132
if(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
set(OPENJPEG_INSTALL_INCLUDE_DIR "include/${OPENJPEG_INSTALL_SUBDIR}")
endif()
Copy link
Contributor

Choose a reason for hiding this comment

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

This change removes the ability to customize the include dir location in v2.5.1. This affects the vcpkg port. (I wouldn't care, but I learned that Visual Studio users feel less comfortable with versioned include paths if not using cmake.)

Choose a reason for hiding this comment

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

why? just pass -DCMAKE_INSTALL_INCLUDEDIR=foo to cmake?

Copy link
Contributor

@dg0yt dg0yt Feb 27, 2024

Choose a reason for hiding this comment

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

This would change the prefix (include -> foo) but not the suffix (OPENJPEG_INSTALL_SUBDIR) because it hardcoded everywhere.

For the vcpkg port I decided to not add a patch (i.e. openjpeg decides), but write two forwarding headers into vcpkg's old location, marked as "legacy".
So probably no further change needed here - but a breaking change nevertheless.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@dg0yt If you want to contribute a pull request to fix that, that's a good moment to do because I'll likely have to issue a 2.5.2 because of #1514 (comment)

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.

8 participants