CMakeLists.txt 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # This test will verify if CheckCXXSymbolExists only report symbols available
  2. # for linking that really are. You can find some documentation on this in
  3. # bug 11333 where we found out that gcc would optimize out the actual
  4. # reference to the symbol, so symbols that are in fact _not_ available in the
  5. # given libraries (but seen in header) were reported as present.
  6. #
  7. # If you change this test do not forget to change the CheckSymbolExists
  8. # test, too.
  9. project(CheckCXXSymbolExists CXX)
  10. cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
  11. set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/../CheckSymbolExists")
  12. include(CheckCXXSymbolExists)
  13. foreach(_config_type Release RelWithDebInfo MinSizeRel Debug)
  14. set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type})
  15. unset(CSE_RESULT_${_config_type} CACHE)
  16. message(STATUS "Testing configuration ${_config_type}")
  17. check_cxx_symbol_exists(non_existent_function_for_symbol_test "cm_cse.h" CSE_RESULT_${_config_type})
  18. if (CSE_RESULT_${_config_type})
  19. message(SEND_ERROR "CheckCXXSymbolExists reported a nonexistent symbol as existing in configuration ${_config_type}")
  20. endif ()
  21. endforeach()
  22. set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})
  23. unset(CSE_RESULT_ERRNO_CERRNO CACHE)
  24. message(STATUS "Checking <cerrno>")
  25. check_cxx_symbol_exists(errno "cerrno" CSE_RESULT_ERRNO_CERRNO)
  26. if (NOT CSE_RESULT_ERRNO_CERRNO)
  27. unset(CSE_RESULT_ERRNO_ERRNOH CACHE)
  28. message(STATUS "Checking <errno.h>")
  29. check_cxx_symbol_exists(errno "errno.h" CSE_RESULT_ERRNO_ERRNOH)
  30. if (NOT CSE_RESULT_ERRNO_ERRNOH)
  31. message(SEND_ERROR "CheckCXXSymbolExists did not find errno in <cerrno> and <errno.h>")
  32. else ()
  33. message(STATUS "errno found in <errno.h>")
  34. endif ()
  35. else ()
  36. message(STATUS "errno found in <cerrno>")
  37. endif ()
  38. if (CMAKE_COMPILER_IS_GNUCXX)
  39. string(APPEND CMAKE_CXX_FLAGS " -O3")
  40. unset(CSE_RESULT_O3 CACHE)
  41. message(STATUS "Testing with optimization -O3")
  42. check_cxx_symbol_exists(non_existent_function_for_symbol_test "cm_cse.h" CSE_RESULT_O3)
  43. if (CSE_RESULT_O3)
  44. message(SEND_ERROR "CheckCXXSymbolExists reported a nonexistent symbol as existing with optimization -O3")
  45. endif ()
  46. endif ()