aboutsummaryrefslogtreecommitdiff
path: root/contrib/native/client/src/protobuf/CMakeLists.txt
blob: b113234c7eba3513cf16177ca282fd0e635630c3 (plain)
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
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Find Protobufs
find_package(Protobuf REQUIRED)
include_directories(${PROTOBUF_INCLUDE_DIR})

#Generate Protobuf code

set (PROTO_SRC_FILES
    ${CMAKE_BINARY_DIR}/protobuf/BitControl.proto
    ${CMAKE_BINARY_DIR}/protobuf/Coordination.proto
    ${CMAKE_BINARY_DIR}/protobuf/GeneralRPC.proto
    ${CMAKE_BINARY_DIR}/protobuf/Types.proto
    ${CMAKE_BINARY_DIR}/protobuf/UserBitShared.proto
    ${CMAKE_BINARY_DIR}/protobuf/BitData.proto
    ${CMAKE_BINARY_DIR}/protobuf/ExecutionProtos.proto
    ${CMAKE_BINARY_DIR}/protobuf/SchemaDef.proto
    ${CMAKE_BINARY_DIR}/protobuf/User.proto
    )

PROTOBUF_GENERATE_CPP(GenProtoSources GenProtoHeaders ${PROTO_SRC_FILES})

set (PROTO_CPPSRC_FILES
    ${CMAKE_CURRENT_SOURCE_DIR}/BitControl.pb.cc
    ${CMAKE_CURRENT_SOURCE_DIR}/Coordination.pb.cc
    ${CMAKE_CURRENT_SOURCE_DIR}/GeneralRPC.pb.cc
    ${CMAKE_CURRENT_SOURCE_DIR}/Types.pb.cc
    ${CMAKE_CURRENT_SOURCE_DIR}/UserBitShared.pb.cc
    ${CMAKE_CURRENT_SOURCE_DIR}/BitData.pb.cc
    ${CMAKE_CURRENT_SOURCE_DIR}/ExecutionProtos.pb.cc
    ${CMAKE_CURRENT_SOURCE_DIR}/SchemaDef.pb.cc
    ${CMAKE_CURRENT_SOURCE_DIR}/User.pb.cc
    )

set (PROTO_HDR_DIR ${CMAKE_CURRENT_SOURCE_DIR})

set (PROTO_CPPHDR_FILES
    ${PROTO_HDR_DIR}/BitControl.pb.h
    ${PROTO_HDR_DIR}/Coordination.pb.h
    ${PROTO_HDR_DIR}/GeneralRPC.pb.h
    ${PROTO_HDR_DIR}/UserBitShared.pb.h
    ${PROTO_HDR_DIR}/BitData.pb.h
    ${PROTO_HDR_DIR}/ExecutionProtos.pb.h
    ${PROTO_HDR_DIR}/SchemaDef.pb.h
    ${PROTO_HDR_DIR}/User.pb.h
    )

set (PROTO_INC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../include/drill/protobuf)

set (PROTO_CPPINC_FILES
    ${PROTO_INC_DIR}/Types.pb.h
    )

set(ProtoIncludes ${PROTO_CPPINC_FILES} )
set(ProtoSources ${PROTO_CPPSRC_FILES} )
set(ProtoHeaders ${PROTO_CPPHDR_FILES})
include_directories(${PROTO_INC_DIR})
include_directories(${PROTO_HDR_DIR})

set(ProtoHeadersDir ${PROTO_HDR_DIR} PARENT_SCOPE)
set(ProtoIncludesDir ${PROTO_INC_DIR} PARENT_SCOPE)

#
#   TARGETS
#

#Preprocess to fix protobuf .proto definitions
SET (SRCDIR ${PROJECT_SOURCE_DIR}/../../../protocol/src/main/protobuf )
SET (TARGDIR ${CMAKE_BINARY_DIR}/protobuf)
SET (FNAME Types.proto)
SET (CPPSRCDIR ${CMAKE_BINARY_DIR}/src/protobuf)
SET (CPPDESTDIR ${PROJECT_SOURCE_DIR}/src/protobuf)
SET (CPPINCDIR ${PROJECT_SOURCE_DIR}/src/include/drill/protobuf)

add_custom_target(fixProtobufs
    COMMAND ${PROJECT_SOURCE_DIR}/scripts/fixProtodefs.sh ${SRCDIR} ${TARGDIR} ${FNAME}
    )

add_custom_target(genProtobufs DEPENDS ${GenProtoSources} fixProtobufs)

# copy protobuf CPP files to destinations in the source tree
add_custom_target(cpProtobufs
    COMMAND ${PROJECT_SOURCE_DIR}/scripts/cpProtofiles.sh ${CPPSRCDIR} ${CPPDESTDIR} ${CPPINCDIR}
    )

#message("ProtoSources =  ${ProtoSources}" )
#message("ProtoHeaders =  ${ProtoHeaders}" )
#message("ProtoIncludes =  ${ProtoIncludes}" )

add_library(protomsgs STATIC ${ProtoSources} ${ProtoHeaders} ${ProtoIncludes} )
#set linker properties. The first time around, the protobufs generated files may not exist
# and CMAKE will not be able to determine the linker type.
SET_TARGET_PROPERTIES(protomsgs PROPERTIES LINKER_LANGUAGE C)

add_dependencies(cpProtobufs genProtobufs)