How to find C11 threads

I was trying to create a project involving the use of C11 threads, but I can’t find the requirements in the CMAKE_C_KNOWN_FEATURES nor in the FindThreads package. Should I write custom detection code for this purpose, or did I miss something?

@robert.maynard Did we implement fine-grained features for C11 or is C11 a “all or nothing” detection?

C11 has compile features, but as threads are part of the C standard library, and not a language feature they aren’t covered.

Sorry for the late reply, but threads are optional feature of the libc in C11, so they aren’t always present even if detected compiler is C11, the same goes for VLA and atomics, since C11 they’re optional features. For now I settled with custom output check against __STDC_NO_THREADS__ macro, but would like to see this feature requirement in cmake too

I don’t think that fine-grained library feature detection or flag manipulation is a game CMake should get into. We had enough trouble with language feature detection in the past that I don’t really want to see that Pandora’s Box opened again. I suppose that something could be added to FindThreads, but negative features aren’t really something that is easily modeled with CMake’s targets.

Personally, I would suggest another project which handles the compiler/library detection routine via a header and makes preprocessor definitions available based on version checks. This could then be maintained outside of CMake, updated independently, and used via find_package and/or FetchContent.

1 Like