Skip to content

Commit

Permalink
Let cmake find out if threads.h is available
Browse files Browse the repository at this point in the history
  • Loading branch information
abique committed Nov 30, 2023
1 parent 4e57e1f commit 1e09a99
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/plugin-template.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1e09a99

Please sign in to comment.