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