~ubuntu-branches/ubuntu/utopic/zoneminder/utopic-proposed

« back to all changes in this revision

Viewing changes to cmake/Modules/CheckPrototypeDefinition.cmake

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo
  • Date: 2014-01-19 22:07:18 UTC
  • mfrom: (15.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20140119220718-idkyepfw1zvr6cm2
Tags: 1.26.5-1ubuntu1
* Merge from Debian unstable. Remaining changes:
  - debian/control: Add libnet-sftp-foreign-perl to dependencies.
  - debian/control: Apache2 transition.
  - Port from ffmpeg to avconv.
  - Still build-depending on libgnutls-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
8
# Example:
 
9
#  check_prototype_definition(getpwent_r
 
10
#   "struct passwd *getpwent_r(struct passwd *src, char *buf, int buflen)"
 
11
#   "NULL"
 
12
#   "unistd.h;pwd.h"
 
13
#   SOLARIS_GETPWENT_R)
 
14
# The following variables may be set before calling this macro to
 
15
# modify the way the check is run:
 
16
#
 
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
 
21
 
 
22
#=============================================================================
 
23
# Copyright 2005-2009 Kitware, Inc.
 
24
# Copyright 2010-2011 Andreas Schneider <asn@cryptomilk.org>
 
25
#
 
26
# Distributed under the OSI-approved BSD License (the "License");
 
27
# see accompanying file Copyright.txt for details.
 
28
#
 
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.)
 
35
#
 
36
 
 
37
 
 
38
get_filename_component(__check_proto_def_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
 
39
 
 
40
 
 
41
function(CHECK_PROTOTYPE_DEFINITION _FUNCTION _PROTOTYPE _RETURN _HEADER _VARIABLE)
 
42
 
 
43
  if ("${_VARIABLE}" MATCHES "^${_VARIABLE}$")
 
44
    set(CHECK_PROTOTYPE_DEFINITION_CONTENT "/* */\n")
 
45
 
 
46
    set(CHECK_PROTOTYPE_DEFINITION_FLAGS ${CMAKE_REQUIRED_FLAGS})
 
47
    if (CMAKE_REQUIRED_LIBRARIES)
 
48
      set(CHECK_PROTOTYPE_DEFINITION_LIBS
 
49
        LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
 
50
    else()
 
51
      set(CHECK_PROTOTYPE_DEFINITION_LIBS)
 
52
    endif()
 
53
    if (CMAKE_REQUIRED_INCLUDES)
 
54
      set(CMAKE_SYMBOL_EXISTS_INCLUDES
 
55
        "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
 
56
    else()
 
57
      set(CMAKE_SYMBOL_EXISTS_INCLUDES)
 
58
    endif()
 
59
 
 
60
    foreach(_FILE ${_HEADER})
 
61
      set(CHECK_PROTOTYPE_DEFINITION_HEADER
 
62
        "${CHECK_PROTOTYPE_DEFINITION_HEADER}#include <${_FILE}>\n")
 
63
    endforeach()
 
64
 
 
65
    set(CHECK_PROTOTYPE_DEFINITION_SYMBOL ${_FUNCTION})
 
66
    set(CHECK_PROTOTYPE_DEFINITION_PROTO ${_PROTOTYPE})
 
67
    set(CHECK_PROTOTYPE_DEFINITION_RETURN ${_RETURN})
 
68
 
 
69
    configure_file("${__check_proto_def_dir}/CheckPrototypeDefinition.c.in"
 
70
      "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckPrototypeDefinition.c" @ONLY)
 
71
 
 
72
    file(READ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckPrototypeDefinition.c _SOURCE)
 
73
 
 
74
    try_compile(${_VARIABLE}
 
75
      ${CMAKE_BINARY_DIR}
 
76
      ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckPrototypeDefinition.c
 
77
      COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
 
78
      ${CHECK_PROTOTYPE_DEFINITION_LIBS}
 
79
      CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${CHECK_PROTOTYPE_DEFINITION_FLAGS}
 
80
      "${CMAKE_SYMBOL_EXISTS_INCLUDES}"
 
81
      OUTPUT_VARIABLE OUTPUT)
 
82
 
 
83
    if (${_VARIABLE})
 
84
      set(${_VARIABLE} 1 CACHE INTERNAL "Have correct prototype for ${_FUNCTION}")
 
85
      message(STATUS "Checking prototype ${_FUNCTION} for ${_VARIABLE} - True")
 
86
      file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
 
87
        "Determining if the prototype ${_FUNCTION} exists for ${_VARIABLE} passed with the following output:\n"
 
88
        "${OUTPUT}\n\n")
 
89
    else ()
 
90
      message(STATUS "Checking prototype ${_FUNCTION} for ${_VARIABLE} - False")
 
91
      set(${_VARIABLE} 0 CACHE INTERNAL "Have correct prototype for ${_FUNCTION}")
 
92
      file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
 
93
        "Determining if the prototype ${_FUNCTION} exists for ${_VARIABLE} failed with the following output:\n"
 
94
        "${OUTPUT}\n\n${_SOURCE}\n\n")
 
95
    endif ()
 
96
  endif()
 
97
 
 
98
endfunction()