CompileFlags.cmake 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. if(MSVC)
  18. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stack:10000000")
  19. endif()
  20. if(CMAKE_CXX_COMPILER_ID STREQUAL Clang
  21. AND "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC"
  22. AND "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
  23. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Xlinker -stack:20000000")
  24. endif()
  25. #silence duplicate symbol warnings on AIX
  26. if(CMAKE_SYSTEM_NAME MATCHES "AIX")
  27. if(NOT CMAKE_COMPILER_IS_GNUCXX)
  28. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -bhalt:5 ")
  29. endif()
  30. endif()
  31. if(CMAKE_SYSTEM MATCHES "OSF1-V")
  32. if(NOT CMAKE_COMPILER_IS_GNUCXX)
  33. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -timplicit_local -no_implicit_include ")
  34. endif()
  35. endif()
  36. # Workaround for short jump tables on PA-RISC
  37. if(CMAKE_SYSTEM_PROCESSOR MATCHES "^parisc")
  38. if(CMAKE_COMPILER_IS_GNUCC)
  39. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mlong-calls")
  40. endif()
  41. if(CMAKE_COMPILER_IS_GNUCXX)
  42. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mlong-calls")
  43. endif()
  44. endif()
  45. # Workaround for TOC Overflow on ppc64
  46. if(CMAKE_SYSTEM_NAME STREQUAL "AIX" AND
  47. CMAKE_SYSTEM_PROCESSOR MATCHES "powerpc")
  48. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-bbigtoc")
  49. elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
  50. CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64")
  51. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-multi-toc")
  52. endif()
  53. if (CMAKE_CXX_COMPILER_ID STREQUAL SunPro AND
  54. NOT DEFINED CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION)
  55. if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.13)
  56. if (NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD EQUAL 98)
  57. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++03")
  58. elseif(CMAKE_VERSION VERSION_LESS 3.8.20170502)
  59. # CMake knows how to add this flag for compilation as C++11,
  60. # but has not been taught that SunPro needs it for linking too.
  61. # Add it in a place that will be used for both.
  62. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  63. endif()
  64. else()
  65. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -library=stlport4")
  66. endif()
  67. endif()
  68. foreach(lang C CXX)
  69. # Suppress warnings from PGI compiler.
  70. if (CMAKE_${lang}_COMPILER_ID STREQUAL "PGI")
  71. set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} -w")
  72. endif()
  73. endforeach()
  74. # use the ansi CXX compile flag for building cmake
  75. if (CMAKE_ANSI_CXXFLAGS)
  76. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_ANSI_CXXFLAGS}")
  77. endif ()
  78. if (CMAKE_ANSI_CFLAGS)
  79. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")
  80. endif ()
  81. # Allow per-translation-unit parallel builds when using MSVC
  82. if(CMAKE_GENERATOR MATCHES "Visual Studio" AND
  83. (CMAKE_C_COMPILER_ID MATCHES "MSVC|Intel" OR
  84. CMAKE_CXX_COMPILER_ID MATCHES "MSVC|Intel"))
  85. set(CMake_MSVC_PARALLEL ON CACHE STRING "\
  86. Enables /MP flag for parallel builds using MSVC. Specify an \
  87. integer value to control the number of threads used (Only \
  88. works on some older versions of Visual Studio). Setting to \
  89. ON lets the toolchain decide how many threads to use. Set to \
  90. OFF to disable /MP completely." )
  91. if(CMake_MSVC_PARALLEL)
  92. if(CMake_MSVC_PARALLEL GREATER 0)
  93. string(APPEND CMAKE_C_FLAGS " /MP${CMake_MSVC_PARALLEL}")
  94. string(APPEND CMAKE_CXX_FLAGS " /MP${CMake_MSVC_PARALLEL}")
  95. else()
  96. string(APPEND CMAKE_C_FLAGS " /MP")
  97. string(APPEND CMAKE_CXX_FLAGS " /MP")
  98. endif()
  99. endif()
  100. endif()