• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Copyright 2017 The Abseil Authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      https://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17# Most widely used distributions have cmake 3.5 or greater available as of March
18# 2019.  A notable exception is RHEL-7 (CentOS7).  You can install a current
19# version of CMake by first installing Extra Packages for Enterprise Linux
20# (https://fedoraproject.org/wiki/EPEL#Extra_Packages_for_Enterprise_Linux_.28EPEL.29)
21# and then issuing `yum install cmake3` on the command line.
22cmake_minimum_required(VERSION 3.5)
23
24# Compiler id for Apple Clang is now AppleClang.
25cmake_policy(SET CMP0025 NEW)
26
27# if command can use IN_LIST
28cmake_policy(SET CMP0057 NEW)
29
30# Project version variables are the empty std::string if version is unspecified
31cmake_policy(SET CMP0048 NEW)
32
33project(absl CXX)
34
35# Output directory is correct by default for most build setups. However, when
36# building Abseil as a DLL, it is important to have the DLL in the same
37# directory as the executable using it. Thus, we put all executables in a single
38# /bin directory.
39set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
40
41# when absl is included as subproject (i.e. using add_subdirectory(abseil-cpp))
42# in the source tree of a project that uses it, install rules are disabled.
43if(NOT "^${CMAKE_SOURCE_DIR}$" STREQUAL "^${PROJECT_SOURCE_DIR}$")
44  set(ABSL_ENABLE_INSTALL FALSE)
45else()
46  set(ABSL_ENABLE_INSTALL TRUE)
47endif()
48
49list(APPEND CMAKE_MODULE_PATH
50  ${CMAKE_CURRENT_LIST_DIR}/CMake
51  ${CMAKE_CURRENT_LIST_DIR}/absl/copts
52)
53
54include(AbseilInstallDirs)
55include(CMakePackageConfigHelpers)
56include(AbseilDll)
57include(AbseilHelpers)
58
59
60##
61## Using absl targets
62##
63## all public absl targets are
64## exported with the absl:: prefix
65##
66## e.g absl::base absl::synchronization absl::strings ....
67##
68## DO NOT rely on the internal targets outside of the prefix
69
70
71# include current path
72list(APPEND ABSL_COMMON_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR})
73
74if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
75  set(ABSL_USING_CLANG ON)
76else()
77  set(ABSL_USING_CLANG OFF)
78endif()
79
80# find dependencies
81## pthread
82find_package(Threads REQUIRED)
83
84option(ABSL_USE_GOOGLETEST_HEAD
85  "If ON, abseil will download HEAD from googletest at config time." OFF)
86
87option(ABSL_RUN_TESTS "If ON, Abseil tests will be run." OFF)
88
89if(${ABSL_RUN_TESTS})
90  # enable CTest.  This will set BUILD_TESTING to ON unless otherwise specified
91  # on the command line
92  include(CTest)
93  enable_testing()
94endif()
95
96## check targets
97if(BUILD_TESTING)
98
99  if(${ABSL_USE_GOOGLETEST_HEAD})
100    include(CMake/Googletest/DownloadGTest.cmake)
101    set(absl_gtest_src_dir ${CMAKE_BINARY_DIR}/googletest-src)
102    set(absl_gtest_build_dir ${CMAKE_BINARY_DIR}/googletest-build)
103  endif()
104
105  check_target(gtest)
106  check_target(gtest_main)
107  check_target(gmock)
108
109  list(APPEND ABSL_TEST_COMMON_LIBRARIES
110    gtest_main
111    gtest
112    gmock
113    ${CMAKE_THREAD_LIBS_INIT}
114  )
115endif()
116
117add_subdirectory(absl)
118
119if(ABSL_ENABLE_INSTALL)
120
121  # install as a subdirectory only
122  install(EXPORT ${PROJECT_NAME}Targets
123    NAMESPACE absl::
124    DESTINATION "${ABSL_INSTALL_CONFIGDIR}"
125  )
126
127  configure_package_config_file(
128    CMake/abslConfig.cmake.in
129    "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
130    INSTALL_DESTINATION "${ABSL_INSTALL_CONFIGDIR}"
131  )
132  install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
133    DESTINATION "${ABSL_INSTALL_CONFIGDIR}"
134  )
135
136  # Abseil only has a version in LTS releases.  This mechanism is accomplished
137  # Abseil's internal Copybara (https://github.com/google/copybara) workflows and
138  # isn't visible in the CMake buildsystem itself.
139  if(absl_VERSION)
140    write_basic_package_version_file(
141      "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
142      COMPATIBILITY ExactVersion
143    )
144
145    install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
146      DESTINATION ${ABSL_INSTALL_CONFIGDIR}
147    )
148  endif()  # absl_VERSION
149
150  install(DIRECTORY absl
151    DESTINATION ${ABSL_INSTALL_INCLUDEDIR}
152    FILES_MATCHING
153      PATTERN "*.inc"
154      PATTERN "*.h"
155  )
156endif()  # ABSL_ENABLE_INSTALL
157