CompileOptions.cmake 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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(NOT MINGW)
  26. add_compile_options(
  27. -std=c++98
  28. )
  29. endif()
  30. if(${COVERAGE})
  31. set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage")
  32. endif()
  33. endif()
  34. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  35. if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8) AND (NOT ${COVERAGE}))
  36. add_compile_options(-g -Og)
  37. else()
  38. add_compile_options(-g -O0)
  39. endif()
  40. add_compile_options(
  41. -Wstrict-null-sentinel
  42. -Wno-vla # Allow VLA in tests
  43. )
  44. add_definitions(-DHAS_VARIABLE_LENGTH_ARRAY)
  45. if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.5)
  46. add_compile_options(-Wlogical-op) # the flag exists in 4.4 but is buggy
  47. endif()
  48. if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.6)
  49. add_compile_options(-Wnoexcept)
  50. endif()
  51. endif()
  52. if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  53. add_compile_options(
  54. -Wc++11-compat
  55. -Wdeprecated-register
  56. -Wno-vla-extension # Allow VLA in tests
  57. )
  58. add_definitions(
  59. -DHAS_VARIABLE_LENGTH_ARRAY
  60. -DSUBSCRIPT_CONFLICTS_WITH_BUILTIN_OPERATOR
  61. )
  62. endif()
  63. if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  64. if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0) AND (NOT ${COVERAGE}))
  65. add_compile_options(-g -Og)
  66. else()
  67. add_compile_options(-g -O0)
  68. endif()
  69. endif()
  70. if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
  71. if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0) AND (NOT ${COVERAGE}))
  72. add_compile_options(-g -Og)
  73. else()
  74. add_compile_options(-g -O0)
  75. endif()
  76. endif()
  77. if(MSVC)
  78. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  79. add_compile_options(
  80. /W4 # Set warning level
  81. /WX # Treats all compiler warnings as errors.
  82. )
  83. if (NOT MSVC_VERSION LESS 1910) # >= Visual Studio 2017
  84. add_compile_options(
  85. /Zc:__cplusplus # Enable updated __cplusplus macro
  86. )
  87. endif()
  88. endif()