xref: /freebsd/contrib/libevent/cmake/CheckConstExists.cmake (revision 257e70f1d5ee61037c8c59b116538d3b6b1427a2)
1include(CheckCSourceCompiles)
2
3macro(check_const_exists CONST FILES VARIABLE)
4  if (NOT DEFINED ${VARIABLE})
5    set(check_const_exists_source "")
6    foreach(file ${FILES})
7      set(check_const_exists_source
8          "${check_const_exists_source}
9          #include <${file}>")
10    endforeach()
11    set(check_const_exists_source
12        "${check_const_exists_source}
13        int main() { (void)${CONST}; return 0; }")
14
15    check_c_source_compiles("${check_const_exists_source}" ${VARIABLE})
16
17    if (${${VARIABLE}})
18      set(${VARIABLE} 1 CACHE INTERNAL "Have const ${CONST}")
19      message(STATUS "Looking for ${CONST} - found")
20    else()
21      set(${VARIABLE} 0 CACHE INTERNAL "Have const ${CONST}")
22      message(STATUS "Looking for ${CONST} - not found")
23    endif()
24  endif()
25endmacro(check_const_exists)
26