forked from awslabs/aws-lambda-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
141 lines (115 loc) · 4.45 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
cmake_minimum_required(VERSION 3.9)
set(CMAKE_CXX_STANDARD 11)
project(aws-lambda-runtime
VERSION 0.0.0
LANGUAGES CXX)
option(ENABLE_LTO "Enables link-time optimization, requires compiler support." OFF)
option(ENABLE_TESTS "Enables building the test project, requires AWS C++ SDK." OFF)
option(ENABLE_SANITIZERS "Enables ASan and UBSan." OFF)
add_library(${PROJECT_NAME}
"src/logging.cpp"
"src/runtime.cpp"
"src/backward.cpp"
"${CMAKE_CURRENT_BINARY_DIR}/version.cpp"
)
set_target_properties(${PROJECT_NAME} PROPERTIES
SOVERSION 0
VERSION ${PROJECT_VERSION}-dev)
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
if (ENABLE_SANITIZERS)
target_compile_options(${PROJECT_NAME} PUBLIC "-fsanitize=address,undefined")
target_link_libraries(${PROJECT_NAME} PUBLIC "-fsanitize=address,undefined")
endif()
if (ENABLE_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT has_lto OUTPUT lto_check_output)
if(has_lto)
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "Link-time optimization (LTO) is not supported: ${lto_check_output}")
endif()
endif()
find_package(CURL REQUIRED)
if (CMAKE_VERSION VERSION_LESS 3.12)
target_link_libraries(${PROJECT_NAME} PRIVATE ${CURL_LIBRARIES})
else()
target_link_libraries(${PROJECT_NAME} PRIVATE CURL::libcurl)
endif()
target_include_directories(${PROJECT_NAME} PRIVATE ${CURL_INCLUDE_DIRS})
find_package(Backtrace REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE ${Backtrace_LIBRARIES})
target_compile_options(${PROJECT_NAME} PRIVATE
"-fno-exceptions"
"-fno-rtti"
"-fvisibility=hidden"
"-fvisibility-inlines-hidden"
"-Wall"
"-Wextra"
"-Werror"
"-Wconversion"
"-Wno-sign-conversion")
find_library(DW_LIB NAMES dw)
if (NOT DW_LIB STREQUAL DW_LIB-NOTFOUND)
message("-- Enhanced stack-traces are enabled via libdw: ${DW_LIB}")
target_compile_definitions(${PROJECT_NAME} PRIVATE "BACKWARD_HAS_DW=1")
target_link_libraries(${PROJECT_NAME} PUBLIC "${DW_LIB}")
else()
find_library(BFD_LIB NAMES bfd)
if (NOT BFD_LIB STREQUAL BFD_LIB-NOTFOUND)
message("-- Enhanced stack-traces are enabled via libbfd: ${BFD_LIB}")
target_compile_definitions(${PROJECT_NAME} PRIVATE "BACKWARD_HAS_BFD=1")
target_link_libraries(${PROJECT_NAME} PRIVATE "${BFD_LIB}")
endif()
endif()
if (LOG_VERBOSITY)
target_compile_definitions(${PROJECT_NAME} PRIVATE "AWS_LAMBDA_LOG=${LOG_VERBOSITY}")
elseif(CMAKE_BUILD_TYPE STREQUAL Debug)
target_compile_definitions(${PROJECT_NAME} PRIVATE "AWS_LAMBDA_LOG=3")
else ()
target_compile_definitions(${PROJECT_NAME} PRIVATE "AWS_LAMBDA_LOG=0")
endif()
#tests
if (ENABLE_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
#versioning
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/src/version.cpp.in"
"${CMAKE_CURRENT_BINARY_DIR}/version.cpp"
NEWLINE_STYLE LF)
include (CMakePackageConfigHelpers)
write_basic_package_version_file("${PROJECT_NAME}-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
# installation
install(FILES "include/aws/http/response.h"
DESTINATION "include/aws/http")
install(FILES
"include/aws/lambda-runtime/runtime.h"
"include/aws/lambda-runtime/version.h"
"include/aws/lambda-runtime/outcome.h"
DESTINATION "include/aws/lambda-runtime")
install(FILES "include/aws/logging/logging.h"
DESTINATION "include/aws/logging")
include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
@ONLY)
export(EXPORT "${PROJECT_NAME}-targets" NAMESPACE AWS::)
install(EXPORT "${PROJECT_NAME}-targets"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake/"
NAMESPACE AWS::)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake/")
install(PROGRAMS "${CMAKE_CURRENT_SOURCE_DIR}/packaging/packager"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake/")