Browse Source

build a protoc binary to use to ensure version compat

try-fix-comms-errors
Alex Mikhalev 6 years ago
parent
commit
d08e58465a
  1. 38
      components/protobuf/functions.cmake
  2. 17
      components/protobuf/protobuf-CMakeLists.cmake

38
components/protobuf/functions.cmake

@ -1,4 +1,38 @@ @@ -1,4 +1,38 @@
find_program(PROTOC protoc)
if(NOT CMAKE_SCRIPT_MODE_FILE)
set(PROTOBUF_DIR ${CMAKE_CURRENT_LIST_DIR}/protobuf)
set(PROTOBUF_BUILD ${PROJECT_BINARY_DIR}/protobuf-build)
set(PROTOBUF_BINARY ${PROJECT_BINARY_DIR}/protobuf-binary)
set(PROTOBUF_SRC ${PROJECT_BINARY_DIR}/protobuf-src)
configure_file(${CMAKE_CURRENT_LIST_DIR}/protobuf-CMakeLists.cmake ${PROTOBUF_BUILD}/CMakeLists.txt)
if(NOT CMAKE_GENERATOR)
set(CMAKE_GENERATOR "Ninja")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${PROTOBUF_BUILD} )
if(result)
message(FATAL_ERROR "CMake step for protobuf failed: ${result}")
endif()
# execute_process(COMMAND ${CMAKE_COMMAND} --build .
# RESULT_VARIABLE result
# WORKING_DIRECTORY ${PROTOBUF_BUILD})
# if(result)
# message(FATAL_ERROR "Build step for protobuf failed: ${result}")
# endif()
set(PROTOC ${PROTOBUF_BINARY}/protoc)
add_custom_command(OUTPUT ${PROTOC}
COMMENT "Building protoc binary"
COMMAND ${CMAKE_COMMAND} --build .
USES_TERMINAL
WORKING_DIRECTORY ${PROTOBUF_BUILD})
endif()
# find_program(PROTOC protoc PATHS ${CMAKE_CURRENT_LIST_DIR}/protobuf/cmake/build/)
function(proto_generate_cpp PROTO_FILE PB_OUT HDR_VAR SRC_VAR)
get_filename_component(PROTO_FILE_NAME ${PROTO_FILE} NAME_WE)
@ -14,7 +48,7 @@ function(proto_generate_cpp PROTO_FILE PB_OUT HDR_VAR SRC_VAR) @@ -14,7 +48,7 @@ function(proto_generate_cpp PROTO_FILE PB_OUT HDR_VAR SRC_VAR)
--cpp_out=${PB_OUT}
--proto_path ${PROTO_FILE_DIR}
${PROTO_FILE_PATH}
DEPENDS ${PROTO_FILE_PATH}
DEPENDS ${PROTO_FILE_PATH} ${PROTOC}
COMMENT "Generating nanopb sources for ${PROTO_FILE}")
set_property(SOURCE ${PROTO_HDR} ${PROTO_SRC} PROPERTY GENERATED TRUE)
set_property(DIRECTORY . APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${PROTO_HDR} ${PROTO_SRC})

17
components/protobuf/protobuf-CMakeLists.cmake

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 2.8.2)
project(protobuf-build NONE)
include(ExternalProject)
ExternalProject_Add(protobuf
URL "${PROTOBUF_DIR}"
SOURCE_DIR "${PROTOBUF_SRC}"
BINARY_DIR "${PROTOBUF_BINARY}"
SOURCE_SUBDIR "cmake"
CMAKE_GENERATOR "${CMAKE_GENERATOR}"
CMAKE_ARGS -Dprotobuf_BUILD_TESTS:BOOL=OFF
INSTALL_COMMAND ""
TEST_COMMAND ""
USES_TERMINAL_CONFIGURE ON
USES_TERMINAL_BUILD ON
)
Loading…
Cancel
Save