forked from mircodz/loki-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
124 lines (104 loc) · 3.36 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
cmake_minimum_required(VERSION 3.12.4)
project(loki-cpp VERSION 0.4.0)
include(GNUInstallDirs)
# CMake Settings
set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY true)
# Project Settings
option(BUILD_SHARED_LIBS "Build libraries as shared" On)
option(BUILD_TESTS "Build unit testing" Off)
# Compiler Settings
set(CMAKE_CXX_COMPILER "/usr/bin/g++")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED On)
set(CMAKE_CXX_EXTENSIONS Off)
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os")
set(CMAKE_CXX_FLAGS_RELEASE "-O4")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
# Testing
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
file(GLOB SOURCES
${PROJECT_SOURCE_DIR}/src/agent.cpp
${PROJECT_SOURCE_DIR}/src/detail/utils.cpp
${PROJECT_SOURCE_DIR}/src/query.cpp
${PROJECT_SOURCE_DIR}/gen/github.com/gogo/protobuf/gogoproto/gogo.pb.cc
${PROJECT_SOURCE_DIR}/gen/google/protobuf/descriptor.pb.cc
${PROJECT_SOURCE_DIR}/gen/google/protobuf/timestamp.pb.cc
${PROJECT_SOURCE_DIR}/gen/logproto.pb.cc)
set(HEADERS
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/gen)
add_library(loki-cpp ${SOURCES})
target_include_directories(loki-cpp PRIVATE ${HEADERS})
target_compile_options(loki-cpp PRIVATE -Wall -Wextra)
find_package(Protobuf)
if(PROTOBUF_FOUND)
#find_package(snappy REQUIRED)
#if(SNAPPY_FOUND)
# target_link_libraries(loki-cpp ${Snappy_INCLUDE_DIR})
# include_directories(${Snappy_LIBRARIES})
#else()
# message(FATAL_ERROR "Could not find snappy")
#endif()
target_link_libraries(loki-cpp snappy)
target_link_libraries(loki-cpp ${PROTOBUF_LIBRARIES})
include_directories(${PROTOBUF_INCLUDE_DIRS})
# Compile .proto files
function(compile_proto _file)
execute_process(
COMMAND protoc
--cpp_out=${PROJECT_SOURCE_DIR}/gen
--proto_path=${PROJECT_SOURCE_DIR}/proto
${_file}
RESULT_VARIABLE result)
if(${result})
message("Error compiling protobuf schemas.")
endif()
endfunction()
set(PROTOBUF_PROTO
github.com/gogo/protobuf/gogoproto/gogo.proto
google/protobuf/descriptor.proto
google/protobuf/timestamp.proto
logproto.proto)
foreach(_file ${PROTOBUF_PROTO})
compile_proto(${_file})
endforeach()
else()
message("Could not find protobof")
endif()
find_package(CURL REQUIRED)
if(CURL_FOUND)
include_directories(${CURL_INCLUDE_DIR})
target_link_libraries(loki-cpp ${CURL_LIBRARIES})
else()
message(FATAL_ERROR "Could not find libcurl")
endif()
find_package(fmt REQUIRED)
IF(fmt_FOUND)
target_link_libraries(loki-cpp fmt::fmt)
else()
message(FATAL_ERROR "Could not find libfmt")
endif()
set(THREADS_PREFER_PTHREAD_FLAG On)
find_package(Threads REQUIRED)
if(Threads_FOUND)
target_link_libraries(loki-cpp Threads::Threads)
else()
message(FATAL_ERROR "Could not find proper threading library")
endif()
# Installation settings
set_target_properties(loki-cpp PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
PUBLIC_HEADER "include/builder.hpp;include/registry.hpp;include/agent.hpp"
PRIVATE_HEADER "include/detail/utils.hpp")
install(TARGETS loki-cpp
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION /usr/local/include/loki OPTIONAL
PRIVATE_HEADER DESTINATION /usr/local/include/loki/detail)
configure_file(loki-cpp.pc.in loki-cpp.pc @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/loki-cpp.pc
DESTINATION /usr/lib/pkgconfig)