|
| 1 | +add_subdirectory(build/getoptPlusPlus) |
| 2 | +add_subdirectory(build/hidapi) |
| 3 | +add_subdirectory(build/jsoncpp) |
| 4 | +add_subdirectory(build/serial) |
| 5 | +add_subdirectory(build/tinkerforge) |
1 | 6 |
|
2 |
| -add_subdirectory(build) |
| 7 | +if(ENABLE_PROTOBUF) |
| 8 | + set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared protobuf library") |
| 9 | + add_subdirectory(external/protobuf) |
| 10 | + |
| 11 | + if(CMAKE_CROSSCOMPILING) |
| 12 | + # when crosscompiling import the protoc executable targets from a file generated by a native build |
| 13 | + option(IMPORT_PROTOC "Protoc export file (protoc_export.cmake) from a native build" "IMPORT_PROTOC-FILE_NOT_FOUND") |
| 14 | + include(${IMPORT_PROTOC}) |
| 15 | + else() |
| 16 | + # export the protoc compiler so it can be used when cross compiling |
| 17 | + export(TARGETS protoc_compiler FILE "${CMAKE_BINARY_DIR}/protoc_export.cmake") |
| 18 | + endif() |
| 19 | + |
| 20 | + # define the include for the protobuf library at the parent scope |
| 21 | + set(PROTOBUF_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf/src") |
| 22 | + set(PROTOBUF_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS} PARENT_SCOPE) |
| 23 | + |
| 24 | + # define the protoc executable at the parent scope |
| 25 | + get_property(PROTOBUF_PROTOC_EXECUTABLE TARGET protoc_compiler PROPERTY LOCATION) |
| 26 | + set(PROTOBUF_PROTOC_EXECUTABLE ${PROTOBUF_PROTOC_EXECUTABLE} PARENT_SCOPE) |
| 27 | + message(STATUS "Using protobuf compiler: " ${PROTOBUF_PROTOC_EXECUTABLE}) |
| 28 | + |
| 29 | + #============================================================================= |
| 30 | + # Copyright 2009 Kitware, Inc. |
| 31 | + # Copyright 2009-2011 Philip Lowman <[email protected]> |
| 32 | + # Copyright 2008 Esben Mose Hansen, Ange Optimization ApS |
| 33 | + # |
| 34 | + # Distributed under the OSI-approved BSD License (the "License"); |
| 35 | + # see accompanying file Copyright.txt for details. |
| 36 | + # |
| 37 | + # This software is distributed WITHOUT ANY WARRANTY; without even the |
| 38 | + # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 39 | + # See the License for more information. |
| 40 | + #============================================================================= |
| 41 | + # (To distribute this file outside of CMake, substitute the full |
| 42 | + # License text for the above reference.) |
| 43 | + function(PROTOBUF_GENERATE_CPP SRCS HDRS) |
| 44 | + if(NOT ARGN) |
| 45 | + message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto files") |
| 46 | + return() |
| 47 | + endif() |
| 48 | + |
| 49 | + if(PROTOBUF_GENERATE_CPP_APPEND_PATH) |
| 50 | + # Create an include path for each file specified |
| 51 | + foreach(FIL ${ARGN}) |
| 52 | + get_filename_component(ABS_FIL ${FIL} ABSOLUTE) |
| 53 | + get_filename_component(ABS_PATH ${ABS_FIL} PATH) |
| 54 | + list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) |
| 55 | + if(${_contains_already} EQUAL -1) |
| 56 | + list(APPEND _protobuf_include_path -I ${ABS_PATH}) |
| 57 | + endif() |
| 58 | + endforeach() |
| 59 | + else() |
| 60 | + set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR}) |
| 61 | + endif() |
| 62 | + |
| 63 | + if(DEFINED PROTOBUF_IMPORT_DIRS) |
| 64 | + foreach(DIR ${PROTOBUF_IMPORT_DIRS}) |
| 65 | + get_filename_component(ABS_PATH ${DIR} ABSOLUTE) |
| 66 | + list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) |
| 67 | + if(${_contains_already} EQUAL -1) |
| 68 | + list(APPEND _protobuf_include_path -I ${ABS_PATH}) |
| 69 | + endif() |
| 70 | + endforeach() |
| 71 | + endif() |
| 72 | + |
| 73 | + if(CMAKE_CROSSCOMPILING) |
| 74 | + set(PROTOC_DEPENDENCY ${PROTOBUF_PROTOC_EXECUTABLE}) |
| 75 | + else() |
| 76 | + set(PROTOC_DEPENDENCY protoc_compiler) |
| 77 | + endif() |
| 78 | + |
| 79 | + set(${SRCS}) |
| 80 | + set(${HDRS}) |
| 81 | + foreach(FIL ${ARGN}) |
| 82 | + get_filename_component(ABS_FIL ${FIL} ABSOLUTE) |
| 83 | + get_filename_component(FIL_WE ${FIL} NAME_WE) |
| 84 | + |
| 85 | + list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc") |
| 86 | + list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h") |
| 87 | + |
| 88 | + add_custom_command( |
| 89 | + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc" |
| 90 | + "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h" |
| 91 | + COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} |
| 92 | + ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL} |
| 93 | + DEPENDS ${ABS_FIL} ${PROTOC_DEPENDENCY} |
| 94 | + COMMENT "Running C++ protocol buffer compiler on ${FIL}" |
| 95 | + VERBATIM |
| 96 | + ) |
| 97 | + endforeach() |
| 98 | + |
| 99 | + set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE) |
| 100 | + set(${SRCS} ${${SRCS}} PARENT_SCOPE) |
| 101 | + set(${HDRS} ${${HDRS}} PARENT_SCOPE) |
| 102 | + endfunction() |
| 103 | +endif() |
0 commit comments