-
Notifications
You must be signed in to change notification settings - Fork 48
/
CMakeLists.txt
129 lines (107 loc) · 3.39 KB
/
CMakeLists.txt
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.8)
project("fb303" LANGUAGES CXX C)
if (NOT DEFINED PACKAGE_VERSION)
set(PACKAGE_VERSION "1.0.0")
endif()
if (NOT DEFINED CPACK_GENERATOR)
set(CPACK_GENERATOR "RPM")
endif()
include(CPack)
option(PYTHON_EXTENSIONS
"Build Python bindings for fb303"
ON
)
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "setting C++ standard to C++${CMAKE_CXX_STANDARD}")
endif()
set(CMAKE_CXX_EXTENSIONS OFF)
# Explicitly enable coroutine support, since GCC does not enable it
# by default when targeting C++17.
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fcoroutines>)
endif()
set(INCLUDE_INSTALL_DIR include CACHE STRING
"The subdirectory where header files should be installed")
set(LIB_INSTALL_DIR lib CACHE STRING
"The subdirectory where libraries should be installed")
set(CMAKE_INSTALL_DIR lib/cmake/fb303 CACHE STRING
"The subdirectory where CMake package config files should be installed")
# CMake include directories
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake"
"${CMAKE_CURRENT_SOURCE_DIR}/build/fbcode_builder/CMake"
${CMAKE_MODULE_PATH})
find_package(Gflags REQUIRED)
find_package(Glog MODULE REQUIRED)
find_package(folly CONFIG REQUIRED)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(fmt CONFIG REQUIRED)
find_package(FBThrift CONFIG REQUIRED)
find_package(fizz CONFIG REQUIRED)
find_package(wangle CONFIG REQUIRED)
include(FBThriftLibrary)
add_subdirectory(fb303/thrift)
file(GLOB fb303_SOURCES fb303/*.cpp fb303/detail/*.cpp)
file(GLOB fb303_HEADERS fb303/*.h fb303/detail/*.h)
install(
DIRECTORY fb303
DESTINATION ${INCLUDE_INSTALL_DIR}
FILES_MATCHING PATTERN *.h
)
add_library(fb303 ${fb303_SOURCES} ${fb303_HEADERS})
if (BUILD_SHARED_LIBS)
set_property(TARGET fb303 PROPERTY VERSION ${PACKAGE_VERSION})
endif ()
target_include_directories(fb303 PUBLIC
${GFLAGS_INCLUDE_DIR}
${GLOG_INCLUDE_DIR}
${DOUBLE_CONVERSION_INCLUDE_DIR}
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>
)
target_link_libraries(fb303
fb303_thrift_cpp
Folly::folly
FBThrift::thrift
)
install(
TARGETS fb303
EXPORT fb303-exports
LIBRARY DESTINATION "${LIB_INSTALL_DIR}"
ARCHIVE DESTINATION "${LIB_INSTALL_DIR}"
)
# Install CMake package configuration files for fb303
include(CMakePackageConfigHelpers)
configure_package_config_file(
CMake/fb303-config.cmake.in
fb303-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_DIR}
PATH_VARS
INCLUDE_INSTALL_DIR
CMAKE_INSTALL_DIR
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/fb303-config.cmake
DESTINATION ${CMAKE_INSTALL_DIR}
)
install(
EXPORT fb303-exports
FILE fb303-targets.cmake
NAMESPACE fb303::
DESTINATION ${CMAKE_INSTALL_DIR}
)