compiler_setup.cmake 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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_GENERATOR STREQUAL "Ninja")
  20. set(NINJA ON)
  21. endif()
  22. if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  23. set(CLANG ON)
  24. endif()
  25. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  26. set(GNU ON)
  27. endif()
  28. if(CLANG OR GNU)
  29. set(
  30. common_flags
  31. -Wall -Wextra -Werror
  32. # Be super pedantic about format strings
  33. -Wformat
  34. # Avoid use of uninitialized values
  35. -Wuninitialized
  36. -fno-common
  37. # Delete unused things
  38. -Wunused-function -Wunused-value -Wunused-variable
  39. )
  40. set(
  41. cxx_flags
  42. # Cut down on symbol clutter
  43. # TODO(wilhuff) try -fvisibility=hidden
  44. -fvisibility-inlines-hidden
  45. )
  46. set(
  47. c_flags
  48. -Wstrict-prototypes
  49. )
  50. if(CLANG)
  51. list(
  52. APPEND common_flags
  53. -Wconditional-uninitialized -Werror=return-type -Winfinite-recursion -Wmove
  54. -Wrange-loop-analysis -Wunreachable-code
  55. # Options added to match apple recommended project settings
  56. -Wcomma
  57. )
  58. endif()
  59. if(NINJA)
  60. # If building under Ninja, disable tty detection and force color output
  61. if(CLANG OR GNU)
  62. list(APPEND common_flags -fdiagnostics-color)
  63. endif()
  64. endif()
  65. foreach(flag ${common_flags} ${c_flags})
  66. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
  67. endforeach()
  68. foreach(flag ${common_flags} ${cxx_flags})
  69. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
  70. endforeach()
  71. endif()
  72. if(APPLE)
  73. # CMake has no special support for Objective-C as a distinct language but
  74. # enabling modules and other clang extensions would apply even to regular C++
  75. # sources which is nonportable. Keep these flags separate to avoid misuse.
  76. set(
  77. OBJC_FLAGS
  78. -Werror=deprecated-objc-isa-usage
  79. -Werror=non-modular-include-in-framework-module
  80. -Werror=objc-root-class
  81. -Wblock-capture-autoreleasing
  82. -Wimplicit-atomic-properties
  83. -Wnon-modular-include-in-framework-module
  84. -fobjc-arc
  85. -fmodules
  86. -fno-autolink
  87. -F${FIREBASE_INSTALL_DIR}/Frameworks
  88. )
  89. endif()