Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
*.app

# Cmake
*.cmake
Makefile
*.dir
*.marks
Expand Down
17 changes: 12 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ project(

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(CheckIncludeFileCXX)
include(cmake/CheckHasStdThreads.cmake)

# Make CTest available and the BUILD_TESTING option (OFF by default)
option(BUILD_TESTING "Set to ON to enable building of tests from top level" OFF)
Expand All @@ -35,12 +35,13 @@ option(
"Set to ON to disable multi-threading, which removes the need for std::thread, std::mutex, and related libraries."
OFF)

# Disable threads if the header is not available
check_include_file_cxx(thread HAS_STD_THREAD_HEADER)
if(NOT HAS_STD_THREAD_HEADER)
# Disable threads if the toolchain doesn't support them
check_std_thread_support(STD_THREAD_SUPPORTED)
if(NOT STD_THREAD_SUPPORTED)
message(
WARNING
"C++ <thread> header not found. Disabling CAN_STACK_DISABLE_THREADS.")
"C++ threading model is not supported. Setting CAN_STACK_DISABLE_THREADS to ON."
)
set(CAN_STACK_DISABLE_THREADS ON)
endif()

Expand Down Expand Up @@ -98,6 +99,12 @@ add_subdirectory("hardware_integration")

option(BUILD_EXAMPLES "Set to ON to enable building of examples from top level"
OFF)
if(BUILD_EXAMPLES AND CAN_STACK_DISABLE_THREADS)
message(
WARNING
"You are trying to build examples while the isobus library is configured in single-threaded mode, examples cannot be built in this mode. The current build configuration is (BUILD_EXAMPLES == ON AND CAN_STACK_DISABLE_THREADS == ON), please change the configuration."
)
endif()
if(BUILD_EXAMPLES)
add_subdirectory("examples/transport_layer")
add_subdirectory("examples/diagnostic_protocol")
Expand Down
15 changes: 15 additions & 0 deletions cmake/CheckHasStdThreads.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.16)

function(check_std_thread_support VARIABLE)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

file(
WRITE "${CMAKE_CURRENT_BINARY_DIR}/thread_test.cpp"
"#include <thread>\nint main() {\n std::thread t([](){});\n t.join();\n return 0;\n}"
)

try_compile(
${VARIABLE} "${CMAKE_BINARY_DIR}/thread_check_build"
SOURCES "${CMAKE_CURRENT_BINARY_DIR}/thread_test.cpp"
CMAKE_FLAGS -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=ON)
endfunction()
Loading