Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[8d170f]: config / cmake / Modules / CheckPrototypeExistsCXX.cmake Maximize Restore History

Download this file

CheckPrototypeExistsCXX.cmake    68 lines (60 with data), 3.2 kB

 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#
# This checks if a prototype for FUNC (with C linkage) has been
# declared in any one of the header files listed in INCLUDE. It uses
# the C++ compiler.
#
# (The check is actually whether declaring a prototype will cause a
# conflict and thus an error. The results may differ depending on the
# compiler. For example, gcc under Cygwin will issue a warning but g++
# will issue an error. In the DCMTK, the prototypes are used in a C++
# context, so we use the C++ compiler to check.
#
MACRO(CHECK_PROTOTYPE_EXISTS_CXX FUNC INCLUDE VARIABLE)
IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
SET( CHECK_PROTOTYPE_EXISTS_CXX_FILE_IN "${VXL_CMAKE_DIR}/CheckPrototypeExists.cxx.in" )
SET( CHECK_PROTOTYPE_EXISTS_CXX_FILE "${CMAKE_BINARY_DIR}/CMakeTmp/CheckPrototypeExists.cxx" )
SET( CHECK_PROTOTYPE_EXISTS_CXX_EXTERNC_BEGIN "extern \"C\" {\n" )
SET( CHECK_PROTOTYPE_EXISTS_CXX_EXTERNC_END "}\n" )
SET(MACRO_CHECK_PROTOTYPE_EXISTS_CXX_FLAGS ${CMAKE_REQUIRED_FLAGS})
MESSAGE(STATUS "Looking for prototype for ${FUNC} in ${INCLUDE}")
SET( ${VARIABLE} 0 )
FOREACH(FILE ${INCLUDE})
# First check if the header exists. Cache the result in a variable named after
# the header, so that we don't re-do the effort
STRING( REGEX REPLACE "\\.|/" "_" CLEAN_FILE ${FILE} )
SET( CHECK_PROTOTYPE_EXISTS_CXX_INCLUDE "CHECK_PROTOTYPE_EXISTS_CXX_INCLUDE_${CLEAN_FILE}" )
CHECK_INCLUDE_FILE( ${FILE} ${CHECK_PROTOTYPE_EXISTS_CXX_INCLUDE} )
IF( CHECK_PROTOTYPE_EXISTS_CXX_INCLUDE )
FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeOutput.log "Trying struct with ${FILE}\n" )
CONFIGURE_FILE( ${CHECK_PROTOTYPE_EXISTS_CXX_FILE_IN}
${CHECK_PROTOTYPE_EXISTS_CXX_FILE} IMMEDIATE )
TRY_COMPILE( CHECK_PROTOTYPE_EXISTS_CXX_RESULT
${CMAKE_BINARY_DIR}
${CHECK_PROTOTYPE_EXISTS_CXX_FILE}
CMAKE_FLAGS
-DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_PROTOTYPE_EXISTS_CXX_FLAGS}
OUTPUT_VARIABLE OUTPUT)
IF( CHECK_PROTOTYPE_EXISTS_CXX_RESULT )
FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeOutput.log
"Determining if prototype ${FUNC} exists in ${FILE} "
"failed with the following output:\n"
"${OUTPUT}\n\n")
ELSE( CHECK_PROTOTYPE_EXISTS_CXX_RESULT )
FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeOutput.log
"Determining if prototype ${FUNC} exists in ${FILE} "
"passed with the following output:\n"
"${OUTPUT}\n\n")
MESSAGE(STATUS " Found in ${FILE}")
SET( ${VARIABLE} 1 )
ENDIF( CHECK_PROTOTYPE_EXISTS_CXX_RESULT )
ENDIF( CHECK_PROTOTYPE_EXISTS_CXX_INCLUDE )
ENDFOREACH(FILE)
IF( ${VARIABLE} )
MESSAGE(STATUS "Looking for prototype of ${FUNC} - found")
SET(${VARIABLE} 1 CACHE INTERNAL "Have prototype ${VARIABLE}")
ELSE(${VARIABLE})
MESSAGE(STATUS "Looking for prototype of ${FUNC} - not found")
SET(${VARIABLE} "" CACHE INTERNAL "Have prototype ${VARIABLE}")
ENDIF(${VARIABLE})
ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
ENDMACRO(CHECK_PROTOTYPE_EXISTS_CXX)