From 0084354ba917f712ce293e06df5d300f9094d86e Mon Sep 17 00:00:00 2001 From: Andrew Stitcher Date: Mon, 8 Jul 2024 12:36:49 -0400 Subject: [PATCH] PROTON-2810: Make standalone C++ examples build work correctly --- cpp/CMakeLists.txt | 2 +- cpp/examples/CMakeLists.txt | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 93b42424e..c65cc8723 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -33,7 +33,7 @@ enable_language(CXX) # So leave this here for a few more years! set(CMAKE_THREAD_PREFER_PTHREAD TRUE) find_package(Threads) -link_libraries(Threads::Threads) +list(APPEND PLATFORM_LIBS Threads::Threads) include(versions.cmake) diff --git a/cpp/examples/CMakeLists.txt b/cpp/examples/CMakeLists.txt index cbaefbe3c..587edfc52 100644 --- a/cpp/examples/CMakeLists.txt +++ b/cpp/examples/CMakeLists.txt @@ -25,6 +25,15 @@ find_package(ProtonCpp REQUIRED) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_EXTENSIONS OFF) +# This is not needed for modern versions of Linux using glibc 2.34 or later +# However RHEL before RHEL 9; Ubuntu before 22.04; Debian before 12 and FreeBSD +# with clang (its system compiler) all still need to link the threads library +# explicitly even though thread support is now included in C++17. +# +# So leave this here for a few more years! +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +find_package(Threads) + # Single-threaded examples foreach(example broker @@ -53,7 +62,7 @@ foreach(example multithreaded_client multithreaded_client_flow_control) add_executable(${example} ${example}.cpp) - target_link_libraries(${example} Proton::cpp) + target_link_libraries(${example} Proton::cpp Threads::Threads) endforeach() # Tracing examples