| # 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_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 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) |
| file(RELATIVE_PATH |
| _file_path |
| "${PROJECT_SOURCE_DIR}" |
| "${CMAKE_CURRENT_SOURCE_DIR}") |
| foreach(name ${ARGN}) |
| list(APPEND _protofiles "${CMAKE_CURRENT_SOURCE_DIR}/${name}.proto") |
| list(APPEND _generated_srcs "${TINK_INCLUDE_DIR}/${_file_path}/${name}.pb.cc") |
| list(APPEND _generated_hdrs "${TINK_INCLUDE_DIR}/${_file_path}/${name}.pb.h") |
| set_source_files_properties("${TINK_INCLUDE_DIR}/${_file_path}/${name}.pb.cc" PROPERTIES GENERATED TRUE) |
| set_source_files_properties("${TINK_INCLUDE_DIR}/${_file_path}/${name}.pb.h" PROPERTIES GENERATED TRUE) |
| endforeach() |
| add_custom_command(OUTPUT ${_generated_srcs} ${_generated_hdrs} |
| COMMAND ${PROTOC} ${_protofiles} |
| -I ${PROJECT_SOURCE_DIR} |
| --cpp_out=lite:${TINK_INCLUDE_DIR} |
| DEPENDS ${_protofiles} |
| ) |
| add_library(${LIB_NAME} |
| ${_generated_srcs} |
| ) |
| add_dependencies(${LIB_NAME} build_external_projects) |
| target_link_libraries(${LIB_NAME} |
| protobuf_lite) |
| set(${HDRS_OUT} ${_generated_hdrs}) |
| endmacro() |
| |
| macro(tink_export_hdrs) |
| file(RELATIVE_PATH _file_path "${PROJECT_SOURCE_DIR}/cc" |
| "${CMAKE_CURRENT_SOURCE_DIR}") |
| foreach(name ${ARGN}) |
| file(COPY "${name}" DESTINATION ${TINK_INCLUDE_DIR}/tink/${_file_path}) |
| endforeach() |
| endmacro() |
| |
| add_subdirectory(proto) |
| add_subdirectory(cc) |