From f174c7881de0f80b33fa9d305da18076470862bd Mon Sep 17 00:00:00 2001 From: Stella Laurenzo Date: Mon, 3 Feb 2025 20:28:58 -0800 Subject: [PATCH] Update find_package for msgpack to work with 5.x and 6.x. 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. --- tensilelite/Tensile/Source/lib/CMakeLists.txt | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/tensilelite/Tensile/Source/lib/CMakeLists.txt b/tensilelite/Tensile/Source/lib/CMakeLists.txt index d055b635d7..a8a9869002 100644 --- a/tensilelite/Tensile/Source/lib/CMakeLists.txt +++ b/tensilelite/Tensile/Source/lib/CMakeLists.txt @@ -96,22 +96,20 @@ 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 - target_include_directories(TensileHost - SYSTEM PRIVATE $ - ) + # 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 + message(STATUS "Found msgpack-cxx (>=6.x)") + target_link_libraries(TensileHost PUBLIC msgpack-cxx) + else() + # Fallback to <= 5.x + find_package(msgpackc-cxx CONFIG REQUIRED NAMES msgpackc-cxx msgpack) + message(STATUS "Found msgpack (<=5.x)") + target_link_libraries(TensileHost PUBLIC msgpackc) endif() + target_compile_definitions(TensileHost PUBLIC -DTENSILE_MSGPACK=1) endif() if(TENSILE_USE_LLVM)