| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 | # Functionsfunction(PROTOBUF_GENERATE_CPP SRCS HDRS)  if(NOT ARGN)    message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto files")    return()  endif()  if(PROTOBUF_GENERATE_CPP_APPEND_PATH)    # Create an include path for each file specified    foreach(FIL ${ARGN})      get_filename_component(ABS_FIL ${FIL} ABSOLUTE)      get_filename_component(ABS_PATH ${ABS_FIL} PATH)      list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)      if(${_contains_already} EQUAL -1)          list(APPEND _protobuf_include_path -I ${ABS_PATH})      endif()    endforeach()  else()    set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR})  endif()  if(DEFINED Protobuf_IMPORT_DIRS)    foreach(DIR ${Protobuf_IMPORT_DIRS})      get_filename_component(ABS_PATH ${DIR} ABSOLUTE)      list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)      if(${_contains_already} EQUAL -1)          list(APPEND _protobuf_include_path -I ${ABS_PATH})      endif()    endforeach()  endif()  set(${SRCS})  set(${HDRS})  foreach(FIL ${ARGN})    get_filename_component(ABS_FIL ${FIL} ABSOLUTE)    get_filename_component(FIL_WE ${FIL} NAME_WE)    list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")    list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")    add_custom_command(      OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"             "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"      COMMAND  ${Protobuf_PROTOC_EXECUTABLE}      ARGS --cpp_out  ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}      DEPENDS ${ABS_FIL} ${Protobuf_PROTOC_EXECUTABLE}      COMMENT "Running C++ protocol buffer compiler on ${FIL}"      VERBATIM )  endforeach()  set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)  set(${SRCS} ${${SRCS}} PARENT_SCOPE)  set(${HDRS} ${${HDRS}} PARENT_SCOPE)endfunction()function(PROTOBUF_GENERATE_PYTHON SRCS)  if(NOT ARGN)    message(SEND_ERROR "Error: PROTOBUF_GENERATE_PYTHON() called without any proto files")    return()  endif()  if(PROTOBUF_GENERATE_CPP_APPEND_PATH)    # Create an include path for each file specified    foreach(FIL ${ARGN})      get_filename_component(ABS_FIL ${FIL} ABSOLUTE)      get_filename_component(ABS_PATH ${ABS_FIL} PATH)      list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)      if(${_contains_already} EQUAL -1)          list(APPEND _protobuf_include_path -I ${ABS_PATH})      endif()    endforeach()  else()    set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR})  endif()  if(DEFINED Protobuf_IMPORT_DIRS)    foreach(DIR ${Protobuf_IMPORT_DIRS})      get_filename_component(ABS_PATH ${DIR} ABSOLUTE)      list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)      if(${_contains_already} EQUAL -1)          list(APPEND _protobuf_include_path -I ${ABS_PATH})      endif()    endforeach()  endif()  set(${SRCS})  foreach(FIL ${ARGN})    get_filename_component(ABS_FIL ${FIL} ABSOLUTE)    get_filename_component(FIL_WE ${FIL} NAME_WE)    list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}_pb2.py")    add_custom_command(      OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}_pb2.py"      COMMAND  ${Protobuf_PROTOC_EXECUTABLE} --python_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}      DEPENDS ${ABS_FIL} ${Protobuf_PROTOC_EXECUTABLE}      COMMENT "Running Python protocol buffer compiler on ${FIL}"      VERBATIM )  endforeach()  set(${SRCS} ${${SRCS}} PARENT_SCOPE)endfunction()# Environment# Backwards compatibility# Define camel case versions of input variablesforeach(UPPER    PROTOBUF_SRC_ROOT_FOLDER    PROTOBUF_IMPORT_DIRS    PROTOBUF_DEBUG    PROTOBUF_LIBRARY    PROTOBUF_PROTOC_LIBRARY    PROTOBUF_INCLUDE_DIR    PROTOBUF_PROTOC_EXECUTABLE    PROTOBUF_LIBRARY_DEBUG    PROTOBUF_PROTOC_LIBRARY_DEBUG    PROTOBUF_LITE_LIBRARY    PROTOBUF_LITE_LIBRARY_DEBUG    )    if (DEFINED ${UPPER})        string(REPLACE "PROTOBUF_" "Protobuf_" Camel ${UPPER})        if (NOT DEFINED ${Camel})            set(${Camel} ${${UPPER}})        endif()    endif()endforeach()if(DEFINED Protobuf_SRC_ROOT_FOLDER)  message(AUTHOR_WARNING "Variable Protobuf_SRC_ROOT_FOLDER defined, but not"    " used in CONFIG mode")endif()include(SelectLibraryConfigurations)# Internal function: search for normal library as well as a debug one#    if the debug one is specified also include debug/optimized keywords#    in *_LIBRARIES variablefunction(_protobuf_find_libraries name filename)  if(${name}_LIBRARIES)    # Use result recorded by a previous call.  elseif(${name}_LIBRARY)    # Honor cache entry used by CMake 3.5 and lower.    set(${name}_LIBRARIES "${${name}_LIBRARY}" PARENT_SCOPE)  else()    get_target_property(${name}_LIBRARY_RELEASE protobuf::lib${filename}      LOCATION_RELEASE)    get_target_property(${name}_LIBRARY_DEBUG protobuf::lib${filename}      LOCATION_DEBUG)    endif()    select_library_configurations(${name})    set(${name}_LIBRARY ${${name}_LIBRARY} PARENT_SCOPE)    set(${name}_LIBRARIES ${${name}_LIBRARIES} PARENT_SCOPE)  endif()endfunction()# Internal function: find threads libraryfunction(_protobuf_find_threads)    set(CMAKE_THREAD_PREFER_PTHREAD TRUE)    find_package(Threads)    if(Threads_FOUND)        list(APPEND PROTOBUF_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})        set(PROTOBUF_LIBRARIES "${PROTOBUF_LIBRARIES}" PARENT_SCOPE)    endif()endfunction()## Main.## By default have PROTOBUF_GENERATE_CPP macro pass -I to protoc# for each directory where a proto file is referenced.if(NOT DEFINED PROTOBUF_GENERATE_CPP_APPEND_PATH)  set(PROTOBUF_GENERATE_CPP_APPEND_PATH TRUE)endif()# The Protobuf library_protobuf_find_libraries(Protobuf protobuf)# The Protobuf Lite library_protobuf_find_libraries(Protobuf_LITE protobuf-lite)# The Protobuf Protoc Library_protobuf_find_libraries(Protobuf_PROTOC protoc)if(UNIX)  _protobuf_find_threads()endif()# Set the include directoryget_target_property(Protobuf_INCLUDE_DIRS protobuf::libprotobuf  INTERFACE_INCLUDE_DIRECTORIES)# Set the protoc Executableget_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc  IMPORTED_LOCATION_RELEASE)if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")  get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc    IMPORTED_LOCATION_DEBUG)endif()# Version info variableset(Protobuf_VERSION "@protobuf_VERSION@")include(FindPackageHandleStandardArgs)FIND_PACKAGE_HANDLE_STANDARD_ARGS(Protobuf    REQUIRED_VARS Protobuf_PROTOC_EXECUTABLE Protobuf_LIBRARIES Protobuf_INCLUDE_DIRS    VERSION_VAR Protobuf_VERSION)# Backwards compatibility# Define upper case versions of output variablesforeach(Camel    Protobuf_VERSION    Protobuf_SRC_ROOT_FOLDER    Protobuf_IMPORT_DIRS    Protobuf_DEBUG    Protobuf_INCLUDE_DIRS    Protobuf_LIBRARIES    Protobuf_PROTOC_LIBRARIES    Protobuf_LITE_LIBRARIES    Protobuf_LIBRARY    Protobuf_PROTOC_LIBRARY    Protobuf_INCLUDE_DIR    Protobuf_PROTOC_EXECUTABLE    Protobuf_LIBRARY_DEBUG    Protobuf_PROTOC_LIBRARY_DEBUG    Protobuf_LITE_LIBRARY    Protobuf_LITE_LIBRARY_DEBUG    )    string(TOUPPER ${Camel} UPPER)    set(${UPPER} ${${Camel}})endforeach()
 |