From cb314f3a2755f43716ecd7c7125c8a8cc5cd4040 Mon Sep 17 00:00:00 2001 From: Adrian Del Grosso <10929341+ad3154@users.noreply.github.com> Date: Fri, 8 Mar 2024 18:06:20 -0700 Subject: [PATCH] [CMAKE]: When threading is disabled, don't attempt to find threads Also, add option in CMake for disabling threading. --- CMakeLists.txt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 049fedb7f..97f6c4a8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,11 +25,17 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() -# Find packages required for Socket CAN -set(THREADS_PREFER_PTHREAD_FLAG ON) -# ESP-IDF doesn't implement find_package(Threads) correctly (dec 2022) -if(NOT ESP_PLATFORM) - find_package(Threads REQUIRED) +option( + CAN_STACK_DISABLE_THREADS + "Set to ON to disable multi-threading, which removes the need for std::thread, std::mutex, and related libraries." + OFF) +if(NOT CAN_STACK_DISABLE_THREADS AND NOT ARDUINO) + # Find packages required for Threading + set(THREADS_PREFER_PTHREAD_FLAG ON) + # ESP-IDF doesn't implement find_package(Threads) correctly (dec 2022) + if(NOT ESP_PLATFORM) + find_package(Threads REQUIRED) + endif() endif() # A handy function to prepend text to all elements in a list (useful for