1# - Check if a C++ function exists
2# CHECK_CXX_EXPRESSION_COMPILES(<expression> <files> <variable>)
3#
4# Check that the <expression> compiles in a program that includes
5# <files> and store the result in a <variable>.  Specify the list
6# of files in one argument as a semicolon-separated list.
7#
8# The following variables may be set before calling this macro to
9# modify the way the check is run:
10#
11#  CMAKE_REQUIRED_FLAGS = string of compile command line flags
12#  CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
13#  CMAKE_REQUIRED_INCLUDES = list of include directories
14#  CMAKE_REQUIRED_LIBRARIES = list of libraries to link
15#
16# ${variable} is set to 1 on success 0 on failure
17
18#=============================================================================
19# Copyright 2003-2011 Kitware, Inc.
20#
21# Distributed under the OSI-approved BSD License (the "License");
22# see accompanying file Copyright.txt for details.
23#
24# This software is distributed WITHOUT ANY WARRANTY; without even the
25# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
26# See the License for more information.
27#=============================================================================
28# (To distribute this file outside of CMake, substitute the full
29#  License text for the above reference.)
30
31include(CheckCXXSourceCompiles)
32
33macro(check_cxx_expression_compiles EXPRESSION FILES VARIABLE)
34  set(SOURCE "/* CHECK_CXX_EXPRESSION_COMPILES */\n")
35  foreach(FILE ${FILES})
36    set(SOURCE "${SOURCE}#include <${FILE}>\n")
37  endforeach()
38  set(SOURCE "${SOURCE}\nint main()\n{\n")
39  set(SOURCE "${SOURCE}  static_cast<void>(${EXPRESSION});\n\n")
40  set(SOURCE "${SOURCE}  return 0;\n}\n")
41  CHECK_CXX_SOURCE_COMPILES("${SOURCE}" "${VARIABLE}") # Returns 1 - Success "" Failure
42  if( NOT ${VARIABLE} ) # Variable is set to zero
43    set(${VARIABLE} 0 CACHE INTERNAL "Test ${VARIABLE}") #Assume failure, only set to non-zero if CHECK_CXX_SOURCE_COMPILES
44  endif()
45endmacro()
46