CompilerSetup.cmake 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # Copyright 2018 Google
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # C++ Compiler setup
  15. # We use C++11
  16. set(CMAKE_CXX_STANDARD 11)
  17. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  18. set(CMAKE_CXX_EXTENSIONS OFF)
  19. if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  20. set(CLANG ON)
  21. endif()
  22. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  23. set(GNU ON)
  24. endif()
  25. if(CLANG OR GNU)
  26. set(
  27. common_flags
  28. -Wall -Wextra -Werror
  29. # Be super pedantic about format strings
  30. -Wformat
  31. # Avoid use of uninitialized values
  32. -Wuninitialized
  33. -fno-common
  34. # Delete unused things
  35. -Wunused-function -Wunused-value -Wunused-variable
  36. )
  37. set(
  38. cxx_flags
  39. # Cut down on symbol clutter
  40. # TODO(wilhuff) try -fvisibility=hidden
  41. -fvisibility-inlines-hidden
  42. )
  43. set(
  44. c_flags
  45. -Wstrict-prototypes
  46. )
  47. if(CLANG)
  48. list(
  49. APPEND common_flags
  50. -Wconditional-uninitialized -Werror=return-type -Winfinite-recursion -Wmove
  51. -Wrange-loop-analysis -Wunreachable-code
  52. # Options added to match apple recommended project settings
  53. -Wcomma
  54. )
  55. endif()
  56. foreach(flag ${common_flags} ${c_flags})
  57. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
  58. endforeach()
  59. foreach(flag ${common_flags} ${cxx_flags})
  60. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
  61. endforeach()
  62. endif()
  63. if(APPLE)
  64. # CMake has no special support for Objective-C as a distinct language but
  65. # enabling modules and other clang extensions would apply even to regular C++
  66. # sources which is nonportable. Keep these flags separate to avoid misuse.
  67. set(
  68. OBJC_FLAGS
  69. -Werror=deprecated-objc-isa-usage
  70. -Werror=non-modular-include-in-framework-module
  71. -Werror=objc-root-class
  72. -Wblock-capture-autoreleasing
  73. -Wimplicit-atomic-properties
  74. -Wnon-modular-include-in-framework-module
  75. -fobjc-arc
  76. -fmodules
  77. -fno-autolink
  78. -F${FIREBASE_INSTALL_DIR}/Frameworks
  79. )
  80. endif(APPLE)