-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
executable file
·151 lines (117 loc) · 5.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
141
142
143
144
145
146
147
148
149
150
151
# ----------------------------------------------------------------
# Copyright (c) Coding Nerd
# Licensed under the Apache License, Version 2.0
# See LICENSE in the project root for license information.
# ----------------------------------------------------------------
cmake_minimum_required(VERSION 3.5.1)
include(cmake/common.cmake)
project(neptune-profiler-proto)
# INSTALL default: off
option(INSTALL "Install neptune binaries and files" OFF)
# doc default: on
option(DOC "Generate and update the doc files" ON)
# cpp default: on
option(CPP "Generate and update the COO files" ON)
find_program(GRPC_CPP_PLUGIN "grpc_cpp_plugin")
if(NOT GRPC_CPP_PLUGIN)
message(FATAL_ERROR "grpc_cpp_plugin not found!")
endif()
# bypass the cmake bug, QNX do not have pthread
find_package(Threads)
if(CPP)
# Find Protobuf installation
# Looks for protobuf-config.cmake file installed by Protobuf's cmake installation.
set(protobuf_MODULE_COMPATIBLE TRUE)
find_package(Protobuf CONFIG REQUIRED)
message(STATUS "Using protobuf ${Protobuf_VERSION}")
set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
set(_REFLECTION gRPC::grpc++_reflection)
# Find gRPC installation
# Looks for gRPCConfig.cmake file installed by gRPC's cmake installation.
find_package(gRPC CONFIG REQUIRED)
message(STATUS "Using gRPC ${gRPC_VERSION}")
set(_GRPC_GRPCPP gRPC::grpc++)
set(TARGET_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
set(CMAKE_TARGET_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cpp)
message(DEBUG "CMAKE_CURRENT_LIST_DIR=${CMAKE_CURRENT_LIST_DIR}")
message(DEBUG "CMAKE_TARGET_DIRECTORY=${CMAKE_TARGET_DIRECTORY}")
file(GLOB PROTO_FILES ${CMAKE_CURRENT_LIST_DIR}/proto/*.proto)
file(GLOB GRPC_PROTO_FILES ${CMAKE_CURRENT_LIST_DIR}/proto/api/*.proto)
message(DEBUG "PROTO_FILES=${PROTO_FILES}")
# Replace .proto -> .pb.cc
string(REGEX REPLACE "${CMAKE_CURRENT_LIST_DIR}/proto" "${CMAKE_TARGET_DIRECTORY}" SRC_FILES ${PROTO_FILES})
string(REGEX REPLACE "[.]proto" ".pb.cc;" SRC_FILES ${SRC_FILES})
# Replace .proto -> .pb.h
# string(REGEX REPLACE "${CMAKE_CURRENT_LIST_DIR}/proto" "${CMAKE_TARGET_DIRECTORY}" INC_FILES ${PROTO_FILES})
# string(REGEX REPLACE "[.]proto" ".pb.h;" INC_FILES ${INC_FILES})
# Replace .proto -> .grpc.pb.cc
string(REGEX REPLACE "${CMAKE_CURRENT_LIST_DIR}/proto" "${CMAKE_TARGET_DIRECTORY}" SRC_GRPC_FILES ${GRPC_PROTO_FILES})
string(REGEX REPLACE "[.]proto" ".grpc.pb.cc;" SRC_GRPC_FILES ${SRC_GRPC_FILES})
# Replace .proto -> .grpc.pb.cc
string(REGEX REPLACE "${CMAKE_CURRENT_LIST_DIR}/proto" "${CMAKE_TARGET_DIRECTORY}" SRC_API_FILES ${GRPC_PROTO_FILES})
string(REGEX REPLACE "[.]proto" ".pb.cc;" SRC_API_FILES ${SRC_API_FILES})
# Replace .proto -> grpc.pb.h
# string(REGEX REPLACE "${CMAKE_CURRENT_LIST_DIR}/proto" "${CMAKE_TARGET_DIRECTORY}" INC_GRPC_FILES ${GRPC_PROTO_FILES})
# string(REGEX REPLACE "[.]proto" ".grpc.pb.h;" INC_GRPC_FILES ${INC_GRPC_FILES})
message(DEBUG "SRC_FILES=${SRC_FILES}")
message(DEBUG "SRC_GRPC_FILES=${SRC_GRPC_FILES}")
file(MAKE_DIRECTORY "${CMAKE_TARGET_DIRECTORY}/api")
message(STATUS "${CMAKE_TARGET_DIRECTORY}")
foreach(proto ${PROTO_FILES})
execute_process(COMMAND ${PROTOC} --cpp_out "${CMAKE_TARGET_DIRECTORY}" -I "${CMAKE_CURRENT_LIST_DIR}/proto" "${proto}"
RESULT_VARIABLE PROTOC_RESULT)
if(NOT PROTOC_RESULT EQUAL "0")
message(FATAL_ERROR "protoc failed with ${PROTOC_RESULT}, please check")
endif()
endforeach(proto)
foreach(proto ${GRPC_PROTO_FILES})
execute_process(COMMAND ${PROTOC} --grpc_out "${CMAKE_TARGET_DIRECTORY}"
--cpp_out "${CMAKE_TARGET_DIRECTORY}"
-I "${CMAKE_CURRENT_LIST_DIR}/proto" --plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN} "${proto}"
RESULT_VARIABLE PROTOC_RESULT)
if(NOT PROTOC_RESULT EQUAL "0")
message(FATAL_ERROR "protoc failed with ${PROTOC_RESULT}, please check")
endif()
endforeach(proto)
# execute_process(COMMAND ${PROTOC} --grpc_out "${CMAKE_TARGET_DIRECTORY}/api"
# -I"${CMAKE_CURRENT_LIST_DIR}/proto"
# --plugin=protoc-gen-grpc="${GRPC_CPP_PLUGIN}"
# "${CMAKE_CURRENT_LIST_DIR}/proto/api/*.proto"
# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
# RESULT_VARIABLE GRPC_RESULT)
# if(NOT GRPC_RESULT EQUAL "0")
# message(FATAL_ERROR "grpc failed with ${PROTOC_RESULT}, please check")
# endif()
include_directories("${CMAKE_CURRENT_BINARY_DIR}/cpp")
add_library(${PROJECT_NAME} SHARED
${SRC_FILES}
${SRC_GRPC_FILES}
${SRC_API_FILES}
)
target_link_libraries(${PROJECT_NAME}
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF})
get_target_property(TARGET_LIBRARIES ${PROJECT_NAME} LINK_LIBRARIES)
message(${TARGET_LIBRARIES})
install(
DIRECTORY ${CMAKE_TARGET_DIRECTORY}
DESTINATION ${TARGET_DIRECTORY}
FILES_MATCHING # install only matched files
PATTERN "*.h" # select header files
)
install(TARGETS ${PROJECT_NAME} DESTINATION ${TARGET_DIRECTORY}/cpp/${CMAKE_SYSTEM_PROCESSOR}/lib)
endif(CPP)
if(DOC)
set(DOC_FILE "${CMAKE_CURRENT_LIST_DIR}/doc/${PROJECT_NAME}-doc.md")
add_custom_command(
OUTPUT ${DOC_FILE}
COMMAND ${PROTOC}
ARGS --doc_out=markdown,${PROJECT_NAME}-doc.md:${CMAKE_CURRENT_LIST_DIR}/doc
-I "${CMAKE_CURRENT_LIST_DIR}/proto/"
-I "${CMAKE_CURRENT_LIST_DIR}/api/proto/"
"${CMAKE_CURRENT_LIST_DIR}/proto/*.proto"
"${CMAKE_CURRENT_LIST_DIR}/proto/api/*.proto"
DEPENDS "${CMAKE_CURRENT_LIST_DIR}/proto/*.proto" "${CMAKE_CURRENT_LIST_DIR}/proto/api/*.proto")
add_custom_target(doc ALL DEPENDS ${DOC_FILE})
endif(DOC)