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

Detect msgpack-cxx <= 6.0.0 with cmake #1079

Closed
aberaud opened this issue Jul 5, 2023 · 10 comments
Closed

Detect msgpack-cxx <= 6.0.0 with cmake #1079

aberaud opened this issue Jul 5, 2023 · 10 comments

Comments

@aberaud
Copy link
Contributor

aberaud commented Jul 5, 2023

Hi,
What is the recommended way to detect and use msgpack-cxx with CMake that would work with msgpack 6.0.0 and also be backward-compatible with older versions ?

Many thanks

@uyha
Copy link

uyha commented Jul 6, 2023

that depends on how you install msgpack-cxx, if you clone this project and use cmake to install it, then using find_package should work, similarly for Conan.

@aberaud
Copy link
Contributor Author

aberaud commented Jul 8, 2023

Thanks.

I currently use:

find_package(msgpack REQUIRED NAMES msgpack msgpack-cxx)
target_link_libraries(mylib PUBLIC msgpack-cxx)

However this only works with the latest version 6.0.0.

What's the recommended way to include and link msgpack that would be backward compatible with older msgpack versions ? Thanks.

@aberaud aberaud changed the title Detect msgpack-cxx with cmake Detect msgpack-cxx <= 6.0.0 with cmake Jul 8, 2023
@uyha
Copy link

uyha commented Jul 8, 2023

the problem is this library makes a breaking change in version v6.0.0, so for versions earlier than that, you’ll have to use msgpackc-cxx. In you CMake script, you can do something like

if(MSGPACK_VERSION VERSION_LESS 6.0.0)
  find_package(msgpack REQUIRED NAMES msgpackc msgpackc-cxx)
  add_library(msgpack-cxx ALIAS msgpackc-cxx)
else()
  find_package(msgpack REQUIRED NAMES msgpack msgpack-cxx)
endif()

Then you can link your targets with msgpack-cxx regardless of the version.

@uyha
Copy link

uyha commented Jul 8, 2023

or if you just want to detect the whether the library is installed and use it, the following snippet may be useful.

find_package(msgpackc-cxx)
if(msgpackc-cxx_FOUND)
  add_library(msgpack-cxx ALIAS msgpackc-cxx)
else()
  find_package(msgpack-cxx REQUIRED)
endif()

@aberaud
Copy link
Contributor Author

aberaud commented Jul 8, 2023

Many thanks :)

Maybe this should be documented in the README because older versions will be around for a while.

@aberaud aberaud closed this as completed Jul 8, 2023
@uyha
Copy link

uyha commented Jul 8, 2023

I’ll create a PR when i have time

@aberaud
Copy link
Contributor Author

aberaud commented Jul 12, 2023

@uyha It seems that older versions of msgpack-c++ (like version 3.0 in Ubuntu 20.04 and version 3.3 in Ubuntu 22.04) use 'msgpack' instead of 'msgpack-cxx' or 'msgpackc-cxx' ?

So there would be a need for a 3-level checks ?

Something like:

find_package(msgpackc-cxx QUIET CONFIG)
if(msgpackc-cxx_FOUND)
  add_library(msgpack-cxx ALIAS msgpackc-cxx)
else()
  find_package(msgpack-cxx CONFIG)
  if(NOT msgpack-cxx_FOUND)
    find_package(msgpack CONFIG REQUIRED)
    add_library(msgpack-cxx ALIAS msgpack)
  endif()
endif()

Does this makes sense ?

@aberaud aberaud reopened this Jul 12, 2023
@uyha
Copy link

uyha commented Jul 12, 2023

looks fine for me

@aberaud
Copy link
Contributor Author

aberaud commented Jul 13, 2023

We ended up using:

find_package(msgpackc-cxx QUIET CONFIG NAMES msgpackc-cxx msgpack)
if(msgpackc-cxx_FOUND)
  add_library(msgpack-cxx ALIAS msgpackc-cxx)
else()
  find_package(msgpack-cxx CONFIG REQUIRED)
endif()

@aberaud aberaud closed this as completed Jul 13, 2023
@redboltz
Copy link
Contributor

I added the document about that in Wiki.
https://github.com/msgpack/msgpack-c/wiki/Q%26A#how-to-support-both-msgpack-c-c-version-5x-and-6x-

User can find the information using search box like this:
https://github.com/search?q=repo%3Amsgpack%2Fmsgpack-c+cmake&type=wikis

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

No branches or pull requests

3 participants