AbseilConfigureCopts.cmake 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # See absl/copts/copts.py and absl/copts/generate_copts.py
  2. include(GENERATED_AbseilCopts)
  3. set(ABSL_DEFAULT_LINKOPTS "")
  4. if (BUILD_SHARED_LIBS AND (MSVC OR ABSL_BUILD_MONOLITHIC_SHARED_LIBS))
  5. set(ABSL_BUILD_DLL TRUE)
  6. set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
  7. else()
  8. set(ABSL_BUILD_DLL FALSE)
  9. endif()
  10. if(APPLE AND CMAKE_CXX_COMPILER_ID MATCHES [[Clang]])
  11. # Some CMake targets (not known at the moment of processing) could be set to
  12. # compile for multiple architectures as specified by the OSX_ARCHITECTURES
  13. # property, which is target-specific. We should neither inspect nor rely on
  14. # any CMake property or variable to detect an architecture, in particular:
  15. #
  16. # - CMAKE_OSX_ARCHITECTURES
  17. # is just an initial value for OSX_ARCHITECTURES; set too early.
  18. #
  19. # - OSX_ARCHITECTURES
  20. # is a per-target property; targets could be defined later, and their
  21. # properties could be modified any time later.
  22. #
  23. # - CMAKE_SYSTEM_PROCESSOR
  24. # does not reflect multiple architectures at all.
  25. #
  26. # When compiling for multiple architectures, a build system can invoke a
  27. # compiler either
  28. #
  29. # - once: a single command line for multiple architectures (Ninja build)
  30. # - twice: two command lines per each architecture (Xcode build system)
  31. #
  32. # If case of Xcode, it would be possible to set an Xcode-specific attributes
  33. # like XCODE_ATTRIBUTE_OTHER_CPLUSPLUSFLAGS[arch=arm64] or similar.
  34. #
  35. # In both cases, the viable strategy is to pass all arguments at once, allowing
  36. # the compiler to dispatch arch-specific arguments to a designated backend.
  37. set(ABSL_RANDOM_RANDEN_COPTS "")
  38. foreach(_arch IN ITEMS "x86_64" "arm64")
  39. string(TOUPPER "${_arch}" _arch_uppercase)
  40. string(REPLACE "X86_64" "X64" _arch_uppercase ${_arch_uppercase})
  41. foreach(_flag IN LISTS ABSL_RANDOM_HWAES_${_arch_uppercase}_FLAGS)
  42. list(APPEND ABSL_RANDOM_RANDEN_COPTS "-Xarch_${_arch}" "${_flag}")
  43. endforeach()
  44. endforeach()
  45. # If a compiler happens to deal with an argument for a currently unused
  46. # architecture, it will warn about an unused command line argument.
  47. option(ABSL_RANDOM_RANDEN_COPTS_WARNING OFF
  48. "Warn if one of ABSL_RANDOM_RANDEN_COPTS is unused")
  49. if(ABSL_RANDOM_RANDEN_COPTS AND NOT ABSL_RANDOM_RANDEN_COPTS_WARNING)
  50. list(APPEND ABSL_RANDOM_RANDEN_COPTS "-Wno-unused-command-line-argument")
  51. endif()
  52. elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64")
  53. if (MSVC)
  54. set(ABSL_RANDOM_RANDEN_COPTS "${ABSL_RANDOM_HWAES_MSVC_X64_FLAGS}")
  55. else()
  56. set(ABSL_RANDOM_RANDEN_COPTS "${ABSL_RANDOM_HWAES_X64_FLAGS}")
  57. endif()
  58. elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm.*|aarch64")
  59. if (CMAKE_SIZEOF_VOID_P STREQUAL "8")
  60. set(ABSL_RANDOM_RANDEN_COPTS "${ABSL_RANDOM_HWAES_ARM64_FLAGS}")
  61. elseif(CMAKE_SIZEOF_VOID_P STREQUAL "4")
  62. set(ABSL_RANDOM_RANDEN_COPTS "${ABSL_RANDOM_HWAES_ARM32_FLAGS}")
  63. else()
  64. message(WARNING "Value of CMAKE_SIZEOF_VOID_P (${CMAKE_SIZEOF_VOID_P}) is not supported.")
  65. endif()
  66. else()
  67. set(ABSL_RANDOM_RANDEN_COPTS "")
  68. endif()
  69. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  70. set(ABSL_DEFAULT_COPTS "${ABSL_GCC_FLAGS}")
  71. set(ABSL_TEST_COPTS "${ABSL_GCC_TEST_FLAGS}")
  72. elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") # MATCHES so we get both Clang and AppleClang
  73. if(MSVC)
  74. # clang-cl is half MSVC, half LLVM
  75. set(ABSL_DEFAULT_COPTS "${ABSL_CLANG_CL_FLAGS}")
  76. set(ABSL_TEST_COPTS "${ABSL_CLANG_CL_TEST_FLAGS}")
  77. else()
  78. set(ABSL_DEFAULT_COPTS "${ABSL_LLVM_FLAGS}")
  79. set(ABSL_TEST_COPTS "${ABSL_LLVM_TEST_FLAGS}")
  80. endif()
  81. elseif(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
  82. # IntelLLVM is similar to Clang, with some additional flags.
  83. if(MSVC)
  84. # clang-cl is half MSVC, half LLVM
  85. set(ABSL_DEFAULT_COPTS "${ABSL_CLANG_CL_FLAGS}")
  86. set(ABSL_TEST_COPTS "${ABSL_CLANG_CL_TEST_FLAGS}")
  87. else()
  88. set(ABSL_DEFAULT_COPTS "${ABSL_LLVM_FLAGS}")
  89. set(ABSL_TEST_COPTS "${ABSL_LLVM_TEST_FLAGS}")
  90. endif()
  91. elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
  92. set(ABSL_DEFAULT_COPTS "${ABSL_MSVC_FLAGS}")
  93. set(ABSL_TEST_COPTS "${ABSL_MSVC_TEST_FLAGS}")
  94. set(ABSL_DEFAULT_LINKOPTS "${ABSL_MSVC_LINKOPTS}")
  95. else()
  96. message(WARNING "Unknown compiler: ${CMAKE_CXX_COMPILER}. Building with no default flags")
  97. set(ABSL_DEFAULT_COPTS "")
  98. set(ABSL_TEST_COPTS "")
  99. endif()
  100. set(ABSL_CXX_STANDARD "${CMAKE_CXX_STANDARD}")