CMakeBackwardCompatibilityCXX.cmake 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. CMakeBackwardCompatibilityCXX
  5. -----------------------------
  6. define a bunch of backwards compatibility variables
  7. ::
  8. CMAKE_ANSI_CXXFLAGS - flag for ansi c++
  9. CMAKE_HAS_ANSI_STRING_STREAM - has <strstream>
  10. include(TestForANSIStreamHeaders)
  11. include(CheckIncludeFileCXX)
  12. include(TestForSTDNamespace)
  13. include(TestForANSIForScope)
  14. #]=======================================================================]
  15. if(NOT CMAKE_SKIP_COMPATIBILITY_TESTS)
  16. # check for some ANSI flags in the CXX compiler if it is not gnu
  17. if(NOT CMAKE_COMPILER_IS_GNUCXX)
  18. include(TestCXXAcceptsFlag)
  19. set(CMAKE_TRY_ANSI_CXX_FLAGS "")
  20. if(CMAKE_SYSTEM_NAME MATCHES "OSF")
  21. set(CMAKE_TRY_ANSI_CXX_FLAGS "-std strict_ansi -nopure_cname")
  22. endif()
  23. # if CMAKE_TRY_ANSI_CXX_FLAGS has something in it, see
  24. # if the compiler accepts it
  25. if(NOT CMAKE_TRY_ANSI_CXX_FLAGS STREQUAL "")
  26. CHECK_CXX_ACCEPTS_FLAG(${CMAKE_TRY_ANSI_CXX_FLAGS} CMAKE_CXX_ACCEPTS_FLAGS)
  27. # if the compiler liked the flag then set CMAKE_ANSI_CXXFLAGS
  28. # to the flag
  29. if(CMAKE_CXX_ACCEPTS_FLAGS)
  30. set(CMAKE_ANSI_CXXFLAGS ${CMAKE_TRY_ANSI_CXX_FLAGS} CACHE INTERNAL
  31. "What flags are required by the c++ compiler to make it ansi." )
  32. endif()
  33. endif()
  34. endif()
  35. set(CMAKE_CXX_FLAGS_SAVE ${CMAKE_CXX_FLAGS})
  36. string(APPEND CMAKE_CXX_FLAGS " ${CMAKE_ANSI_CXXFLAGS}")
  37. include(TestForANSIStreamHeaders)
  38. include(CheckIncludeFileCXX)
  39. include(TestForSTDNamespace)
  40. include(TestForANSIForScope)
  41. include(TestForSSTREAM)
  42. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_SAVE}")
  43. endif()