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

Minor cmake fixes #385

Merged
merged 13 commits into from
Jan 25, 2024
Merged

Minor cmake fixes #385

merged 13 commits into from
Jan 25, 2024

Conversation

lgbaldoni
Copy link
Contributor

No description provided.

CMakeLists.txt Outdated
@@ -173,7 +173,7 @@ if (USE_CRYPTO)
endif ()

if(KVZ_BUILD_SHARED_LIBS)
list( APPEND CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib" "./" "../lib" )
list( APPEND CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" "./" "../lib" )
Copy link

@kmilos kmilos Jan 19, 2024

Choose a reason for hiding this comment

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

Are there any cases where GNUInstallDirs is broken?

See https://gitlab.kitware.com/cmake/cmake/-/issues/18640 which suggests $LIB_SUFFIX is maybe not the best way to go...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kmilos you're completely right and I don't know how I could forget about it.

CMakeLists.txt Outdated
@@ -173,7 +173,7 @@ if (USE_CRYPTO)
endif ()

if(KVZ_BUILD_SHARED_LIBS)
list( APPEND CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib" "./" "../lib" )
list( APPEND CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" "./" "../lib" )
Copy link

Choose a reason for hiding this comment

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

Great, but CMAKE_INSTALL_LIBDIR can be an absolute path on some platforms like NixOS... Perhaps just use ${CMAKE_INSTALL_FULL_LIBDIR} instead of ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}?

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 remember that problem on openSUSE, years ago. I thought it had been solved. Not everywhere, it comes out.

libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
Copy link

@kmilos kmilos Jan 19, 2024

Choose a reason for hiding this comment

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

Ah, here you actually don't want an absolute path always in order to enable a relocatable package...

Instead, one has to check if CMAKE_INSTALL_LIBDIR was absolute and act accordingly. See for example lensfun/lensfun@542b989

Copy link

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Considering that the kvazaarCMake.pc.in is based on the one that is used by uvg266, we are going to be maintaining two templates regardless, unless automake can also use the CMake version. Additionally, the template has been updated literally once, nine years ago, it is not really an issue to have two templates, even if it is not an optimal solution.

If you are adamant on us not having two templates on this repository I will accept a PR, but please submit a similar PR for uvg266 also.

Copy link

Choose a reason for hiding this comment

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

If you are adamant on us not having two templates on this repository

I'm not. Just sharing what has become sort of "best practice" I've experienced across several imaging related libraries, especially ones that are (or were) supporting both autotools and cmake, like libtiff and libheif for example. I see no reason not to reuse it...

It's of course your prerogative how you want to maintain your repositories, and apologies to have annoyed you with my comments.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I understand why having two templates cannot be considered a best practice. However, considering the low maintenance needed for these files, and the fact that we aim not to support both autotools and cmake, but replace autotools with cmake, I'm fine with not following best practices here.

For your other suggestions I'm grateful, as I have very little experience with CMake.

apologies to have annoyed you with my comments.

I interpreted your usage of ellipsis as a criticism towards the fact that I was not aware of the best practices, which I assume was not the intention? I would like to apologize for my maybe overly harsh comments towards you.

Otherwise, in your opinion, does the current state of the PR adhere to the best practices?

Copy link

Choose a reason for hiding this comment

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

No problem. There's just two more minor details, I'll leave comments on the latest commits.

CMakeLists.txt Outdated
if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
set(KVAZAAR_PC_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
else()
set(KVAZAAR_PC_LIBDIR "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
Copy link

Choose a reason for hiding this comment

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

Suggested change
set(KVAZAAR_PC_LIBDIR "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
set(KVAZAAR_PC_LIBDIR "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")

Copy link

Choose a reason for hiding this comment

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

Will also need to add and handle KVAZAAR_PC_INCDIR, but that one indeed w/ \${prefix}

@@ -1,6 +1,6 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/lib
libdir=@KVAZAAR_PC_LIBDIR@
incdir=${prefix}/include
Copy link

Choose a reason for hiding this comment

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

Add @KVAZAAR_PC_INCDIR@

CMakeLists.txt Outdated
if(KVZ_BUILD_SHARED_LIBS) # Just add the lib to the bin directory for now
if(MSVC)
install(TARGETS kvazaar DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
endif()
endif()
install(FILES ${PROJECT_SOURCE_DIR}/src/kvazaar.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
install(FILES ${PROJECT_SOURCE_DIR}/doc/kvazaar.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man)
install(FILES ${PROJECT_SOURCE_DIR}/doc/kvazaar.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1)
Copy link

Choose a reason for hiding this comment

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

Suggested change
install(FILES ${PROJECT_SOURCE_DIR}/doc/kvazaar.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1)
install(FILES ${PROJECT_SOURCE_DIR}/doc/kvazaar.1 DESTINATION ${CMAKE_INSTALL_MANDIR})

CMakeLists.txt Outdated
install(TARGETS kvazaar-bin DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
install(TARGETS kvazaar DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
install(TARGETS kvazaar DESTINATION ${CMAKE_INSTALL_LIBDIR})
if(KVZ_BUILD_SHARED_LIBS) # Just add the lib to the bin directory for now
if(MSVC)
install(TARGETS kvazaar DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
endif()
endif()
install(FILES ${PROJECT_SOURCE_DIR}/src/kvazaar.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
Copy link

Choose a reason for hiding this comment

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

Use CMAKE_INSTALL_INCLUDEDIR

CMakeLists.txt Outdated
@@ -281,16 +289,16 @@ source_group( "" FILES ${SOURCE_GROUP_TOPLEVEL})

# ToDo: make configurable

install(FILES ${PROJECT_SOURCE_DIR}/src/kvazaar.pc DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pkgconfig)
install(FILES ${PROJECT_SOURCE_DIR}/src/kvazaar.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(TARGETS kvazaar-bin DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
Copy link

Choose a reason for hiding this comment

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

Use CMAKE_INSTALL_BINDIR

CMakeLists.txt Outdated
install(TARGETS kvazaar-bin DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
install(TARGETS kvazaar DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
install(TARGETS kvazaar DESTINATION ${CMAKE_INSTALL_LIBDIR})
if(KVZ_BUILD_SHARED_LIBS) # Just add the lib to the bin directory for now
if(MSVC)
Copy link

Choose a reason for hiding this comment

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

Why is this MSVC only? One can build shared libs on MINGW as well, so this should potentially be WIN32?

Also, maybe there is no need to special case this anyway? If you do

install(TARGETS kvazaar
  RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}

this will work out for shared and static libraries for all platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, maybe there is no need to special case this anyway? If you do

RUNTIME is not being installed that way. Do I need to define it somewhere first?

else()
set(KVAZAAR_PC_LIBDIR "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
set(KVAZAAR_PC_LIBDIR "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
set(KVAZAAR_PC_INCDIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
Copy link

Choose a reason for hiding this comment

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

Suggested change
set(KVAZAAR_PC_INCDIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
endif()
if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
set(KVAZAAR_PC_INCDIR "${CMAKE_INSTALL_INCLUDEDIR}")
else()
set(KVAZAAR_PC_INCDIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Silly me. Although it would have worked most of the time:)

Copy link

Choose a reason for hiding this comment

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

Probably, but there is no guarantee I guess!

CMakeLists.txt Outdated
@@ -101,8 +101,10 @@ add_definitions(-DCMAKE_BUILD)
# Set correct pkgconfig libdir variable
if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
set(KVAZAAR_PC_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
set(KVAZAAR_PC_INCDIR "${CMAKE_INSTALL_INCLUDEDIR}")
Copy link

Choose a reason for hiding this comment

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

Suggested change
set(KVAZAAR_PC_INCDIR "${CMAKE_INSTALL_INCLUDEDIR}")

CMakeLists.txt Outdated
install(TARGETS kvazaar
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Copy link

Choose a reason for hiding this comment

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

Why leave this out? RUNTIME DESTINATION covers the .dll on Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ouch, misunderstood.

Copy link

Choose a reason for hiding this comment

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

Yep, it's not just for the binary/.exe

@kmilos
Copy link

kmilos commented Jan 22, 2024

I think it looks ok now 👍

Should still get tested on as many different platforms (and configs) as possible before releasing though...

@lgbaldoni
Copy link
Contributor Author

Should still get tested on as many different platforms (and configs) as possible before releasing though...

That would require setting up docker/appveyor accounts...

@kmilos
Copy link

kmilos commented Jan 22, 2024

That would require setting up docker/appveyor accounts...

You can cover at least Linux, macOS and Windows (both MSVC and MinGW) w/ readily available GitHub Actions.

@Jovasa
Copy link
Member

Jovasa commented Jan 25, 2024

I tested on Manjaro, Ubuntu, MSVC, and MinGW, and as far I can tell, everything seems to be working as it should be.

Big thanks to you both!

@Jovasa Jovasa merged commit bb89833 into ultravideo:master Jan 25, 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
Development

Successfully merging this pull request may close these issues.

3 participants