File: CheckClangBlocks.cmake

package info (click to toggle)
libfyaml 0.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,328 kB
  • sloc: ansic: 62,193; asm: 8,692; sh: 1,628; makefile: 581; python: 23
file content (53 lines) | stat: -rw-r--r-- 1,536 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# --- CheckClangBlocks.cmake ---
# Detect support for Clang Blocks (Clang or AppleClang)
# Defines: HAVE_CLANG_BLOCKS (0 or 1)
# Defines: CLANG_BLOCKS_LIB (empty or "BlocksRuntime")

# Default
set(HAVE_CLANG_BLOCKS 0)
set(CLANG_BLOCKS_LIB "")

if (CMAKE_C_COMPILER_ID MATCHES "Clang")

    # AppleClang: Blocks are built-in
    if (CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
        message(STATUS "AppleClang detected — Blocks support is built in")

        set(HAVE_CLANG_BLOCKS 1)
        set(CLANG_BLOCKS_LIB "")

    else()
        # LLVM Clang: must test for -fblocks and libBlocksRuntime
        message(STATUS "LLVM Clang detected — checking for BlocksRuntime")

        include(CheckCSourceCompiles)

        set(CMAKE_REQUIRED_FLAGS "-fblocks")
        set(CMAKE_REQUIRED_LIBRARIES "BlocksRuntime")

        check_c_source_compiles("
            #include <Block.h>
            int main(void) {
                void (^b)(void) = ^{ };
                b();
                return 0;
            }
        " HAVE_WORKING_CLANG_BLOCKS)

        unset(CMAKE_REQUIRED_FLAGS)
        unset(CMAKE_REQUIRED_LIBRARIES)

        if (HAVE_WORKING_CLANG_BLOCKS)
            message(STATUS "Clang Blocks support ENABLED")
            set(HAVE_CLANG_BLOCKS 1)
            set(CLANG_BLOCKS_LIB "BlocksRuntime")
        else()
            message(WARNING
                "libBlocksRuntime not found — Clang Blocks disabled")
            set(HAVE_CLANG_BLOCKS 0)
            set(CLANG_BLOCKS_LIB "")
        endif()

    endif()

endif()