Skip to content
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

New downloads! #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
  •  
  •  
  •  
504 changes: 504 additions & 0 deletions absl/CMake/AbseilDll.cmake

Large diffs are not rendered by default.

230 changes: 164 additions & 66 deletions absl/CMake/AbseilHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

include(CMakeParseArguments)
include(AbseilConfigureCopts)
include(AbseilDll)
include(AbseilInstallDirs)

# The IDE folder for Abseil that will be used if Abseil is included in a CMake
Expand Down Expand Up @@ -80,95 +81,173 @@ function(absl_cc_library)
${ARGN}
)

if(NOT ABSL_CC_LIB_TESTONLY OR ABSL_RUN_TESTS)
if(ABSL_ENABLE_INSTALL)
set(_NAME "${ABSL_CC_LIB_NAME}")
else()
set(_NAME "absl_${ABSL_CC_LIB_NAME}")
if(ABSL_CC_LIB_TESTONLY AND NOT ABSL_RUN_TESTS)
return()
endif()

if(ABSL_ENABLE_INSTALL)
set(_NAME "${ABSL_CC_LIB_NAME}")
else()
set(_NAME "absl_${ABSL_CC_LIB_NAME}")
endif()

# Check if this is a header-only library
# Note that as of February 2019, many popular OS's (for example, Ubuntu
# 16.04 LTS) only come with cmake 3.5 by default. For this reason, we can't
# use list(FILTER...)
set(ABSL_CC_SRCS "${ABSL_CC_LIB_SRCS}")
foreach(src_file IN LISTS ABSL_CC_SRCS)
if(${src_file} MATCHES ".*\\.(h|inc)")
list(REMOVE_ITEM ABSL_CC_SRCS "${src_file}")
endif()
endforeach()

# Check if this is a header-only library
# Note that as of February 2019, many popular OS's (for example, Ubuntu
# 16.04 LTS) only come with cmake 3.5 by default. For this reason, we can't
# use list(FILTER...)
set(ABSL_CC_SRCS "${ABSL_CC_LIB_SRCS}")
foreach(src_file IN LISTS ABSL_CC_SRCS)
if(${src_file} MATCHES ".*\\.(h|inc)")
list(REMOVE_ITEM ABSL_CC_SRCS "${src_file}")
endif()
endforeach()
if("${ABSL_CC_SRCS}" STREQUAL "")
if("${ABSL_CC_SRCS}" STREQUAL "")
set(ABSL_CC_LIB_IS_INTERFACE 1)
else()
set(ABSL_CC_LIB_IS_INTERFACE 0)
endif()

# Determine this build target's relationship to the DLL. It's one of four things:
# 1. "dll" -- This target is part of the DLL
# 2. "dll_dep" -- This target is not part of the DLL, but depends on the DLL.
# Note that we assume any target not in the DLL depends on the
# DLL. This is not a technical necessity but a convenience
# which happens to be true, because nearly every target is
# part of the DLL.
# 3. "shared" -- This is a shared library, perhaps on a non-windows platform
# where DLL doesn't make sense.
# 4. "static" -- This target does not depend on the DLL and should be built
# statically.
if (${ABSL_BUILD_DLL})
absl_internal_dll_contains(TARGET ${_NAME} OUTPUT _in_dll)
if (${_in_dll})
# This target should be replaced by the DLL
set(_build_type "dll")
set(ABSL_CC_LIB_IS_INTERFACE 1)
else()
set(ABSL_CC_LIB_IS_INTERFACE 0)
# Building a DLL, but this target is not part of the DLL
set(_build_type "dll_dep")
endif()
elseif(BUILD_SHARED_LIBS)
set(_build_type "shared")
else()
set(_build_type "static")
endif()

if(NOT ABSL_CC_LIB_IS_INTERFACE)
if(NOT ABSL_CC_LIB_IS_INTERFACE)
if(${_build_type} STREQUAL "dll_dep")
# This target depends on the DLL. When adding dependencies to this target,
# any depended-on-target which is contained inside the DLL is replaced
# with a dependency on the DLL.
add_library(${_NAME} STATIC "")
target_sources(${_NAME} PRIVATE ${ABSL_CC_LIB_SRCS} ${ABSL_CC_LIB_HDRS})
target_include_directories(${_NAME}
PUBLIC
$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS}>
$<INSTALL_INTERFACE:${ABSL_INSTALL_INCLUDEDIR}>
absl_internal_dll_targets(
DEPS ${ABSL_CC_LIB_DEPS}
OUTPUT _dll_deps
)
target_compile_options(${_NAME}
PRIVATE ${ABSL_CC_LIB_COPTS})
target_link_libraries(${_NAME}
PUBLIC ${ABSL_CC_LIB_DEPS}
PUBLIC ${_dll_deps}
PRIVATE
${ABSL_CC_LIB_LINKOPTS}
${ABSL_DEFAULT_LINKOPTS}
)
target_compile_definitions(${_NAME} PUBLIC ${ABSL_CC_LIB_DEFINES})

# Add all Abseil targets to a a folder in the IDE for organization.
if(ABSL_CC_LIB_PUBLIC)
set_property(TARGET ${_NAME} PROPERTY FOLDER ${ABSL_IDE_FOLDER})
elseif(ABSL_CC_LIB_TESTONLY)
set_property(TARGET ${_NAME} PROPERTY FOLDER ${ABSL_IDE_FOLDER}/test)
if (ABSL_CC_LIB_TESTONLY)
set(_gtest_link_define "GTEST_LINKED_AS_SHARED_LIBRARY=1")
else()
set_property(TARGET ${_NAME} PROPERTY FOLDER ${ABSL_IDE_FOLDER}/internal)
set(_gtest_link_define)
endif()

# INTERFACE libraries can't have the CXX_STANDARD property set
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD ${ABSL_CXX_STANDARD})
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)

# When being installed, we lose the absl_ prefix. We want to put it back
# to have properly named lib files. This is a no-op when we are not being
# installed.
set_target_properties(${_NAME} PROPERTIES
OUTPUT_NAME "absl_${_NAME}"
target_compile_definitions(${_NAME}
PUBLIC
ABSL_CONSUME_DLL
"${_gtest_link_define}"
)
else()
# Generating header-only library
add_library(${_NAME} INTERFACE)
target_include_directories(${_NAME}
INTERFACE
$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS}>
$<INSTALL_INTERFACE:${ABSL_INSTALL_INCLUDEDIR}>
)

elseif(${_build_type} STREQUAL "static" OR ${_build_type} STREQUAL "shared")
add_library(${_NAME} "")
target_sources(${_NAME} PRIVATE ${ABSL_CC_LIB_SRCS} ${ABSL_CC_LIB_HDRS})
target_link_libraries(${_NAME}
INTERFACE
${ABSL_CC_LIB_DEPS}
${ABSL_CC_LIB_LINKOPTS}
${ABSL_DEFAULT_LINKOPTS}
PUBLIC ${ABSL_CC_LIB_DEPS}
PRIVATE
${ABSL_CC_LIB_LINKOPTS}
${ABSL_DEFAULT_LINKOPTS}
)
target_compile_definitions(${_NAME} INTERFACE ${ABSL_CC_LIB_DEFINES})
else()
message(FATAL_ERROR "Invalid build type: ${_build_type}")
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)
install(TARGETS ${_NAME} EXPORT ${PROJECT_NAME}Targets
RUNTIME DESTINATION ${ABSL_INSTALL_BINDIR}
LIBRARY DESTINATION ${ABSL_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${ABSL_INSTALL_LIBDIR}
# Linker language can be inferred from sources, but in the case of DLLs we
# don't have any .cc files so it would be ambiguous. We could set it
# explicitly only in the case of DLLs but, because "CXX" is always the
# correct linker language for static or for shared libraries, we set it
# unconditionally.
set_property(TARGET ${_NAME} PROPERTY LINKER_LANGUAGE "CXX")

target_include_directories(${_NAME}
PUBLIC
"$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS}>"
$<INSTALL_INTERFACE:${ABSL_INSTALL_INCLUDEDIR}>
)
target_compile_options(${_NAME}
PRIVATE ${ABSL_CC_LIB_COPTS})
target_compile_definitions(${_NAME} PUBLIC ${ABSL_CC_LIB_DEFINES})

# Add all Abseil targets to a a folder in the IDE for organization.
if(ABSL_CC_LIB_PUBLIC)
set_property(TARGET ${_NAME} PROPERTY FOLDER ${ABSL_IDE_FOLDER})
elseif(ABSL_CC_LIB_TESTONLY)
set_property(TARGET ${_NAME} PROPERTY FOLDER ${ABSL_IDE_FOLDER}/test)
else()
set_property(TARGET ${_NAME} PROPERTY FOLDER ${ABSL_IDE_FOLDER}/internal)
endif()

# INTERFACE libraries can't have the CXX_STANDARD property set
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD ${ABSL_CXX_STANDARD})
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)

# When being installed, we lose the absl_ prefix. We want to put it back
# to have properly named lib files. This is a no-op when we are not being
# installed.
if(ABSL_ENABLE_INSTALL)
set_target_properties(${_NAME} PROPERTIES
OUTPUT_NAME "absl_${_NAME}"
)
endif()
else()
# Generating header-only library
add_library(${_NAME} INTERFACE)
target_include_directories(${_NAME}
INTERFACE
"$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS}>"
$<INSTALL_INTERFACE:${ABSL_INSTALL_INCLUDEDIR}>
)

add_library(absl::${ABSL_CC_LIB_NAME} ALIAS ${_NAME})
if (${_build_type} STREQUAL "dll")
set(ABSL_CC_LIB_DEPS abseil_dll)
endif()

target_link_libraries(${_NAME}
INTERFACE
${ABSL_CC_LIB_DEPS}
${ABSL_CC_LIB_LINKOPTS}
${ABSL_DEFAULT_LINKOPTS}
)
target_compile_definitions(${_NAME} INTERFACE ${ABSL_CC_LIB_DEFINES})
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)
install(TARGETS ${_NAME} EXPORT ${PROJECT_NAME}Targets
RUNTIME DESTINATION ${ABSL_INSTALL_BINDIR}
LIBRARY DESTINATION ${ABSL_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${ABSL_INSTALL_LIBDIR}
)
endif()

add_library(absl::${ABSL_CC_LIB_NAME} ALIAS ${_NAME})
endfunction()

# absl_cc_test()
Expand Down Expand Up @@ -221,23 +300,42 @@ function(absl_cc_test)
)

set(_NAME "absl_${ABSL_CC_TEST_NAME}")

add_executable(${_NAME} "")
target_sources(${_NAME} PRIVATE ${ABSL_CC_TEST_SRCS})
target_include_directories(${_NAME}
PUBLIC ${ABSL_COMMON_INCLUDE_DIRS}
PRIVATE ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}
)
target_compile_definitions(${_NAME}
PUBLIC ${ABSL_CC_TEST_DEFINES}
)

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

# Replace dependencies on targets inside the DLL with abseil_dll itself.
absl_internal_dll_targets(
DEPS ${ABSL_CC_TEST_DEPS}
OUTPUT ABSL_CC_TEST_DEPS
)
else()
target_compile_definitions(${_NAME}
PUBLIC
${ABSL_CC_TEST_DEFINES}
)
endif()
target_compile_options(${_NAME}
PRIVATE ${ABSL_CC_TEST_COPTS}
)

target_link_libraries(${_NAME}
PUBLIC ${ABSL_CC_TEST_DEPS}
PRIVATE ${ABSL_CC_TEST_LINKOPTS}
)
# Add all Abseil targets to a a folder in the IDE for organization.
# Add all Abseil targets to a folder in the IDE for organization.
set_property(TARGET ${_NAME} PROPERTY FOLDER ${ABSL_IDE_FOLDER}/test)

set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD ${ABSL_CXX_STANDARD})
Expand Down
10 changes: 10 additions & 0 deletions absl/CMake/Googletest/DownloadGTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ configure_file(
${CMAKE_BINARY_DIR}/googletest-download/CMakeLists.txt
)

set(ABSL_SAVE_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
set(ABSL_SAVE_CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
if (BUILD_SHARED_LIBS)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGTEST_CREATE_SHARED_LIBRARY=1")
endif()

# Configure and build the downloaded googletest source
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
Expand All @@ -22,6 +29,9 @@ if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()

set(CMAKE_CXX_FLAGS ${ABSL_SAVE_CMAKE_CXX_FLAGS})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ABSL_SAVE_CMAKE_RUNTIME_OUTPUT_DIRECTORY})

# Prevent overriding the parent project's compiler/linker settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

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

```cmake
cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.5)
project(my_project)

set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ ${CMAKE_CXX_FLAGS}")

if(MSVC)
# /wd4005 macro-redefinition
# /wd4068 unknown pragma
# /wd4244 conversion from 'type1' to 'type2'
# /wd4267 conversion from 'size_t' to 'type2'
# /wd4800 force value to bool 'true' or 'false' (performance warning)
add_compile_options(/wd4005 /wd4068 /wd4244 /wd4267 /wd4800)
add_definitions(/DNOMINMAX /DWIN32_LEAN_AND_MEAN=1 /D_CRT_SECURE_NO_WARNINGS)
endif()
# Pick the C++ standard to compile with.
# Abseil currently supports C++11, C++14, and C++17.
set(CMAKE_CXX_STANDARD 11)

add_subdirectory(abseil-cpp)

Expand Down Expand Up @@ -93,13 +85,15 @@ https://github.com/abseil/abseil-cpp/issues/109 for more information.
Here's a non-exhaustive list of Abseil CMake public targets:

```cmake
absl::base
absl::algorithm
absl::base
absl::debugging
absl::flat_hash_map
absl::flags
absl::memory
absl::meta
absl::numeric
absl::random
absl::strings
absl::synchronization
absl::time
Expand Down
18 changes: 7 additions & 11 deletions absl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ cmake_policy(SET CMP0048 NEW)

project(absl CXX)

# Output directory is correct by default for most build setups. However, when
# building Abseil as a DLL, it is important to have the DLL in the same
# directory as the executable using it. Thus, we put all executables in a single
# /bin directory.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# when absl is included as subproject (i.e. using add_subdirectory(abseil-cpp))
# in the source tree of a project that uses it, install rules are disabled.
if(NOT "^${CMAKE_SOURCE_DIR}$" STREQUAL "^${PROJECT_SOURCE_DIR}$")
Expand All @@ -47,6 +53,7 @@ list(APPEND CMAKE_MODULE_PATH

include(AbseilInstallDirs)
include(CMakePackageConfigHelpers)
include(AbseilDll)
include(AbseilHelpers)


Expand Down Expand Up @@ -110,17 +117,6 @@ endif()
add_subdirectory(absl)

if(ABSL_ENABLE_INSTALL)
# absl:lts-remove-begin(system installation is supported for LTS releases)
# We don't support system-wide installation
list(APPEND SYSTEM_INSTALL_DIRS "/usr/local" "/usr" "/opt/" "/opt/local" "c:/Program Files/${PROJECT_NAME}")
if(NOT DEFINED CMAKE_INSTALL_PREFIX OR CMAKE_INSTALL_PREFIX IN_LIST SYSTEM_INSTALL_DIRS)
message(WARNING "\
The default and system-level install directories are unsupported except in LTS \
releases of Abseil. Please set CMAKE_INSTALL_PREFIX to install Abseil in your \
source or build tree directly.\
")
endif()
# absl:lts-remove-end

# install as a subdirectory only
install(EXPORT ${PROJECT_NAME}Targets
Expand Down
Loading