Skip to content

Import abseil-cpp source tag 20230802.0 #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
465 changes: 366 additions & 99 deletions CMake/AbseilDll.cmake

Large diffs are not rendered by default.

156 changes: 77 additions & 79 deletions CMake/AbseilHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ if(NOT DEFINED ABSL_IDE_FOLDER)
set(ABSL_IDE_FOLDER Abseil)
endif()

if(ABSL_USE_SYSTEM_INCLUDES)
set(ABSL_INTERNAL_INCLUDE_WARNING_GUARD SYSTEM)
else()
set(ABSL_INTERNAL_INCLUDE_WARNING_GUARD "")
endif()

# absl_cc_library()
#
# CMake function to imitate Bazel's cc_library rule.
Expand Down Expand Up @@ -83,8 +89,9 @@ function(absl_cc_library)
${ARGN}
)

if(NOT ABSL_CC_LIB_PUBLIC AND ABSL_CC_LIB_TESTONLY AND
NOT (BUILD_TESTING AND ABSL_BUILD_TESTING))
if(ABSL_CC_LIB_TESTONLY AND
NOT ((BUILD_TESTING AND ABSL_BUILD_TESTING) OR
(ABSL_BUILD_TEST_HELPERS AND ABSL_CC_LIB_PUBLIC)))
return()
endif()

Expand Down Expand Up @@ -125,10 +132,12 @@ function(absl_cc_library)
if (${ABSL_BUILD_DLL})
if(ABSL_ENABLE_INSTALL)
absl_internal_dll_contains(TARGET ${_NAME} OUTPUT _in_dll)
absl_internal_test_dll_contains(TARGET ${_NAME} OUTPUT _in_test_dll)
else()
absl_internal_dll_contains(TARGET ${ABSL_CC_LIB_NAME} OUTPUT _in_dll)
absl_internal_test_dll_contains(TARGET ${ABSL_CC_LIB_NAME} OUTPUT _in_test_dll)
endif()
if (${_in_dll})
if (${_in_dll} OR ${_in_test_dll})
# This target should be replaced by the DLL
set(_build_type "dll")
set(ABSL_CC_LIB_IS_INTERFACE 1)
Expand All @@ -143,35 +152,55 @@ function(absl_cc_library)
endif()

# Generate a pkg-config file for every library:
if((_build_type STREQUAL "static" OR _build_type STREQUAL "shared")
AND ABSL_ENABLE_INSTALL)
if(NOT ABSL_CC_LIB_TESTONLY)
if(absl_VERSION)
set(PC_VERSION "${absl_VERSION}")
else()
set(PC_VERSION "head")
endif()
foreach(dep ${ABSL_CC_LIB_DEPS})
if(${dep} MATCHES "^absl::(.*)")
# Join deps with commas.
if(ABSL_ENABLE_INSTALL)
if(absl_VERSION)
set(PC_VERSION "${absl_VERSION}")
else()
set(PC_VERSION "head")
endif()
if(NOT _build_type STREQUAL "dll")
set(LNK_LIB "${LNK_LIB} -labsl_${_NAME}")
endif()
foreach(dep ${ABSL_CC_LIB_DEPS})
if(${dep} MATCHES "^absl::(.*)")
# for DLL builds many libs are not created, but add
# the pkgconfigs nevertheless, pointing to the dll.
if(_build_type STREQUAL "dll")
# hide this MATCHES in an if-clause so it doesn't overwrite
# the CMAKE_MATCH_1 from (${dep} MATCHES "^absl::(.*)")
if(NOT PC_DEPS MATCHES "abseil_dll")
# Join deps with commas.
if(PC_DEPS)
set(PC_DEPS "${PC_DEPS},")
endif()
# don't duplicate dll-dep if it exists already
set(PC_DEPS "${PC_DEPS} abseil_dll = ${PC_VERSION}")
set(LNK_LIB "${LNK_LIB} -labseil_dll")
endif()
else()
# Join deps with commas.
if(PC_DEPS)
set(PC_DEPS "${PC_DEPS},")
endif()
set(PC_DEPS "${PC_DEPS} absl_${CMAKE_MATCH_1} = ${PC_VERSION}")
endif()
endforeach()
foreach(cflag ${ABSL_CC_LIB_COPTS})
if(${cflag} MATCHES "^(-Wno|/wd)")
# These flags are needed to suppress warnings that might fire in our headers.
set(PC_CFLAGS "${PC_CFLAGS} ${cflag}")
elseif(${cflag} MATCHES "^(-W|/w[1234eo])")
# Don't impose our warnings on others.
else()
set(PC_CFLAGS "${PC_CFLAGS} ${cflag}")
endif()
endforeach()
string(REPLACE ";" " " PC_LINKOPTS "${ABSL_CC_LIB_LINKOPTS}")
FILE(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/lib/pkgconfig/absl_${_NAME}.pc" CONTENT "\
endif()
endforeach()
foreach(cflag ${ABSL_CC_LIB_COPTS})
if(${cflag} MATCHES "^(-Wno|/wd)")
# These flags are needed to suppress warnings that might fire in our headers.
set(PC_CFLAGS "${PC_CFLAGS} ${cflag}")
elseif(${cflag} MATCHES "^(-W|/w[1234eo])")
# Don't impose our warnings on others.
elseif(${cflag} MATCHES "^-m")
# Don't impose CPU instruction requirements on others, as
# the code performs feature detection on runtime.
else()
set(PC_CFLAGS "${PC_CFLAGS} ${cflag}")
endif()
endforeach()
string(REPLACE ";" " " PC_LINKOPTS "${ABSL_CC_LIB_LINKOPTS}")
FILE(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/lib/pkgconfig/absl_${_NAME}.pc" CONTENT "\
prefix=${CMAKE_INSTALL_PREFIX}\n\
exec_prefix=\${prefix}\n\
libdir=${CMAKE_INSTALL_FULL_LIBDIR}\n\
Expand All @@ -182,11 +211,10 @@ Description: Abseil ${_NAME} library\n\
URL: https://abseil.io/\n\
Version: ${PC_VERSION}\n\
Requires:${PC_DEPS}\n\
Libs: -L\${libdir} ${PC_LINKOPTS} $<$<NOT:$<BOOL:${ABSL_CC_LIB_IS_INTERFACE}>>:-labsl_${_NAME}>\n\
Libs: -L\${libdir} $<$<NOT:$<BOOL:${ABSL_CC_LIB_IS_INTERFACE}>>:${LNK_LIB}> ${PC_LINKOPTS}\n\
Cflags: -I\${includedir}${PC_CFLAGS}\n")
INSTALL(FILES "${CMAKE_BINARY_DIR}/lib/pkgconfig/absl_${_NAME}.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()
INSTALL(FILES "${CMAKE_BINARY_DIR}/lib/pkgconfig/absl_${_NAME}.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()

if(NOT ABSL_CC_LIB_IS_INTERFACE)
Expand Down Expand Up @@ -239,7 +267,7 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
# unconditionally.
set_property(TARGET ${_NAME} PROPERTY LINKER_LANGUAGE "CXX")

target_include_directories(${_NAME}
target_include_directories(${_NAME} ${ABSL_INTERNAL_INCLUDE_WARNING_GUARD}
PUBLIC
"$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS}>"
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
Expand All @@ -258,21 +286,10 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
endif()

if(ABSL_PROPAGATE_CXX_STD)
# Abseil libraries require C++11 as the current minimum standard.
# Top-level application CMake projects should ensure a consistent C++
# standard for all compiled sources by setting CMAKE_CXX_STANDARD.
target_compile_features(${_NAME} PUBLIC cxx_std_11)
else()
# Note: This is legacy (before CMake 3.8) behavior. Setting the
# target-level CXX_STANDARD property to ABSL_CXX_STANDARD (which is
# initialized by CMAKE_CXX_STANDARD) should have no real effect, since
# that is the default value anyway.
#
# CXX_STANDARD_REQUIRED does guard against the top-level CMake project
# not having enabled CMAKE_CXX_STANDARD_REQUIRED (which prevents
# "decaying" to an older standard if the requested one isn't available).
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD ${ABSL_CXX_STANDARD})
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
# Abseil libraries require C++14 as the current minimum standard. When
# compiled with C++17 (either because it is the compiler's default or
# explicitly requested), then Abseil requires C++17.
target_compile_features(${_NAME} PUBLIC ${ABSL_INTERNAL_CXX_STD_FEATURE})
endif()

# When being installed, we lose the absl_ prefix. We want to put it back
Expand All @@ -281,13 +298,13 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
if(ABSL_ENABLE_INSTALL)
set_target_properties(${_NAME} PROPERTIES
OUTPUT_NAME "absl_${_NAME}"
SOVERSION "2206.0.0"
SOVERSION "2308.0.0"
)
endif()
else()
# Generating header-only library
add_library(${_NAME} INTERFACE)
target_include_directories(${_NAME}
target_include_directories(${_NAME} ${ABSL_INTERNAL_INCLUDE_WARNING_GUARD}
INTERFACE
"$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS}>"
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
Expand All @@ -306,19 +323,14 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
target_compile_definitions(${_NAME} INTERFACE ${ABSL_CC_LIB_DEFINES})

if(ABSL_PROPAGATE_CXX_STD)
# Abseil libraries require C++11 as the current minimum standard.
# Abseil libraries require C++14 as the current minimum standard.
# Top-level application CMake projects should ensure a consistent C++
# standard for all compiled sources by setting CMAKE_CXX_STANDARD.
target_compile_features(${_NAME} INTERFACE cxx_std_11)

# (INTERFACE libraries can't have the CXX_STANDARD property set, so there
# is no legacy behavior else case).
target_compile_features(${_NAME} INTERFACE ${ABSL_INTERNAL_CXX_STD_FEATURE})
endif()
endif()

# TODO currently we don't install googletest alongside abseil sources, so
# installed abseil can't be tested.
if(NOT ABSL_CC_LIB_TESTONLY AND ABSL_ENABLE_INSTALL)
if(ABSL_ENABLE_INSTALL)
install(TARGETS ${_NAME} EXPORT ${PROJECT_NAME}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down Expand Up @@ -384,14 +396,15 @@ function(absl_cc_test)
target_sources(${_NAME} PRIVATE ${ABSL_CC_TEST_SRCS})
target_include_directories(${_NAME}
PUBLIC ${ABSL_COMMON_INCLUDE_DIRS}
PRIVATE ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}
PRIVATE ${absl_gtest_src_dir}/googletest/include ${absl_gtest_src_dir}/googlemock/include
)

if (${ABSL_BUILD_DLL})
target_compile_definitions(${_NAME}
PUBLIC
${ABSL_CC_TEST_DEFINES}
ABSL_CONSUME_DLL
ABSL_CONSUME_TEST_DLL
GTEST_LINKED_AS_SHARED_LIBRARY=1
)

Expand All @@ -400,6 +413,10 @@ function(absl_cc_test)
DEPS ${ABSL_CC_TEST_DEPS}
OUTPUT ABSL_CC_TEST_DEPS
)
absl_internal_dll_targets(
DEPS ${ABSL_CC_TEST_LINKOPTS}
OUTPUT ABSL_CC_TEST_LINKOPTS
)
else()
target_compile_definitions(${_NAME}
PUBLIC
Expand All @@ -418,30 +435,11 @@ function(absl_cc_test)
set_property(TARGET ${_NAME} PROPERTY FOLDER ${ABSL_IDE_FOLDER}/test)

if(ABSL_PROPAGATE_CXX_STD)
# Abseil libraries require C++11 as the current minimum standard.
# Abseil libraries require C++14 as the current minimum standard.
# Top-level application CMake projects should ensure a consistent C++
# standard for all compiled sources by setting CMAKE_CXX_STANDARD.
target_compile_features(${_NAME} PUBLIC cxx_std_11)
else()
# Note: This is legacy (before CMake 3.8) behavior. Setting the
# target-level CXX_STANDARD property to ABSL_CXX_STANDARD (which is
# initialized by CMAKE_CXX_STANDARD) should have no real effect, since
# that is the default value anyway.
#
# CXX_STANDARD_REQUIRED does guard against the top-level CMake project
# not having enabled CMAKE_CXX_STANDARD_REQUIRED (which prevents
# "decaying" to an older standard if the requested one isn't available).
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD ${ABSL_CXX_STANDARD})
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
target_compile_features(${_NAME} PUBLIC ${ABSL_INTERNAL_CXX_STD_FEATURE})
endif()

add_test(NAME ${_NAME} COMMAND ${_NAME})
endfunction()


function(check_target my_target)
if(NOT TARGET ${my_target})
message(FATAL_ERROR " ABSL: compiling absl requires a ${my_target} CMake target in your project,
see CMake/README.md for more details")
endif(NOT TARGET ${my_target})
endfunction()
2 changes: 1 addition & 1 deletion CMake/Googletest/CMakeLists.txt.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8.2)
cmake_minimum_required(VERSION 3.10)

project(googletest-external NONE)

Expand Down
10 changes: 5 additions & 5 deletions CMake/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ section of your executable or of your library.<br>
Here is a short CMakeLists.txt example of an application project using Abseil.

```cmake
cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.10)
project(my_app_project)

# Pick the C++ standard to compile with.
# Abseil currently supports C++11, C++14, and C++17.
set(CMAKE_CXX_STANDARD 11)
# Abseil currently supports C++14, C++17, and C++20.
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_subdirectory(abseil-cpp)
Expand All @@ -62,7 +62,7 @@ will control Abseil library targets) is set to at least that minimum. For
example:

```cmake
cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.10)
project(my_lib_project)

# Leave C++ standard up to the root application, so set it only if this is the
Expand Down Expand Up @@ -170,7 +170,7 @@ And finally install:
cmake --build /temporary/build/abseil-cpp --target install
```

# CMake Option Synposis
# CMake Option Synopsis

## Enable Standard CMake Installation

Expand Down
2 changes: 1 addition & 1 deletion CMake/install_test_project/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# A simple CMakeLists.txt for testing cmake installation

cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.10)
project(absl_cmake_testing CXX)

add_executable(simple simple.cc)
Expand Down
Loading