CMakeLists.txt 2.13 KB
Newer Older
1 2 3 4 5 6 7 8 9
# This test will verify if CheckCXXSymbolExists only report symbols available
# for linking that really are. You can find some documentation on this in
# bug 11333 where we found out that gcc would optimize out the actual
# reference to the symbol, so symbols that are in fact _not_ available in the
# given libraries (but seen in header) were reported as present.
#
# If you change this test do not forget to change the CheckSymbolExists
# test, too.

10
project(CheckCXXSymbolExists CXX)
11

12
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
13

14
set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/../CheckSymbolExists")
15

16
include(CheckCXXSymbolExists)
17 18 19 20

foreach(_config_type Release RelWithDebInfo MinSizeRel Debug)
  set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type})
  unset(CSE_RESULT_${_config_type} CACHE)
21
  message(STATUS "Testing configuration ${_config_type}")
22 23
  check_cxx_symbol_exists(non_existent_function_for_symbol_test "cm_cse.h" CSE_RESULT_${_config_type})

24 25
  if (CSE_RESULT_${_config_type})
    message(SEND_ERROR "CheckCXXSymbolExists reported a nonexistent symbol as existing in configuration ${_config_type}")
26
  endif ()
27 28 29 30 31
endforeach()

set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})
unset(CSE_RESULT_ERRNO_CERRNO CACHE)

32
message(STATUS "Checking <cerrno>")
33 34 35

check_cxx_symbol_exists(errno "cerrno" CSE_RESULT_ERRNO_CERRNO)

36
if (NOT CSE_RESULT_ERRNO_CERRNO)
37 38
  unset(CSE_RESULT_ERRNO_ERRNOH CACHE)

39
  message(STATUS "Checking <errno.h>")
40 41 42

  check_cxx_symbol_exists(errno "errno.h" CSE_RESULT_ERRNO_ERRNOH)

43 44
  if (NOT CSE_RESULT_ERRNO_ERRNOH)
    message(SEND_ERROR "CheckCXXSymbolExists did not find errno in <cerrno> and <errno.h>")
45
  else ()
46
    message(STATUS "errno found in <errno.h>")
47 48
  endif ()
else ()
49
  message(STATUS "errno found in <cerrno>")
50
endif ()
51

52
if (CMAKE_COMPILER_IS_GNUCXX)
53
  string(APPEND CMAKE_CXX_FLAGS " -O3")
54
  unset(CSE_RESULT_O3 CACHE)
55
  message(STATUS "Testing with optimization -O3")
56 57 58

  check_cxx_symbol_exists(non_existent_function_for_symbol_test "cm_cse.h" CSE_RESULT_O3)

59 60
  if (CSE_RESULT_O3)
    message(SEND_ERROR "CheckCXXSymbolExists reported a nonexistent symbol as existing with optimization -O3")
61 62
  endif ()
endif ()