-
Notifications
You must be signed in to change notification settings - Fork 445
/
Abseil.cmake
76 lines (66 loc) · 2.97 KB
/
Abseil.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
macro(p4c_obtain_abseil)
option(
P4C_USE_PREINSTALLED_ABSEIL
"Look for a preinstalled version of Abseil in the system instead of installing the library using FetchContent."
OFF
)
# If P4C_USE_PREINSTALLED_ABSEIL is ON just try to find a preinstalled version of Abseil.
if(P4C_USE_PREINSTALLED_ABSEIL)
if(ENABLE_ABSEIL_STATIC)
set(SAVED_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
endif()
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
find_package(absl REQUIRED)
if(ENABLE_ABSEIL_STATIC)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${SAVED_CMAKE_FIND_LIBRARY_SUFFIXES})
endif()
else()
set(P4C_ABSEIL_VERSION "20240116.1")
message(STATUS "Fetching Abseil version ${P4C_ABSEIL_VERSION} for P4C...")
# Unity builds do not work for Abseil...
set(CMAKE_UNITY_BUILD_PREV ${CMAKE_UNITY_BUILD})
set(CMAKE_UNITY_BUILD OFF)
# Print out download state while setting up Abseil.
set(FETCHCONTENT_QUIET_PREV ${FETCHCONTENT_QUIET})
set(FETCHCONTENT_QUIET OFF)
set(ABSL_USE_EXTERNAL_GOOGLETEST ON)
set(ABSL_FIND_GOOGLETEST OFF)
set(ABSL_BUILD_TESTING OFF)
set(ABSL_ENABLE_INSTALL OFF)
set(ABSL_USE_SYSTEM_INCLUDES ON)
set(ABSL_PROPAGATE_CXX_STD ON)
FetchContent_Declare(
abseil
URL https://github.com/abseil/abseil-cpp/releases/download/${P4C_ABSEIL_VERSION}/abseil-cpp-${P4C_ABSEIL_VERSION}.tar.gz
URL_HASH SHA256=3c743204df78366ad2eaf236d6631d83f6bc928d1705dd0000b872e53b73dc6a
USES_TERMINAL_DOWNLOAD TRUE
GIT_PROGRESS TRUE
)
fetchcontent_makeavailable_but_exclude_install(abseil)
# Suppress warnings for all Abseil targets.
get_all_targets(ABSL_BUILD_TARGETS ${absl_SOURCE_DIR})
foreach(target ${ABSL_BUILD_TARGETS})
if(target MATCHES "absl_*")
# Do not suppress warnings for Abseil library targets that are aliased.
get_target_property(target_type ${target} TYPE)
if (NOT ${target_type} STREQUAL "INTERFACE_LIBRARY")
# We need this workaround because of https://github.com/abseil/abseil-cpp/issues/1664.
# TODO: Remove once the Abseil compilation issue is fixed.
if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 14)
target_compile_options(${target} PUBLIC "-mbmi")
endif()
target_compile_options(${target} PRIVATE "-Wno-error" "-w")
endif()
endif()
endforeach()
# TODO: Remove once the Abseil compilation issue is fixed.
if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 14)
message(WARNING "Compiling with GCC > 14. Adding -mbmi to Abseil targets, this may cause incompatibility with old CPUs.")
endif()
# Reset temporary variable modifications.
set(CMAKE_UNITY_BUILD ${CMAKE_UNITY_BUILD_PREV})
set(FETCHCONTENT_QUIET ${FETCHCONTENT_QUIET_PREV})
endif()
message(STATUS "Done with setting up Abseil for P4C.")
endmacro(p4c_obtain_abseil)