-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
97 lines (82 loc) · 3.19 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
cmake_minimum_required(VERSION 2.8.10)
project(pbconf CXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/lib)
include(FindProtobuf)
find_path(BRPC_INCLUDE_PATH NAMES brpc/server.h)
find_library(BRPC_LIB NAMES libbrpc.a brpc)
if ((NOT BRPC_INCLUDE_PATH) OR (NOT BRPC_LIB))
message(FATAL_ERROR "Fail to find brpc")
endif()
find_path(YAML_CPP_INCLUDE_PATH NAMES yaml-cpp/yaml.h)
find_library(YAML_CPP_LIB NAMES libyaml-cpp.a yaml-cpp)
if ((NOT YAML_CPP_INCLUDE_PATH) OR (NOT YAML_CPP_LIB))
message(FATAL_ERROR "Fail to find yaml-cpp")
endif()
find_path(HOCON_INCLUDE_PATH NAMES hocon/version.h)
find_library(HOCON_LIB NAMES libcpp-hocon.a cpp-hocon)
if ((NOT HOCON_INCLUDE_PATH) OR (NOT HOCON_LIB))
message(FATAL_ERROR "Fail to find hocon")
endif()
set(LEATHERMAN_COMPONENTS locale catch nowide util)
find_package(Leatherman REQUIRED COMPONENTS ${LEATHERMAN_COMPONENTS})
find_package(Boost 1.54 COMPONENTS log locale thread date_time chrono system program_options)
# Publish headers
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/pbconf/
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/output/include/pbconf/
FILES_MATCHING
PATTERN "*.h"
)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/output/include/
DESTINATION include
FILES_MATCHING
PATTERN "*.h"
)
# Publish libraries
file(GLOB_RECURSE PBCONF_LIB_SOURCES "${CMAKE_SOURCE_DIR}/src/pbconf/*.cpp")
add_library(pbconf STATIC ${PBCONF_LIB_SOURCES})
# demo
file(GLOB DEMO_PROTOS "${CMAKE_SOURCE_DIR}/src/example/proto/*.proto")
foreach(PROTO ${DEMO_PROTOS})
get_filename_component(PROTO_WE ${PROTO} NAME_WE)
list(APPEND PROTO_SRCS "${CMAKE_CURRENT_BINARY_DIR}/example/proto/${PROTO_WE}.pb.cc")
execute_process(
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} ${PROTO_FLAGS}
--cpp_out=${CMAKE_CURRENT_BINARY_DIR}
--proto_path=${PROTOBUF_INCLUDE_DIR}
--proto_path=${CMAKE_SOURCE_DIR}/src
--proto_path=${CMAKE_SOURCE_DIR}/src/example/proto/ ${PROTO}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
ERROR_VARIABLE PROTO_ERROR
RESULT_VARIABLE PROTO_RESULT
)
if (${PROTO_RESULT} EQUAL 0)
else ()
message (FATAL_ERROR "Fail to generate cpp of ${PROTO} : ${PROTO_ERROR}")
endif()
endforeach()
file(GLOB_RECURSE DEMO_SOURCES "${CMAKE_SOURCE_DIR}/src/example/*.cpp")
set(SOURCES
${DEMO_SOURCES}
${PROTO_SRCS}
)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/output/bin)
include_directories("${CMAKE_CURRENT_BINARY_DIR}/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/")
include_directories("${CMAKE_CURRENT_BINARY_DIR}/example/proto/")
include_directories(${Boost_INCLUDE_DIRS})
add_executable(demo ${SOURCES})
target_link_libraries(demo pbconf)
target_link_libraries(demo protobuf)
target_link_libraries(demo brpc)
target_link_libraries(demo yaml-cpp)
target_link_libraries(demo iconv)
target_link_libraries(demo ${LEATHERMAN_LIBRARIES})
target_link_libraries(demo ${Boost_LIBRARIES})
target_link_libraries(demo cpp-hocon)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/example/conf/
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/output/conf/
FILES_MATCHING
PATTERN "*"
)
# demo end