File: CFeatureCheck.cmake

package info (click to toggle)
opus 1.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,860 kB
  • sloc: ansic: 592,652; sh: 4,541; asm: 723; makefile: 457; perl: 264; python: 77
file content (39 lines) | stat: -rw-r--r-- 1,036 bytes parent folder | download | duplicates (4)
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
# - Compile and run code to check for C features
#
# This functions compiles a source file under the `cmake` folder
# and adds the corresponding `HAVE_[FILENAME]` flag to the CMake
# environment
#
#  c_feature_check(<FLAG> [<VARIANT>])
#
# - Example
#
# include(CFeatureCheck)
# c_feature_check(VLA)

if(__c_feature_check)
  return()
endif()
set(__c_feature_check INCLUDED)

function(c_feature_check FILE)
  string(TOLOWER ${FILE} FILE)
  string(TOUPPER ${FILE} VAR)
  string(TOUPPER "${VAR}_SUPPORTED" FEATURE)
  if (DEFINED ${VAR}_SUPPORTED)
    set(${VAR}_SUPPORTED 1 PARENT_SCOPE)
    return()
  endif()

  if (NOT DEFINED COMPILE_${FEATURE})
      message(STATUS "Performing Test ${FEATURE}")
      try_compile(COMPILE_${FEATURE} ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/${FILE}.c)
  endif()

  if(COMPILE_${FEATURE})
    message(STATUS "Performing Test ${FEATURE} -- success")
    set(${VAR}_SUPPORTED 1 PARENT_SCOPE)
  else()
    message(STATUS "Performing Test ${FEATURE} -- failed to compile")
  endif()
endfunction()