CMakeLists.txt 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # This test will verify if CheckSymbolExists 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 CheckCXXSymbolExists
  8. # test, too.
  9. project(CheckSymbolExists C)
  10. cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
  11. set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}")
  12. include(CheckSymbolExists)
  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_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 "CheckSymbolExists 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 CACHE)
  24. check_symbol_exists(errno "errno.h" CSE_RESULT_ERRNO)
  25. if (NOT CSE_RESULT_ERRNO)
  26. message(SEND_ERROR "CheckSymbolExists did not find errno in <errno.h>")
  27. else ()
  28. message(STATUS "errno found as expected")
  29. endif ()
  30. if (CMAKE_COMPILER_IS_GNUCC)
  31. string(APPEND CMAKE_C_FLAGS " -O3")
  32. unset(CSE_RESULT_O3 CACHE)
  33. message(STATUS "Testing with optimization -O3")
  34. check_symbol_exists(non_existent_function_for_symbol_test "cm_cse.h" CSE_RESULT_O3)
  35. if (CSE_RESULT_O3)
  36. message(SEND_ERROR "CheckSymbolExists reported a nonexistent symbol as existing with optimization -O3")
  37. endif ()
  38. endif ()