Debian Codegraph @

cmake/CheckDIRSymbolExists.cmake

raw
1 # - Check if the DIR symbol exists like in AC_HEADER_DIRENT.
2 # CHECK_DIRSYMBOL_EXISTS(FILES VARIABLE)
3 #
4 # FILES - include files to check
5 # VARIABLE - variable to return result
6 #
7 # This module is a small but important variation on CheckSymbolExists.cmake.
8 # The symbol always searched for is DIR, and the test programme follows
9 # the AC_HEADER_DIRENT test programme rather than the CheckSymbolExists.cmake
10 # test programme which always fails since DIR tends to be typedef'd
11 # rather than #define'd.
12 #
13 # The following variables may be set before calling this macro to
14 # modify the way the check is run:
15 #
16 # CMAKE_REQUIRED_FLAGS = string of compile command line flags
17 # CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
18 # CMAKE_REQUIRED_INCLUDES = list of include directories
19 # CMAKE_REQUIRED_LIBRARIES = list of libraries to link
20
21 MACRO(CHECK_DIRSYMBOL_EXISTS FILES VARIABLE)
22 IF(NOT DEFINED ${VARIABLE})
23 SET(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
24 SET(MACRO_CHECK_DIRSYMBOL_EXISTS_FLAGS ${CMAKE_REQUIRED_FLAGS})
25 IF(CMAKE_REQUIRED_LIBRARIES)
26 SET(CHECK_DIRSYMBOL_EXISTS_LIBS
27 "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
28 ELSE(CMAKE_REQUIRED_LIBRARIES)
29 SET(CHECK_DIRSYMBOL_EXISTS_LIBS)
30 ENDIF(CMAKE_REQUIRED_LIBRARIES)
31 IF(CMAKE_REQUIRED_INCLUDES)
32 SET(CMAKE_DIRSYMBOL_EXISTS_INCLUDES
33 "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
34 ELSE(CMAKE_REQUIRED_INCLUDES)
35 SET(CMAKE_DIRSYMBOL_EXISTS_INCLUDES)
36 ENDIF(CMAKE_REQUIRED_INCLUDES)
37 FOREACH(FILE ${FILES})
38 SET(CMAKE_CONFIGURABLE_FILE_CONTENT
39 "${CMAKE_CONFIGURABLE_FILE_CONTENT}#include <${FILE}>\n")
40 ENDFOREACH(FILE)
41 SET(CMAKE_CONFIGURABLE_FILE_CONTENT
42 "${CMAKE_CONFIGURABLE_FILE_CONTENT}\nint main()\n{if ((DIR *) 0) return 0;}\n")
43
44 CONFIGURE_FILE("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
45 "${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/CheckDIRSymbolExists.c" @ONLY)
46
47 MESSAGE(STATUS "Looking for DIR in ${FILES}")
48 TRY_COMPILE(${VARIABLE}
49 ${CMAKE_BINARY_DIR}
50 ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/CheckDIRSymbolExists.c
51 COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
52 CMAKE_FLAGS
53 -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_DIRSYMBOL_EXISTS_FLAGS}
54 "${CHECK_DIRSYMBOL_EXISTS_LIBS}"
55 "${CMAKE_DIRSYMBOL_EXISTS_INCLUDES}"
56 OUTPUT_VARIABLE OUTPUT)
57 IF(${VARIABLE})
58 MESSAGE(STATUS "Looking for DIR in ${FILES} - found")
59 SET(${VARIABLE} 1 CACHE INTERNAL "Have symbol DIR")
60 FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeOutput.log
61 "Determining if the DIR symbol is defined as in AC_HEADER_DIRENT "
62 "passed with the following output:\n"
63 "${OUTPUT}\nFile ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/CheckDIRSymbolExists.c:\n"
64 "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
65 ELSE(${VARIABLE})
66 MESSAGE(STATUS "Looking for DIR in ${FILES} - not found.")
67 SET(${VARIABLE} "" CACHE INTERNAL "Have symbol DIR")
68 FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeError.log
69 "Determining if the DIR symbol is defined as in AC_HEADER_DIRENT "
70 "failed with the following output:\n"
71 "${OUTPUT}\nFile ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/CheckDIRSymbolExists.c:\n"
72 "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
73 ENDIF(${VARIABLE})
74 ENDIF(NOT DEFINED ${VARIABLE})
75 ENDMACRO(CHECK_DIRSYMBOL_EXISTS)