lagom_compile_options.cmake 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. include(${CMAKE_CURRENT_LIST_DIR}/common_compile_options.cmake)
  2. add_cxx_compile_options(-Wno-maybe-uninitialized)
  3. add_cxx_compile_options(-Wno-shorten-64-to-32)
  4. if(NOT MSVC)
  5. add_cxx_compile_options(-fsigned-char)
  6. add_cxx_compile_options(-ggnu-pubnames)
  7. else()
  8. # char is signed
  9. add_cxx_compile_options(/J)
  10. # full symbolic debugginng information
  11. add_cxx_compile_options(/Z7)
  12. endif()
  13. if (NOT WIN32)
  14. add_cxx_compile_options(-fPIC)
  15. endif()
  16. if (LINUX)
  17. add_compile_definitions(_FILE_OFFSET_BITS=64)
  18. endif()
  19. if (APPLE)
  20. list(APPEND CMAKE_PREFIX_PATH /opt/homebrew)
  21. endif()
  22. if (CMAKE_BUILD_TYPE STREQUAL "Debug")
  23. if (NOT MSVC)
  24. add_cxx_compile_options(-ggdb3)
  25. endif()
  26. add_cxx_compile_options(-Og)
  27. else()
  28. add_cxx_compile_options(-O2)
  29. if (NOT MSVC)
  30. add_cxx_compile_options(-g1)
  31. endif()
  32. endif()
  33. function(add_cxx_linker_flag_if_supported flag)
  34. include(CheckLinkerFlag)
  35. check_linker_flag(CXX ${flag} LAGOM_LINKER_SUPPORTS_${flag})
  36. if (${LAGOM_LINKER_SUPPORTS_${flag}})
  37. add_cxx_link_options(${flag})
  38. endif()
  39. endfunction()
  40. if (NOT WIN32)
  41. add_cxx_linker_flag_if_supported(LINKER:--gdb-index)
  42. if (NOT ENABLE_FUZZERS)
  43. add_cxx_linker_flag_if_supported(LINKER:-Bsymbolic-non-weak-functions)
  44. endif()
  45. endif()
  46. if (ENABLE_LAGOM_COVERAGE_COLLECTION)
  47. if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$" AND NOT ENABLE_FUZZERS)
  48. add_cxx_compile_options(-fprofile-instr-generate -fcoverage-mapping)
  49. add_cxx_link_options(-fprofile-instr-generate)
  50. else()
  51. message(FATAL_ERROR
  52. "Collecting code coverage is unsupported in this configuration.")
  53. endif()
  54. endif()