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