compiler_setup.cmake 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. include(compiler_id)
  16. # We use C++11
  17. set(CMAKE_CXX_STANDARD 11)
  18. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  19. set(CMAKE_CXX_EXTENSIONS OFF)
  20. if(CMAKE_GENERATOR STREQUAL "Ninja")
  21. set(NINJA ON)
  22. endif()
  23. if(CXX_CLANG OR CXX_GNU)
  24. set(
  25. common_flags
  26. -Wall -Wextra -Werror
  27. # Be super pedantic about format strings
  28. -Wformat
  29. # Avoid use of uninitialized values
  30. -Wuninitialized
  31. -fno-common
  32. # Delete unused things
  33. -Wunused-function -Wunused-value -Wunused-variable
  34. )
  35. set(
  36. cxx_flags
  37. -Wreorder -Werror=reorder
  38. )
  39. set(
  40. c_flags
  41. -Wstrict-prototypes
  42. )
  43. if(CXX_CLANG)
  44. list(
  45. APPEND common_flags
  46. -Wconditional-uninitialized -Werror=return-type -Winfinite-recursion -Wmove
  47. -Wrange-loop-analysis -Wunreachable-code
  48. # Options added to match apple recommended project settings
  49. # TODO(wilhuff): re-enable -Wcomma once Abseil fixes the definition of
  50. # ABSL_ASSERT upstream
  51. -Wno-comma
  52. )
  53. endif()
  54. if(NINJA)
  55. # If building under Ninja, disable tty detection and force color output
  56. if(CXX_CLANG OR CXX_GNU)
  57. list(APPEND common_flags -fdiagnostics-color)
  58. endif()
  59. endif()
  60. endif()
  61. if(APPLE)
  62. # CMake has no special support for Objective-C as a distinct language but
  63. # enabling modules and other clang extensions would apply even to regular C++
  64. # sources which is nonportable. Keep these flags separate to avoid misuse.
  65. set(
  66. OBJC_FLAGS
  67. -Werror=deprecated-objc-isa-usage
  68. -Werror=non-modular-include-in-framework-module
  69. -Werror=objc-root-class
  70. -Wblock-capture-autoreleasing
  71. -Wimplicit-atomic-properties
  72. -Wnon-modular-include-in-framework-module
  73. -fobjc-arc
  74. -fmodules
  75. -fno-autolink
  76. -F${FIREBASE_INSTALL_DIR}/Frameworks
  77. )
  78. endif()
  79. if(MSVC)
  80. set(
  81. common_flags
  82. # Cut down on symbol cruft in windows.h
  83. /DWIN32_LEAN_AND_MEAN=1
  84. /DNOMINMAX=1
  85. # Specify at least Windows Vista/Server 2008 (required by gRPC)
  86. /D_WIN32_WINNT=0x600
  87. # Disable warnings that can't be easily addressed or are ignored by
  88. # upstream projects.
  89. # unary minus operator applied to unsigned type, result still unsigned
  90. /wd4146
  91. # character cannot be represented in the current code page
  92. /wd4566
  93. )
  94. endif()
  95. foreach(flag ${common_flags} ${c_flags})
  96. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
  97. endforeach()
  98. foreach(flag ${common_flags} ${cxx_flags})
  99. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
  100. endforeach()
  101. foreach(flag ${common_flags} ${c_flags})
  102. list(APPEND FIREBASE_C_FLAGS ${flag})
  103. endforeach()
  104. foreach(flag ${common_flags} ${cxx_flags})
  105. list(APPEND FIREBASE_CXX_FLAGS ${flag})
  106. endforeach()