CompileOptions.cmake 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
  2. add_compile_options(
  3. -pedantic
  4. -Wall
  5. -Wcast-align
  6. -Wcast-qual
  7. -Wconversion
  8. -Wctor-dtor-privacy
  9. -Wdisabled-optimization
  10. -Werror
  11. -Wextra
  12. -Wformat=2
  13. -Winit-self
  14. -Wmissing-include-dirs
  15. -Wnon-virtual-dtor
  16. -Wold-style-cast
  17. -Woverloaded-virtual
  18. -Wparentheses
  19. -Wredundant-decls
  20. -Wshadow
  21. -Wsign-promo
  22. -Wstrict-aliasing
  23. -Wundef
  24. )
  25. if(${COVERAGE})
  26. set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage")
  27. endif()
  28. endif()
  29. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  30. if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8) AND (NOT ${COVERAGE}))
  31. add_compile_options(-g -Og)
  32. else()
  33. add_compile_options(-g -O0)
  34. endif()
  35. add_compile_options(
  36. -Wstrict-null-sentinel
  37. -Wno-vla # Allow VLA in tests
  38. )
  39. add_definitions(-DHAS_VARIABLE_LENGTH_ARRAY)
  40. if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.5)
  41. add_compile_options(-Wlogical-op) # the flag exists in 4.4 but is buggy
  42. endif()
  43. if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.6)
  44. add_compile_options(-Wnoexcept)
  45. endif()
  46. endif()
  47. if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  48. add_compile_options(
  49. -Wc++11-compat
  50. -Wdeprecated-register
  51. -Wno-vla-extension # Allow VLA in tests
  52. )
  53. add_definitions(
  54. -DHAS_VARIABLE_LENGTH_ARRAY
  55. -DSUBSCRIPT_CONFLICTS_WITH_BUILTIN_OPERATOR
  56. )
  57. endif()
  58. if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  59. if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0) AND (NOT ${COVERAGE}))
  60. add_compile_options(-g -Og)
  61. else()
  62. add_compile_options(-g -O0)
  63. endif()
  64. endif()
  65. if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
  66. if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0) AND (NOT ${COVERAGE}))
  67. add_compile_options(-g -Og)
  68. else()
  69. add_compile_options(-g -O0)
  70. endif()
  71. endif()
  72. if(MSVC)
  73. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  74. add_compile_options(
  75. /W4 # Set warning level
  76. /WX # Treats all compiler warnings as errors.
  77. )
  78. if (NOT MSVC_VERSION LESS 1910) # >= Visual Studio 2017
  79. add_compile_options(
  80. /Zc:__cplusplus # Enable updated __cplusplus macro
  81. )
  82. endif()
  83. endif()