CompileFlags.cmake 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #-----------------------------------------------------------------------------
  4. # set some special flags for different compilers
  5. #
  6. if(WIN32 AND CMAKE_C_COMPILER_ID STREQUAL "Intel")
  7. set(_INTEL_WINDOWS 1)
  8. endif()
  9. # Disable deprecation warnings for standard C functions.
  10. # really only needed for newer versions of VS, but should
  11. # not hurt other versions, and this will work into the
  12. # future
  13. if(MSVC OR _INTEL_WINDOWS)
  14. add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
  15. else()
  16. endif()
  17. #silence duplicate symbol warnings on AIX
  18. if(CMAKE_SYSTEM_NAME MATCHES "AIX")
  19. if(NOT CMAKE_COMPILER_IS_GNUCXX)
  20. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -bhalt:5 ")
  21. endif()
  22. endif()
  23. if(CMAKE_SYSTEM_NAME MATCHES "IRIX")
  24. if(NOT CMAKE_COMPILER_IS_GNUCXX)
  25. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-woff84 -no_auto_include")
  26. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-woff15")
  27. endif()
  28. endif()
  29. if(CMAKE_SYSTEM MATCHES "OSF1-V")
  30. if(NOT CMAKE_COMPILER_IS_GNUCXX)
  31. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -timplicit_local -no_implicit_include ")
  32. endif()
  33. endif()
  34. if(CMAKE_SYSTEM_NAME MATCHES "HP-UX" AND CMAKE_CXX_COMPILER_ID MATCHES "HP")
  35. # HP aCC since version 3.80 supports the flag +hpxstd98 to get ANSI C++98
  36. # template support. It is known that version 6.25 doesn't need that flag.
  37. # Versions prior to 3.80 will not be able to build CMake. Current assumption:
  38. # it is needed for every version from 3.80 to 4 to get it working.
  39. if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4 AND
  40. NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.80)
  41. # use new C++ library and improved template support
  42. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -AA +hpxstd98")
  43. endif()
  44. endif()
  45. # Workaround for short jump tables on PA-RISC
  46. if(CMAKE_SYSTEM_PROCESSOR MATCHES "^parisc")
  47. if(CMAKE_COMPILER_IS_GNUCC)
  48. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mlong-calls")
  49. endif()
  50. if(CMAKE_COMPILER_IS_GNUCXX)
  51. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mlong-calls")
  52. endif()
  53. endif()
  54. if (CMAKE_CXX_COMPILER_ID STREQUAL SunPro AND
  55. NOT DEFINED CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION)
  56. if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.13)
  57. if (NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD EQUAL 98)
  58. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++03")
  59. elseif(CMAKE_VERSION VERSION_LESS 3.8.20170502)
  60. # CMake knows how to add this flag for compilation as C++11,
  61. # but has not been taught that SunPro needs it for linking too.
  62. # Add it in a place that will be used for both.
  63. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  64. endif()
  65. else()
  66. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -library=stlport4")
  67. endif()
  68. endif()
  69. foreach(lang C CXX)
  70. # Suppress warnings from PGI compiler.
  71. if (CMAKE_${lang}_COMPILER_ID STREQUAL "PGI")
  72. set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} -w")
  73. endif()
  74. endforeach()
  75. # use the ansi CXX compile flag for building cmake
  76. if (CMAKE_ANSI_CXXFLAGS)
  77. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_ANSI_CXXFLAGS}")
  78. endif ()
  79. if (CMAKE_ANSI_CFLAGS)
  80. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")
  81. endif ()