generated from userver-framework/service_template
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCMakeLists.txt
175 lines (151 loc) · 5.8 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
cmake_minimum_required(VERSION 3.12)
project(realmedium_sample CXX)
# Adding userver dependency
find_package(userver COMPONENTS core postgresql chaotic QUIET)
if(NOT userver_FOUND) # Fallback to subdirectory usage
# Enable userver libraries that are needed in this project
set(USERVER_FEATURE_POSTGRESQL ON CACHE BOOL "" FORCE)
# Compatibility mode: some systems don't support these features
set(USERVER_FEATURE_CRYPTOPP_BLAKE2 OFF CACHE BOOL "" FORCE)
set(USERVER_FEATURE_GRPC_CHANNELZ OFF CACHE BOOL "" FORCE)
set(USERVER_FEATURE_REDIS_HI_MALLOC ON CACHE BOOL "" FORCE)
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/userver)
message(STATUS "Using userver framework from third_party/userver")
add_subdirectory(third_party/userver)
else()
message(FATAL_ERROR "Either install the userver or provide a path to it")
endif()
endif()
userver_setup_environment()
set(CPP_JWT_BUILD_TESTS OFF)
set(CPP_JWT_BUILD_EXAMPLES OFF)
add_subdirectory(third_party/cpp-jwt)
option(JWT_BUILD_EXAMPLES OFF)
# Common sources
add_library(${PROJECT_NAME}_objs OBJECT
src/cache/articles_cache.hpp
src/cache/articles_cache.cpp
src/cache/comments_cache.cpp
src/cache/comments_cache.hpp
src/handlers/profiles/profiles.cpp
src/handlers/profiles/profiles.hpp
src/handlers/users/users.cpp
src/handlers/users/users.hpp
src/handlers/tags/tags.cpp
src/handlers/tags/tags.hpp
src/handlers/users/users_login.cpp
src/handlers/users/users_login.hpp
src/handlers/users/user_get.cpp
src/handlers/users/user_get.hpp
src/handlers/users/user_put.cpp
src/handlers/users/user_put.hpp
src/handlers/profiles/profiles_follow.cpp
src/handlers/profiles/profiles_follow.hpp
src/handlers/profiles/profiles_follow_delete.cpp
src/handlers/profiles/profiles_follow_delete.hpp
src/handlers/articles/articles_slug_delete.cpp
src/handlers/articles/articles_slug_delete.hpp
src/handlers/articles/articles_slug_get.cpp
src/handlers/articles/articles_slug_get.hpp
src/handlers/articles/articles_slug_put.cpp
src/handlers/articles/articles_slug_put.hpp
src/handlers/articles/articles_get.cpp
src/handlers/articles/articles_get.hpp
src/handlers/articles/articles_post.cpp
src/handlers/articles/articles_post.hpp
src/handlers/articles/feed_articles.hpp
src/handlers/articles/feed_articles.cpp
src/handlers/articles/articles_favorite.cpp
src/handlers/articles/articles_favorite.hpp
src/handlers/comments/comment_delete.cpp
src/handlers/comments/comment_delete.hpp
src/handlers/comments/comment_post.cpp
src/handlers/comments/comment_post.hpp
src/handlers/comments/comments_get.cpp
src/handlers/comments/comments_get.hpp
src/handlers/auth/auth_bearer.hpp
src/handlers/auth/auth_bearer.cpp
src/dto/article.cpp
src/dto/article.hpp
src/dto/profile.cpp
src/dto/profile.hpp
src/dto/comment.hpp
src/dto/comment.cpp
src/db/sql.hpp
src/db/types.hpp
src/models/user.hpp
src/models/user.cpp
src/models/comment.hpp
src/models/comment.cpp
src/models/article.hpp
src/models/article.cpp
src/models/profile.hpp
src/models/profile.cpp
src/validators/user_validators.hpp
src/validators/user_validators.cpp
src/validators/length_validator.hpp
src/validators/length_validator.cpp
src/utils/random.hpp
src/utils/random.cpp
src/utils/errors.hpp
src/utils/errors.cpp
src/utils/make_error.hpp
src/utils/make_error.cpp
src/utils/jwt.hpp
src/utils/jwt.cpp
src/utils/slugify.hpp
src/utils/slugify.cpp
src/handlers/articles/articles_unfavorite.cpp
src/handlers/articles/articles_unfavorite.hpp
src/dto/filter.hpp
src/dto/filter.cpp
src/validators/validators.cpp
src/validators/article_validators.cpp
src/validators/article_validators.hpp
)
include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_link_libraries(${PROJECT_NAME}_objs PUBLIC userver::core userver::postgresql)
file(GLOB_RECURSE SCHEMAS ${CMAKE_CURRENT_SOURCE_DIR}/docs/*.yaml)
userver_target_generate_chaotic(${PROJECT_NAME}-chgen
ARGS
-n "/components/schemas/([^/]*)/=real_medium::handlers::{0}"
-f "(.*)={0}"
--clang-format=
--generate-serializers
OUTPUT_DIR
${CMAKE_CURRENT_BINARY_DIR}/src
SCHEMAS
${SCHEMAS}
RELATIVE_TO
${CMAKE_CURRENT_SOURCE_DIR}
)
target_link_libraries(${PROJECT_NAME}_objs PUBLIC ${PROJECT_NAME}-chgen)
target_include_directories(${PROJECT_NAME}_objs PUBLIC cpp-jwt)
target_link_libraries(${PROJECT_NAME}_objs PUBLIC cpp-jwt)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
find_package(ICU 4.4 COMPONENTS io i18n REQUIRED)
target_include_directories(${PROJECT_NAME}_objs PUBLIC ${ICU_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME}_objs PUBLIC ${ICU_LIBRARIES})
# The Service
add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_objs)
# Unit Tests
add_executable(${PROJECT_NAME}_unittest
src/utils/slugify_test.cpp
src/validators/validator_test.cpp
)
target_link_libraries(${PROJECT_NAME}_unittest PRIVATE ${PROJECT_NAME}_objs userver::utest)
add_google_tests(${PROJECT_NAME}_unittest)
# Functional Tests
add_subdirectory(tests)
# Install
include(GNUInstallDirs)
if(DEFINED ENV{PREFIX})
message(STATUS "Set install prefix: $ENV{PREFIX}")
file(TO_CMAKE_PATH "$ENV{PREFIX}" PREFIX_PATH)
set(CMAKE_INSTALL_PREFIX ${PREFIX_PATH})
endif()
set(CONFIG_JWT ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_SYSCONFDIR}/${PROJECT_NAME}/jwt_config.json)
file(GLOB CONFIGS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/configs/*.yaml ${CMAKE_CURRENT_SOURCE_DIR}/configs/*.json)
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${PROJECT_NAME})
install(FILES ${CONFIGS_FILES} DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/${PROJECT_NAME} COMPONENT ${PROJECT_NAME})