From f3cd2d3c23d5e15e78517bbf623699e9e88d914e Mon Sep 17 00:00:00 2001 From: "Ethan J. Musser" Date: Mon, 22 Dec 2025 18:25:01 -0500 Subject: [PATCH 1/2] Refactor targets to find/link `Threads::Threads` --- source/Legacy/CMakeLists.txt | 10 +++--- source/LibMultiSense/CMakeLists.txt | 10 +++--- source/Utilities/Legacy/CMakeLists.txt | 33 +++++-------------- source/Utilities/LibMultiSense/CMakeLists.txt | 31 +++++------------ 4 files changed, 27 insertions(+), 57 deletions(-) diff --git a/source/Legacy/CMakeLists.txt b/source/Legacy/CMakeLists.txt index 2a7367c1..a0bfbd3a 100644 --- a/source/Legacy/CMakeLists.txt +++ b/source/Legacy/CMakeLists.txt @@ -86,12 +86,12 @@ set_target_properties(MultiSense PROPERTIES PUBLIC_HEADER "${MULTISENSE_HEADERS} # We want to link against our child libraries. # -if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") +find_package(Threads REQUIRED) +target_link_libraries(MultiSense Threads::Threads) +if(CMAKE_SYSTEM_NAME STREQUAL "Windows" OR CMAKE_SYSTEM_NAME STREQUAL "WindowsStore") target_link_libraries(MultiSense ws2_32) -elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - target_link_libraries(MultiSense pthread) -else() - target_link_libraries(MultiSense pthread rt) +elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") + target_link_libraries(MultiSense rt) endif() include(CMakePackageConfigHelpers) diff --git a/source/LibMultiSense/CMakeLists.txt b/source/LibMultiSense/CMakeLists.txt index 52d93345..17a2e3f6 100644 --- a/source/LibMultiSense/CMakeLists.txt +++ b/source/LibMultiSense/CMakeLists.txt @@ -63,12 +63,12 @@ set_target_properties(MultiSense PROPERTIES PUBLIC_HEADER "${MULTISENSE_HEADERS} # We want to link against our child libraries. # -if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") +find_package(Threads REQUIRED) +target_link_libraries(MultiSense Threads::Threads) +if(CMAKE_SYSTEM_NAME STREQUAL "Windows" OR CMAKE_SYSTEM_NAME STREQUAL "WindowsStore") target_link_libraries(MultiSense ws2_32) -elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - target_link_libraries(MultiSense pthread) -else() - target_link_libraries(MultiSense pthread rt) +elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") + target_link_libraries(MultiSense rt) endif() if (BUILD_TESTS) diff --git a/source/Utilities/Legacy/CMakeLists.txt b/source/Utilities/Legacy/CMakeLists.txt index 21c747d6..8ff29b02 100644 --- a/source/Utilities/Legacy/CMakeLists.txt +++ b/source/Utilities/Legacy/CMakeLists.txt @@ -8,32 +8,17 @@ include_directories(shared) # Common libraries that each utility needs to link with. # -if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") - -set (MULTISENSE_UTILITY_LIBS - ${MULTISENSE_UTILITY_LIBS} - MultiSense - ws2_32 -) - -elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - -set (MULTISENSE_UTILITY_LIBS - ${MULTISENSE_UTILITY_LIBS} - MultiSense - pthread -) - -else () - -set (MULTISENSE_UTILITY_LIBS - ${MULTISENSE_UTILITY_LIBS} - MultiSense - pthread - rt +find_package(Threads REQUIRED) +list(APPEND MULTISENSE_UTILITY_LIBS + MultiSense + Threads::Threads ) -endif () +if(CMAKE_SYSTEM_NAME STREQUAL "Windows" OR CMAKE_SYSTEM_NAME STREQUAL "WindowsStore") + list(APPEND MULTISENSE_UTILITY_LIBS ws2_32) +elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") + list(APPEND MULTISENSE_UTILITY_LIBS rt) +endif() # # Recurse into each of these directories. diff --git a/source/Utilities/LibMultiSense/CMakeLists.txt b/source/Utilities/LibMultiSense/CMakeLists.txt index 405eaf0d..d3ec3885 100644 --- a/source/Utilities/LibMultiSense/CMakeLists.txt +++ b/source/Utilities/LibMultiSense/CMakeLists.txt @@ -1,30 +1,15 @@ -if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") - -set (MULTISENSE_UTILITY_LIBS - ${MULTISENSE_UTILITY_LIBS} - MultiSense - ws2_32 -) - -elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - -set (MULTISENSE_UTILITY_LIBS - ${MULTISENSE_UTILITY_LIBS} - MultiSense - pthread -) - -else () - -set (MULTISENSE_UTILITY_LIBS - ${MULTISENSE_UTILITY_LIBS} +find_package(Threads REQUIRED) +list(APPEND MULTISENSE_UTILITY_LIBS MultiSense - pthread - rt + Threads::Threads ) -endif () +if(CMAKE_SYSTEM_NAME STREQUAL "Windows" OR CMAKE_SYSTEM_NAME STREQUAL "WindowsStore") + list(APPEND MULTISENSE_UTILITY_LIBS ws2_32) +elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") + list(APPEND MULTISENSE_UTILITY_LIBS rt) +endif() add_subdirectory(ChangeIpUtility) add_subdirectory(DeviceInfoUtility) From bbc0300b2b169555df2fb3cc2534e5154b3357ec Mon Sep 17 00:00:00 2001 From: "Ethan J. Musser" Date: Mon, 22 Dec 2025 18:26:41 -0500 Subject: [PATCH 2/2] Find `Threads` public API dependency --- source/LibMultiSense/MultiSenseConfig.cmake.in | 1 + 1 file changed, 1 insertion(+) diff --git a/source/LibMultiSense/MultiSenseConfig.cmake.in b/source/LibMultiSense/MultiSenseConfig.cmake.in index dbc311d5..fff2c958 100644 --- a/source/LibMultiSense/MultiSenseConfig.cmake.in +++ b/source/LibMultiSense/MultiSenseConfig.cmake.in @@ -5,6 +5,7 @@ find_dependency(MultiSenseWire) if (@BUILD_JSON_SERIALIZATION@) find_dependency(nlohmann_json 3.9 REQUIRED) endif () +find_dependency(Threads) include("${CMAKE_CURRENT_LIST_DIR}/MultiSenseTargets.cmake")