-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
150 lines (119 loc) · 4.26 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# Copyright 2016 Carnegie Mellon University
#
# 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.2.0 FATAL_ERROR)
project(Storehouse)
option(BUILD_STATIC "" OFF)
enable_testing()
include(ExternalProject)
######################
### Setup ####
######################
# Verify C++11 support
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support.")
endif()
### Helper macros ####
MACRO(INSTALL_HEADERS_WITH_DIRECTORY HEADER_LIST)
FOREACH(HEADER ${${HEADER_LIST}})
STRING(REGEX MATCH "(.*)[/\\]" DIR ${HEADER})
INSTALL(FILES ${HEADER} DESTINATION include/${DIR})
ENDFOREACH(HEADER)
ENDMACRO(INSTALL_HEADERS_WITH_DIRECTORY)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
set(GLOBAL_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(THIRDPARTY_SOURCE_DIR "${CMAKE_SOURCE_DIR}/thirdparty")
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
endif()
###### DEPENDENCIES #######
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
if(NOT APPLE AND UNIX)
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -pthread -ldl -lrt")
endif()
###### PROJECT LIBRARIES #######
set(PYBIND11_PYTHON_VERSION 3)
find_package(pybind11 REQUIRED)
find_package(GFlags REQUIRED)
find_package(Glog REQUIRED)
find_package(CURL REQUIRED)
set(GTEST_INCLUDE_DIRS
"${GLOBAL_OUTPUT_PATH}/googletest/include")
set(GTEST_LIBRARIES
"${GLOBAL_OUTPUT_PATH}/googletest/lib/libgtest.a")
set(GTEST_LIB_MAIN
"${GLOBAL_OUTPUT_PATH}/googletest/lib/libgtest_main.a")
set(STOREHOUSE_LIBRARIES
"${CUSTOM_LIBRARIES}"
"${GLOG_LIBRARIES}"
"${CURL_LIBRARIES}"
"${OPENSSL_LIBRARIES}"
"${STOREHOUSE_LIBRARIES}")
include_directories(
"."
"${GLOG_INCLUDE_DIRS}"
"${GTEST_INCLUDE_DIRS}")
set(AWS_MODULES core s3)
set(AWS_TARGETS)
foreach(MODULE ${AWS_MODULES})
find_package(aws-cpp-sdk-${MODULE} REQUIRED CONFIG
PATHS
"thirdparty/build/bin/aws-sdk-cpp/lib/cmake/aws-cpp-sdk-${MODULE}"
"thirdparty/build/bin/aws-sdk-cpp/lib64/cmake/aws-cpp-sdk-${MODULE}")
list(APPEND AWS_TARGETS aws-cpp-sdk-${MODULE})
endforeach()
add_subdirectory(storehouse)
set(SOURCE_FILES
storehouse/storage_backend.cpp
storehouse/storage_config.cpp
storehouse/util.cpp
$<TARGET_OBJECTS:posix_storage_lib>
$<TARGET_OBJECTS:s3_storage_lib>)
if(BUILD_STATIC)
set(DEPS storehouse_deps.o)
add_custom_command(
OUTPUT ${DEPS}
COMMAND ar -x $<TARGET_FILE:aws-cpp-sdk-core>
COMMAND ar -x $<TARGET_FILE:aws-cpp-sdk-s3>
COMMAND ld -r *.o -o ${DEPS}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
add_library(storehouse STATIC ${DEPS} ${SOURCE_FILES})
target_link_libraries(storehouse PUBLIC ${STOREHOUSE_LIBRARIES})
else()
add_library(storehouse SHARED ${SOURCE_FILES})
target_link_libraries(storehouse PUBLIC ${STOREHOUSE_LIBRARIES})
target_link_libraries(storehouse PRIVATE ${AWS_TARGETS})
endif()
get_target_property(AWS_CORE_INC aws-cpp-sdk-core INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(AWS_S3_INC aws-cpp-sdk-s3 INTERFACE_INCLUDE_DIRECTORIES)
message(${AWS_S3_INC})
include_directories(${AWS_CORE_INC} ${AWS_S3_INC})
set(PUBLIC_HEADER_FILES
storehouse/storage_backend.h
storehouse/storage_config.h)
install(TARGETS storehouse
EXPORT StorehouseTarget
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)
configure_file(cmake/StorehouseConfig.cmake.in
"${PROJECT_BINARY_DIR}/cmake/StorehouseConfig.cmake" @ONLY)
install(FILES "${PROJECT_BINARY_DIR}/cmake/StorehouseConfig.cmake"
DESTINATION share/storehouse)
install_headers_with_directory(PUBLIC_HEADER_FILES)
install(EXPORT StorehouseTarget
DESTINATION share/storehouse)