commit 1e09a9944b31e4a59202cb24aac812c9a751f7d2
parent 4e57e1f4c07500f40cb5c146b75987382884fc8d
Author: Alexandre Bique <bique.alexandre@gmail.com>
Date: Thu, 30 Nov 2023 14:37:03 +0100
Let cmake find out if threads.h is available
Diffstat:
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -50,6 +50,7 @@ add_custom_target(clap-tests)
if (${CLAP_BUILD_TESTS})
message(STATUS "Including CLAP tests, compile tests, and versions")
+ include(CheckIncludeFile)
macro(clap_compile_cpp SUFFIX EXT STDC STDCPP)
add_executable(clap-compile-${SUFFIX} EXCLUDE_FROM_ALL src/main.${EXT})
@@ -84,11 +85,17 @@ if (${CLAP_BUILD_TESTS})
clap_compile_cpp(cpp17 cc 17 17)
clap_compile_cpp(cpp20 cc 17 20)
+ check_include_file(threads.h CLAP_HAS_THREADS_H)
+
add_library(clap-plugin-template MODULE EXCLUDE_FROM_ALL src/plugin-template.c)
target_link_libraries(clap-plugin-template PRIVATE clap)
set_target_properties(clap-plugin-template PROPERTIES C_STANDARD 11)
add_dependencies(clap-tests clap-plugin-template)
+ if(CLAP_HAS_THREADS_H)
+ target_compile_definitions(clap-plugin-template PRIVATE CLAP_HAS_THREADS_H)
+ endif()
+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(clap-plugin-template PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/src/linux-my_plug.version)
target_link_libraries(clap-plugin-template PRIVATE -Wl,-z,defs)
diff --git a/src/plugin-template.c b/src/plugin-template.c
@@ -8,7 +8,7 @@
#include <stdio.h>
#include <assert.h>
-#if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__) && !defined(_MSC_VER)
+#if __STDC_VERSION__ >= 201112L && !defined (__STDC_NO_THREADS__) && defined (CLAP_HAS_THREADS_H)
# define CLAP_HAS_THREAD
# include <threads.h>
#endif