blob: 0e77387f415d2416310d9d48bd3357fe938e7a10 [file] [log] [blame]
# Copyright 2018 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
###############################################################################
#
# This CMake file is intended to be used in order to build Tink as part of the
# Cobalt stand-alone build. It is not intended to work to build Tink
# in isolation and it is not intended to build Tink as part of the
# Fuchsia build.
###############################################################################
cmake_minimum_required (VERSION 3.0.0)
PROJECT (tink)
set(TINK_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
set(TINK_PROTO_DIR ${TINK_INCLUDE_DIR}/proto)
# Runs the protoc compiler on a set of .proto files to generate c++ files.
# Compiles the c++ files into a static library.
#
# Args:
# LIB_NAME: The name of the CMake target for the generated static library
# HDRS_OUT: A variable in which to write the list of names of the generated
# header files
# <remaining args>: List of simple names of .proto files to include from the
# current source directory. The names should not include
# ".proto"
# example usage:
#
# tink_make_protobuf_cpp_lib(report_master_proto_lib
# REPORT_PROTO_HDRS
# report_master report_internal)
#
# This will compile the files report_master.proto and report_internal.proto in
# the current source directory and generate a static library with a
# target name of report_master_proto_lib containing the ReportMaster gRPC
# service as well as the compiled protos from report_internal. The variable
# REPORT_PROTO_HDRS will contain the list of strings:
# { <some-path>/report_internal.grpc.pb.h
# <some-path>/report_internal.pb.h
# <some-path>/report_master.grpc.pb.h
# <some-path>/report_master.pb.h}
# (Note that report_internal.proto does not contain a gRPC service definition
# so that report_internal.grpc.pb.h is essentially empty.)
macro(tink_make_protobuf_cpp_lib LIB_NAME HDRS_OUT)
set(_protofiles)
set(_generated_srcs)
set(_generated_hdrs)
foreach(name ${ARGN})
list(APPEND _protofiles "${CMAKE_CURRENT_SOURCE_DIR}/${name}.proto")
list(APPEND _generated_srcs "${TINK_INCLUDE_DIR}/${name}.pb.cc")
list(APPEND _generated_hdrs "${TINK_INCLUDE_DIR}/${name}.pb.h")
set_source_files_properties("${TINK_INCLUDE_DIR}/${name}.pb.cc" PROPERTIES GENERATED TRUE)
set_source_files_properties("${TINK_INCLUDE_DIR}/${name}.pb.h" PROPERTIES GENERATED TRUE)
endforeach()
add_custom_command(OUTPUT ${_generated_srcs} ${_generated_hdrs}
COMMAND ${PROTOC} ${_protofiles}
-I ${CMAKE_CURRENT_SOURCE_DIR}
-I ${CMAKE_CURRENT_SOURCE_DIR}
--cpp_out=${TINK_INCLUDE_DIR}
DEPENDS ${_protofiles}
)
add_library(${LIB_NAME}
${_generated_srcs}
)
add_dependencies(${LIB_NAME} build_external_projects)
target_link_libraries(${LIB_NAME}
# TODO(pesk, rudominer) This is a problem. We cannot use protobuf_full.
# We have to use protobuf_lite.
protobuf_full_cobalt)
set(${HDRS_OUT} ${_generated_hdrs})
endmacro()
tink_make_protobuf_cpp_lib(tink_proto_common_lib TINK_COMMMON_PROTO_HDRS
proto/common)
tink_make_protobuf_cpp_lib(tink_proto_tink_lib TINK_TINK_PROTO_HDRS
proto/tink)
target_link_libraries(tink_proto_tink_lib
tink_proto_common_lib)
tink_make_protobuf_cpp_lib(tink_proto_ecdsa_lib TINK_ECDSA_PROTO_HDRS
proto/ecdsa)
target_link_libraries(tink_proto_ecdsa_lib
tink_proto_common_lib)
add_subdirectory(cc)