compilerconfig.cmake 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # OBS CMake macOS compiler configuration module
  2. # Enable distinction between Clang and AppleClang
  3. if(POLICY CMP0025)
  4. cmake_policy(SET CMP0025 NEW)
  5. endif()
  6. # Honor visibility presets for all target types (executable, shared, module, static)
  7. if(POLICY CMP0063)
  8. cmake_policy(SET CMP0063 NEW)
  9. endif()
  10. include(ccache)
  11. include(compiler_common)
  12. include(simd)
  13. # Set C17 / C++17 standards as required and disable extensions
  14. set(CMAKE_CXX_STANDARD 17)
  15. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  16. set(CMAKE_CXX_EXTENSIONS OFF)
  17. set(CMAKE_C_STANDARD 17)
  18. set(CMAKE_C_STANDARD_REQUIRED ON)
  19. set(CMAKE_C_EXTENSIONS OFF)
  20. # Set symbols to be hidden by default for C and C++
  21. set(CMAKE_CXX_VISIBILITY_PRESET hidden)
  22. set(CMAKE_C_VISIBILITY_PRESET hidden)
  23. set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE)
  24. # Add default C and C++ compiler options if Xcode generator is not used
  25. if(NOT XCODE)
  26. list(
  27. APPEND
  28. _obs_c_options
  29. -Werror
  30. -Wextra
  31. -Wvla
  32. -Wswitch
  33. -Wformat-security
  34. -Wunused-parameter
  35. -Wno-unused-function
  36. -Wno-missing-field-initializers
  37. -Wformat
  38. -fno-strict-aliasing
  39. -Wno-error=shorten-64-to-32)
  40. # Enable stripping of dead symbols when not building for Debug configuration
  41. set(_release_configs RelWithDebInfo Release MinSizeRel)
  42. if(CMAKE_BUILD_TYPE IN_LIST _release_configs)
  43. add_link_options(LINKER:-dead_strip)
  44. endif()
  45. add_compile_options("$<$<COMPILE_LANGUAGE:C>:${_obs_c_options}>" "$<$<COMPILE_LANGUAGE:CXX>:${_obs_c_options}>")
  46. option(ENABLE_COMPILER_TRACE "Enable clang time-trace (requires Ninja)" OFF)
  47. mark_as_advanced(ENABLE_COMPILER_TRACE)
  48. # Add time trace option to compiler, if enabled.
  49. if(ENABLE_COMPILER_TRACE AND CMAKE_GENERATOR STREQUAL "Ninja")
  50. add_compile_options($<$<COMPILE_LANGUAGE:C>:-ftime-trace> $<$<COMPILE_LANGUAGE:CXX>:-ftime-trace>)
  51. else()
  52. set(ENABLE_COMPILER_TRACE
  53. OFF
  54. CACHE STRING "Enable clang time-trace (requires Ninja)" FORCE)
  55. endif()
  56. # Enable color diagnostics for AppleClang
  57. set(CMAKE_COLOR_DIAGNOSTICS ON)
  58. endif()
  59. add_compile_definitions($<$<CONFIG:DEBUG>:DEBUG> $<$<CONFIG:DEBUG>:_DEBUG>)