Skip to content

Commit

Permalink
Update find_package for msgpack to work with 5.x and 6.x.
Browse files Browse the repository at this point in the history
Adapted from: https://github.com/msgpack/msgpack-c/wiki/Q%26A#how-to-support-both-msgpack-c-c-version-5x-and-6x-

Note that 6.x also defines compile definitions that must be respected.
  • Loading branch information
stellaraccident committed Feb 4, 2025
1 parent 67df503 commit 9f8003a
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions tensilelite/Tensile/Source/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,31 @@ if(TENSILE_USE_LLVM OR TENSILE_USE_MSGPACK)
endif()

if(TENSILE_USE_MSGPACK)
find_package(msgpack REQUIRED)
target_compile_definitions(TensileHost PUBLIC -DTENSILE_MSGPACK=1)

if(TARGET msgpackc-cxx)
get_target_property(msgpack_inc msgpackc-cxx INTERFACE_INCLUDE_DIRECTORIES)
elseif(TARGET msgpackc)
get_target_property(msgpack_inc msgpackc INTERFACE_INCLUDE_DIRECTORIES)
endif()

if(DEFINED msgpack_inc)
# include C++ headers manually
# External header includes included as system files
# See: https://github.com/msgpack/msgpack-c/wiki/Q%26A#how-to-support-both-msgpack-c-c-version-5x-and-6x-
# Prefer 6.x (msgpack-cxx) as that is what we bundle in the build.
find_package(msgpack-cxx CONFIG)
if(msgpack-cxx_FOUND)
# Version 6.x
get_target_property(msgpack_inc msgpack-cxx INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(msgpack_defs msgpack-cxx INTERFACE_COMPILE_DEFINITIONS)
target_include_directories(TensileHost
SYSTEM PRIVATE $<BUILD_INTERFACE:${msgpack_inc}>
)
target_compile_definitions(TensileHost PRIVATE $<BUILD_INTERFACE:${msgpack_defs}>)
message(STATUS "Found msgpack-cxx (>=6.x): ${msgpack_inc} ${msgpack_defs}")
else()
# Fallback to <= 5.x
find_package(msgpackc-cxx CONFIG REQUIRED NAMES msgpackc-cxx msgpack)
get_target_property(msgpack_inc msgpackc INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(msgpack_defs msgpackc INTERFACE_COMPILE_DEFINITIONS)
message(STATUS "Found msgpack (<=5.x): ${msgpack_inc} ${msgpack_defs}")
endif()
target_include_directories(TensileHost
SYSTEM PRIVATE $<BUILD_INTERFACE:${msgpack_inc}>
)
target_compile_definitions(TensileHost PRIVATE $<BUILD_INTERFACE:${msgpack_defs}>)

target_compile_definitions(TensileHost PUBLIC -DTENSILE_MSGPACK=1)
endif()

if(TENSILE_USE_LLVM)
Expand Down

0 comments on commit 9f8003a

Please sign in to comment.