compiler_common.cmake 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. # OBS CMake common compiler options module
  2. include_guard(GLOBAL)
  3. option(OBS_COMPILE_DEPRECATION_AS_WARNING "Downgrade deprecation warnings to actual warnings" FALSE)
  4. mark_as_advanced(OBS_COMPILE_DEPRECATION_AS_WARNING)
  5. # Set C and C++ language standards to C17 and C++17
  6. set(CMAKE_C_STANDARD 17)
  7. set(CMAKE_C_STANDARD_REQUIRED TRUE)
  8. set(CMAKE_CXX_STANDARD 17)
  9. set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
  10. # Set symbols to be hidden by default for C and C++
  11. set(CMAKE_C_VISIBILITY_PRESET hidden)
  12. set(CMAKE_CXX_VISIBILITY_PRESET hidden)
  13. set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE)
  14. # clang options for C, C++, ObjC, and ObjC++
  15. set(
  16. _obs_clang_common_options
  17. -fno-strict-aliasing
  18. -Wno-trigraphs
  19. -Wno-missing-field-initializers
  20. -Wno-missing-prototypes
  21. -Werror=return-type
  22. -Wunreachable-code
  23. -Wquoted-include-in-framework-header
  24. -Wno-missing-braces
  25. -Wparentheses
  26. -Wswitch
  27. -Wno-unused-function
  28. -Wno-unused-label
  29. -Wunused-parameter
  30. -Wunused-variable
  31. -Wunused-value
  32. -Wempty-body
  33. -Wuninitialized
  34. -Wno-unknown-pragmas
  35. -Wfour-char-constants
  36. -Wconstant-conversion
  37. -Wno-conversion
  38. -Wint-conversion
  39. -Wbool-conversion
  40. -Wenum-conversion
  41. -Wnon-literal-null-conversion
  42. -Wsign-compare
  43. -Wshorten-64-to-32
  44. -Wpointer-sign
  45. -Wnewline-eof
  46. -Wno-implicit-fallthrough
  47. -Wdeprecated-declarations
  48. -Wno-sign-conversion
  49. -Winfinite-recursion
  50. -Wcomma
  51. -Wno-strict-prototypes
  52. -Wno-semicolon-before-method-body
  53. -Wformat-security
  54. -Wvla
  55. -Wno-error=shorten-64-to-32
  56. $<$<BOOL:${OBS_COMPILE_DEPRECATION_AS_WARNING}>:-Wno-error=deprecated-declarations>
  57. )
  58. # clang options for C
  59. set(_obs_clang_c_options ${_obs_clang_common_options} -Wno-shadow -Wno-float-conversion)
  60. # clang options for C++
  61. set(
  62. _obs_clang_cxx_options
  63. ${_obs_clang_common_options}
  64. -Wno-non-virtual-dtor
  65. -Wno-overloaded-virtual
  66. -Wno-exit-time-destructors
  67. -Wno-shadow
  68. -Winvalid-offsetof
  69. -Wmove
  70. -Werror=block-capture-autoreleasing
  71. -Wrange-loop-analysis
  72. )
  73. if(CMAKE_CXX_STANDARD GREATER_EQUAL 20)
  74. list(APPEND _obs_clang_cxx_options -fno-char8_t)
  75. endif()
  76. if(NOT DEFINED CMAKE_COMPILE_WARNING_AS_ERROR)
  77. set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
  78. endif()
  79. # Enable interprocedural optimization
  80. message(STATUS "Checking for interprocedural optimization support")
  81. if(NOT DEFINED HAS_INTERPROCEDURAL_OPTIMIZATION)
  82. include(CheckIPOSupported)
  83. check_ipo_supported(RESULT _ipo_result OUTPUT _ipo_output)
  84. set(
  85. HAS_INTERPROCEDURAL_OPTIMIZATION
  86. ${_ipo_result}
  87. CACHE BOOL
  88. "Result of compiler check for interprocedural optimization"
  89. FORCE
  90. )
  91. if(HAS_INTERPROCEDURAL_OPTIMIZATION)
  92. message(STATUS "Checking for interprocedural optimization support - available")
  93. else()
  94. message(STATUS "Checking for interprocedural optimization support - unavailable")
  95. endif()
  96. mark_as_advanced(HAS_INTERPROCEDURAL_OPTIMIZATION)
  97. unset(_ipo_result)
  98. unset(_ipo_output)
  99. endif()
  100. if(HAS_INTERPROCEDURAL_OPTIMIZATION)
  101. message(STATUS "Checking for interprocedural optimization support - enabled [Release, MinSizeRel]")
  102. set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF)
  103. set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO OFF)
  104. set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
  105. set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL ON)
  106. else()
  107. message(STATUS "Checking for interprocedural optimization support - disabled")
  108. set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF)
  109. set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO OFF)
  110. set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF)
  111. set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL OFF)
  112. endif()