8000 CMake: build either static or shared + don't force PIC + add ALIAS targets by SpaceIm · Pull Request #951 · redis/hiredis · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

CMake: build either static or shared + don't force PIC + add ALIAS targets #951

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

Closed
wants to merge 10 commits into from

Conversation

SpaceIm
Copy link
Contributor
@SpaceIm SpaceIm commented May 3, 2021

This PR tries to improve CMakeLists.txt:

  • still allow static introduced in Add static library target and cpack support #851 (/cc @masariello), but don't build both. CMake has BUILD_SHARED_LIBS to control SHARED or STATIC, it's good practice to use this instead of building both flavors in the same build:
    • less tedious for downstream projects (static & shared have the same CMake imported target, it avoids to contaminate downstream build files with target name tests)
    • reduce build time, because most downstream don't want both shared & static
    • finally Makefile & CMakeLists.txt were not consistent
    • package managers: conan & vcpkg don't like CMakeLists building both shared & static.
  • optional PIC for static libs (since Enable position-independent code, and add PDB files to packages for MSVC builds #874 PIC was forced unconditionally), PIC is needed on Unix platform only if you link hiredis into a shared lib
  • add ALIAS targets so that downstream projects can consume namespaced targets with find_package or add_subdirectory in a consistent way.
  • link to OpenSSL::SSL imported target, it's far more robust. This imported target is available since CMake 3.4 in built-in FindOpenSSL.cmake module, and fortunatly it's the min CMake version in hiredis.

I did not remove it, but this file -commited in #851 - seems to be useless (some generated file by Visual Studio?): https://github.com/redis/hiredis/blob/master/hiredis.targets

@SpaceIm SpaceIm force-pushed the cmake-static-or-shared branch from 3789e29 to 9c35d3a Compare May 3, 2021 11:05
@michael-grunder
Copy link
Collaborator

Thanks for the PR, the updated CMakeLists.txt is much cleaner.

I'm not very familiar with CMake, but is this change likely to cause pain for anyone if we were to release it in v1.0.1?

-ADD_LIBRARY(hiredis_static STATIC ${hiredis_sources})
+ADD_LIBRARY(hiredis::hiredis ALIAS hiredis

@SpaceIm
Copy link
Contributor Author
SpaceIm commented May 3, 2021

Since commits in #851 don't land in any release for the moment, I guess that this change is harmless. It could eventually break people who were using master branch.

@michael-grunder
Copy link
Collaborator

Since commits in #851 don't land in any release for the moment

For some reason, I thought #851 was in v1.0.0.

I'll give it a quick test and then get it merged today.

Thanks again!

@SpaceIm
Copy link
Contributor Author
SpaceIm commented May 3, 2021

I forgot: do be consistent with 1.0.0, BUILD_SHARED_LIBS could be turned to an option set to ON by default.

For some reason, I thought #851 was in v1.0.0.

I remember when I've packaged hiredis 1.0.0 for conan, and I'm pretty sure that there was only hardcoded shared libs (and I had to patch CMakeLists to allow static).

@masariello
Copy link
Contributor

This file is used by cpack when building a nuget package.

https://github.com/redis/hiredis/blob/master/hiredis.targets

Will the shared and static packages have different IDs?

prince-chrismc
prince-chrismc previously approved these changes May 3, 2021
@clemensg
Copy link
clemensg commented Feb 8, 2022

Hi @SpaceIm , any chance of getting this rebased on current master? Thanks

@SpaceIm
Copy link
Contributor Author
SpaceIm commented Feb 8, 2022

This file is used by cpack when building a nuget package.

https://github.com/redis/hiredis/blob/master/hiredis.targets

Will the shared and static packages have different IDs?

I don't know nuget, I guess they manage this detail themself.

8000
@autoantwort
Copy link
Contributor

Hi @SpaceIm , any chance of getting this rebased on current master? Thanks

I have created #1160 for that.

@chayim
Copy link
Contributor
chayim commented Jul 5, 2023

Closing based on Jan 28 comment since this is in.

@chayim chayim closed this Jul 5, 2023
@SpaceIm SpaceIm deleted the cmake-static-or-shared branch July 5, 2023 17:02
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.

7 participants
0