1 # - Check if the protoype we expect is correct.
2 # check_prototype_definition(FUNCTION PROTOTYPE RETURN HEADER VARIABLE)
3 # FUNCTION - The name of the function (used to check if prototype exists)
4 # PROTOTYPE- The prototype to check.
5 # RETURN - The return value of the function.
6 # HEADER - The header files required.
7 # VARIABLE - The variable to store the result.
9 # check_prototype_definition(getpwent_r
10 # "struct passwd *getpwent_r(struct passwd *src, char *buf, int buflen)"
14 # The following variables may be set before calling this macro to
15 # modify the way the check is run:
17 # CMAKE_REQUIRED_FLAGS = string of compile command line flags
18 # CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
19 # CMAKE_REQUIRED_INCLUDES = list of include directories
20 # CMAKE_REQUIRED_LIBRARIES = list of libraries to link
22 #=============================================================================
23 # Copyright 2005-2009 Kitware, Inc.
24 # Copyright 2010-2011 Andreas Schneider <asn@cryptomilk.org>
26 # Distributed under the OSI-approved BSD License (the "License");
27 # see accompanying file Copyright.txt for details.
29 # This software is distributed WITHOUT ANY WARRANTY; without even the
30 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
31 # See the License for more information.
32 #=============================================================================
33 # (To distribute this file outside of CMake, substitute the full
34 # License text for the above reference.)
37 include("${CMAKE_CURRENT_LIST_DIR}/CMakeExpandImportedTargets.cmake")
39 get_filename_component(__check_proto_def_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
42 function(CHECK_PROTOTYPE_DEFINITION _FUNCTION _PROTOTYPE _RETURN _HEADER _VARIABLE)
44 if ("${_VARIABLE}" MATCHES "^${_VARIABLE}$")
45 set(CHECK_PROTOTYPE_DEFINITION_CONTENT "/* */\n")
47 set(CHECK_PROTOTYPE_DEFINITION_FLAGS ${CMAKE_REQUIRED_FLAGS})
48 if (CMAKE_REQUIRED_LIBRARIES)
49 # this one translates potentially used imported library targets to their files on disk
50 cmake_expand_imported_targets(_ADJUSTED_CMAKE_REQUIRED_LIBRARIES LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CONFIGURATION "${CMAKE_TRY_COMPILE_CONFIGURATION}")
51 set(CHECK_PROTOTYPE_DEFINITION_LIBS
52 "-DLINK_LIBRARIES:STRING=${_ADJUSTED_CMAKE_REQUIRED_LIBRARIES}")
54 set(CHECK_PROTOTYPE_DEFINITION_LIBS)
56 if (CMAKE_REQUIRED_INCLUDES)
57 set(CMAKE_SYMBOL_EXISTS_INCLUDES
58 "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
60 set(CMAKE_SYMBOL_EXISTS_INCLUDES)
63 foreach(_FILE ${_HEADER})
64 set(CHECK_PROTOTYPE_DEFINITION_HEADER
65 "${CHECK_PROTOTYPE_DEFINITION_HEADER}#include <${_FILE}>\n")
68 set(CHECK_PROTOTYPE_DEFINITION_SYMBOL ${_FUNCTION})
69 set(CHECK_PROTOTYPE_DEFINITION_PROTO ${_PROTOTYPE})
70 set(CHECK_PROTOTYPE_DEFINITION_RETURN ${_RETURN})
72 configure_file("${__check_proto_def_dir}/CheckPrototypeDefinition.c.in"
73 "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckPrototypeDefinition.c" @ONLY)
75 file(READ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckPrototypeDefinition.c _SOURCE)
77 try_compile(${_VARIABLE}
79 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckPrototypeDefinition.c
80 COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
81 CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${CHECK_PROTOTYPE_DEFINITION_FLAGS}
82 "${CHECK_PROTOTYPE_DEFINITION_LIBS}"
83 "${CMAKE_SYMBOL_EXISTS_INCLUDES}"
84 OUTPUT_VARIABLE OUTPUT)
87 set(${_VARIABLE} 1 CACHE INTERNAL "Have correct prototype for ${_FUNCTION}")
88 message(STATUS "Checking prototype ${_FUNCTION} for ${_VARIABLE} - True")
89 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
90 "Determining if the prototype ${_FUNCTION} exists for ${_VARIABLE} passed with the following output:\n"
93 message(STATUS "Checking prototype ${_FUNCTION} for ${_VARIABLE} - False")
94 set(${_VARIABLE} 0 CACHE INTERNAL "Have correct prototype for ${_FUNCTION}")
95 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
96 "Determining if the prototype ${_FUNCTION} exists for ${_VARIABLE} failed with the following output:\n"
97 "${OUTPUT}\n\n${_SOURCE}\n\n")