compiler_setup.cmake 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. -Wcomma
  50. )
  51. endif()
  52. if(NINJA)
  53. # If building under Ninja, disable tty detection and force color output
  54. if(CXX_CLANG OR CXX_GNU)
  55. list(APPEND common_flags -fdiagnostics-color)
  56. endif()
  57. endif()
  58. endif()
  59. if(APPLE)
  60. # CMake has no special support for Objective-C as a distinct language but
  61. # enabling modules and other clang extensions would apply even to regular C++
  62. # sources which is nonportable. Keep these flags separate to avoid misuse.
  63. set(
  64. OBJC_FLAGS
  65. -Werror=deprecated-objc-isa-usage
  66. -Werror=non-modular-include-in-framework-module
  67. -Werror=objc-root-class
  68. -Wblock-capture-autoreleasing
  69. -Wimplicit-atomic-properties
  70. -Wnon-modular-include-in-framework-module
  71. -fobjc-arc
  72. -fmodules
  73. -fno-autolink
  74. -F${FIREBASE_INSTALL_DIR}/Frameworks
  75. )
  76. endif()
  77. if(MSVC)
  78. set(
  79. common_flags
  80. # Cut down on symbol cruft in windows.h
  81. /DWIN32_LEAN_AND_MEAN=1
  82. /DNOMINMAX=1
  83. # Specify at least Windows Vista/Server 2008 (required by gRPC)
  84. /D_WIN32_WINNT=0x600
  85. # Disable warnings that can't be easily addressed or are ignored by
  86. # upstream projects.
  87. # unary minus operator applied to unsigned type, result still unsigned
  88. /wd4146
  89. # character cannot be represented in the current code page
  90. /wd4566
  91. )
  92. endif()
  93. foreach(flag ${common_flags} ${c_flags})
  94. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
  95. endforeach()
  96. foreach(flag ${common_flags} ${cxx_flags})
  97. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
  98. endforeach()
  99. foreach(flag ${common_flags} ${c_flags})
  100. list(APPEND FIREBASE_C_FLAGS ${flag})
  101. endforeach()
  102. foreach(flag ${common_flags} ${cxx_flags})
  103. list(APPEND FIREBASE_CXX_FLAGS ${flag})
  104. endforeach()