CompileOptions.cmake 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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() # GCC 4.8
  34. add_compile_options(
  35. -g
  36. -O0 # GCC 4.8 doesn't support -Og
  37. -Wno-shadow # allow the same name for a function parameter and a member functions
  38. -Wp,-w # Disable preprocessing warnings (see below)
  39. )
  40. # GCC 4.8 doesn't support __has_include, so we need to help him
  41. add_definitions(
  42. -DARDUINOJSON_ENABLE_STD_STRING=1
  43. -DARDUINOJSON_ENABLE_STD_STREAM=1
  44. )
  45. endif()
  46. add_compile_options(
  47. -Wstrict-null-sentinel
  48. -Wno-vla # Allow VLA in tests
  49. )
  50. add_definitions(-DHAS_VARIABLE_LENGTH_ARRAY)
  51. if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.5)
  52. add_compile_options(-Wlogical-op) # the flag exists in 4.4 but is buggy
  53. endif()
  54. if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.6)
  55. add_compile_options(-Wnoexcept)
  56. endif()
  57. endif()
  58. if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  59. add_compile_options(
  60. -Wc++11-compat
  61. -Wdeprecated-register
  62. -Wno-vla-extension # Allow VLA in tests
  63. )
  64. add_definitions(
  65. -DHAS_VARIABLE_LENGTH_ARRAY
  66. -DSUBSCRIPT_CONFLICTS_WITH_BUILTIN_OPERATOR
  67. )
  68. endif()
  69. if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  70. add_compile_options(-stdlib=libc++)
  71. link_libraries(c++ m)
  72. if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0) AND(NOT ${COVERAGE}))
  73. add_compile_options(-g -Og)
  74. else()
  75. add_compile_options(-g -O0)
  76. endif()
  77. endif()
  78. if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
  79. if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0) AND(NOT ${COVERAGE}))
  80. add_compile_options(-g -Og)
  81. else()
  82. add_compile_options(-g -O0)
  83. endif()
  84. endif()
  85. if(MSVC)
  86. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  87. add_compile_options(
  88. /W4 # Set warning level
  89. /WX # Treats all compiler warnings as errors.
  90. /Zc:__cplusplus # Enable updated __cplusplus macro
  91. )
  92. endif()
  93. if(MINGW)
  94. # Static link on MinGW to avoid linking with the wrong DLLs when multiple
  95. # versions are installed.
  96. add_link_options(-static)
  97. endif()