compilerconfig.cmake 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. # Add default C and C++ compiler options if Xcode generator is not used
  14. if(NOT XCODE)
  15. list(
  16. APPEND
  17. _obs_c_options
  18. -Werror
  19. -Wextra
  20. -Wvla
  21. -Wswitch
  22. -Wformat-security
  23. -Wunused-parameter
  24. -Wno-unused-function
  25. -Wno-missing-field-initializers
  26. -Wformat
  27. -fno-strict-aliasing
  28. -Wno-error=shorten-64-to-32)
  29. # Set symbols to be hidden by default for C and C++
  30. set(CMAKE_CXX_STANDARD 17)
  31. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  32. set(CMAKE_CXX_VISIBILITY_PRESET hidden)
  33. set(CMAKE_C_VISIBILITY_PRESET hidden)
  34. set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE)
  35. # Enable stripping of dead symbols when not building for Debug configuration
  36. set(_release_configs RelWithDebInfo Release MinSizeRel)
  37. if(CMAKE_BUILD_TYPE IN_LIST _release_configs)
  38. add_link_options(LINKER:-dead_strip)
  39. endif()
  40. add_compile_options("$<$<COMPILE_LANGUAGE:C>:${_obs_c_options}>" "$<$<COMPILE_LANGUAGE:CXX>:${_obs_c_options}>")
  41. option(ENABLE_COMPILER_TRACE "Enable clang time-trace (requires Ninja)" OFF)
  42. mark_as_advanced(ENABLE_COMPILER_TRACE)
  43. # Add time trace option to compiler, if enabled.
  44. if(ENABLE_COMPILER_TRACE AND CMAKE_GENERATOR STREQUAL "Ninja")
  45. add_compile_options($<$<COMPILE_LANGUAGE:C>:-ftime-trace> $<$<COMPILE_LANGUAGE:CXX>:-ftime-trace>)
  46. else()
  47. set(ENABLE_COMPILER_TRACE
  48. OFF
  49. CACHE STRING "Enable clang time-trace (requires Ninja)" FORCE)
  50. endif()
  51. # Enable color diagnostics for AppleClang
  52. set(CMAKE_COLOR_DIAGNOSTICS ON)
  53. endif()
  54. add_compile_definitions($<$<CONFIG:DEBUG>:DEBUG> $<$<CONFIG:DEBUG>:_DEBUG>)