Skip to content

Detect msgpack-cxx <= 6.0.0 with cmake #1079

Closed

Description

@aberaud

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

Activity

  1. uyha commented on Jul 6, 2023

    @uyha

    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.

  2. aberaud commented on Jul 8, 2023

    @aberaud
    ContributorAuthor

    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.

  3. changed the title [-]Detect msgpack-cxx with cmake[/-] [+]Detect msgpack-cxx <= 6.0.0 with cmake[/+] on Jul 8, 2023
  4. uyha commented on Jul 8, 2023

    @uyha

    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.

  5. uyha commented on Jul 8, 2023

    @uyha

    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()
  6. aberaud commented on Jul 8, 2023

    @aberaud
    ContributorAuthor

    Many thanks :)

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

  7. uyha commented on Jul 8, 2023

    @uyha

    I’ll create a PR when i have time

  8. aberaud commented on Jul 12, 2023

    @aberaud
    ContributorAuthor

    @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 ?

  9. uyha commented on Jul 12, 2023

    @uyha

    looks fine for me

  10. aberaud commented on Jul 13, 2023

    @aberaud
    ContributorAuthor

    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()
  11. redboltz commented on Jul 13, 2023

    @redboltz
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions