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