CompileFlags.cmake 4.0 KB

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