2017-05-30 23:49:18 +00:00
|
|
|
# This file contains backwards compatibility patches for various legacy functions and variables
|
2016-06-01 14:00:08 +00:00
|
|
|
# Functions
|
2015-08-02 13:31:28 +00:00
|
|
|
|
|
|
|
function(PROTOBUF_GENERATE_CPP SRCS HDRS)
|
2017-09-22 09:44:59 +00:00
|
|
|
cmake_parse_arguments(protobuf_generate_cpp "" "EXPORT_MACRO" "" ${ARGN})
|
|
|
|
|
|
|
|
set(_proto_files "${protobuf_generate_cpp_UNPARSED_ARGUMENTS}")
|
|
|
|
if(NOT _proto_files)
|
2015-08-02 13:31:28 +00:00
|
|
|
message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto files")
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(PROTOBUF_GENERATE_CPP_APPEND_PATH)
|
2017-05-30 23:49:18 +00:00
|
|
|
set(_append_arg APPEND_PATH)
|
2015-08-02 13:31:28 +00:00
|
|
|
endif()
|
|
|
|
|
2016-06-01 14:00:08 +00:00
|
|
|
if(DEFINED Protobuf_IMPORT_DIRS)
|
2017-05-30 23:49:18 +00:00
|
|
|
set(_import_arg IMPORT_DIRS ${Protobuf_IMPORT_DIRS})
|
2015-08-02 13:31:28 +00:00
|
|
|
endif()
|
|
|
|
|
2017-05-30 23:49:18 +00:00
|
|
|
set(_outvar)
|
2017-09-22 11:12:59 +00:00
|
|
|
protobuf_generate(${_append_arg} LANGUAGE cpp EXPORT_MACRO ${protobuf_generate_cpp_EXPORT_MACRO} OUT_VAR _outvar ${_import_arg} PROTOS ${_proto_files})
|
2017-05-30 23:49:18 +00:00
|
|
|
|
2015-08-02 13:31:28 +00:00
|
|
|
set(${SRCS})
|
|
|
|
set(${HDRS})
|
2017-05-30 23:49:18 +00:00
|
|
|
foreach(_file ${_outvar})
|
|
|
|
if(_file MATCHES "cc$")
|
|
|
|
list(APPEND ${SRCS} ${_file})
|
|
|
|
else()
|
|
|
|
list(APPEND ${HDRS} ${_file})
|
|
|
|
endif()
|
2015-08-02 13:31:28 +00:00
|
|
|
endforeach()
|
|
|
|
set(${SRCS} ${${SRCS}} PARENT_SCOPE)
|
|
|
|
set(${HDRS} ${${HDRS}} PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
2016-06-01 14:00:08 +00:00
|
|
|
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)
|
2017-05-30 23:49:18 +00:00
|
|
|
set(_append_arg APPEND_PATH)
|
2016-06-01 14:00:08 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(DEFINED Protobuf_IMPORT_DIRS)
|
2017-05-30 23:49:18 +00:00
|
|
|
set(_import_arg IMPORT_DIRS ${Protobuf_IMPORT_DIRS})
|
2016-06-01 14:00:08 +00:00
|
|
|
endif()
|
|
|
|
|
2017-05-30 23:49:18 +00:00
|
|
|
set(_outvar)
|
2017-09-22 11:12:59 +00:00
|
|
|
protobuf_generate(${_append_arg} LANGUAGE python OUT_VAR _outvar ${_import_arg} PROTOS ${ARGN})
|
2017-05-30 23:49:18 +00:00
|
|
|
set(${SRCS} ${_outvar} PARENT_SCOPE)
|
2016-06-01 14:00:08 +00:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# Environment
|
|
|
|
|
|
|
|
# Backwards compatibility
|
|
|
|
# Define camel case versions of input variables
|
|
|
|
foreach(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)
|
|
|
|
|
2015-08-02 13:31:28 +00:00
|
|
|
# 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 variable
|
|
|
|
function(_protobuf_find_libraries name filename)
|
2016-06-01 14:00:08 +00:00
|
|
|
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()
|
2016-06-08 03:32:17 +00:00
|
|
|
get_target_property(${name}_LIBRARY_RELEASE protobuf::lib${filename}
|
|
|
|
LOCATION_RELEASE)
|
|
|
|
get_target_property(${name}_LIBRARY_DEBUG protobuf::lib${filename}
|
|
|
|
LOCATION_DEBUG)
|
2016-06-01 14:00:08 +00:00
|
|
|
|
|
|
|
select_library_configurations(${name})
|
|
|
|
set(${name}_LIBRARY ${${name}_LIBRARY} PARENT_SCOPE)
|
|
|
|
set(${name}_LIBRARIES ${${name}_LIBRARIES} PARENT_SCOPE)
|
|
|
|
endif()
|
2015-08-02 13:31:28 +00:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# Internal function: find threads library
|
|
|
|
function(_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
|
2016-06-01 14:00:08 +00:00
|
|
|
_protobuf_find_libraries(Protobuf protobuf)
|
2015-08-02 13:31:28 +00:00
|
|
|
|
|
|
|
# The Protobuf Lite library
|
2016-06-01 14:00:08 +00:00
|
|
|
_protobuf_find_libraries(Protobuf_LITE protobuf-lite)
|
2015-08-02 13:31:28 +00:00
|
|
|
|
|
|
|
# The Protobuf Protoc Library
|
2016-06-01 14:00:08 +00:00
|
|
|
_protobuf_find_libraries(Protobuf_PROTOC protoc)
|
2015-08-02 13:31:28 +00:00
|
|
|
|
|
|
|
if(UNIX)
|
|
|
|
_protobuf_find_threads()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Set the include directory
|
2016-06-01 14:00:08 +00:00
|
|
|
get_target_property(Protobuf_INCLUDE_DIRS protobuf::libprotobuf
|
|
|
|
INTERFACE_INCLUDE_DIRECTORIES)
|
2015-08-02 13:31:28 +00:00
|
|
|
|
|
|
|
# Set the protoc Executable
|
2016-06-08 03:32:17 +00:00
|
|
|
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
|
|
|
|
IMPORTED_LOCATION_RELEASE)
|
|
|
|
if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
|
2016-06-01 14:00:08 +00:00
|
|
|
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
|
2016-06-08 03:32:17 +00:00
|
|
|
IMPORTED_LOCATION_DEBUG)
|
2015-08-03 08:58:48 +00:00
|
|
|
endif()
|
2017-10-13 22:41:40 +00:00
|
|
|
if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
|
|
|
|
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
|
|
|
|
IMPORTED_LOCATION_NOCONFIG)
|
|
|
|
endif()
|
2015-08-02 13:31:28 +00:00
|
|
|
|
2016-06-01 14:00:08 +00:00
|
|
|
# Version info variable
|
|
|
|
set(Protobuf_VERSION "@protobuf_VERSION@")
|
2015-08-02 13:31:28 +00:00
|
|
|
|
2016-06-01 14:00:08 +00:00
|
|
|
include(FindPackageHandleStandardArgs)
|
|
|
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Protobuf
|
2016-06-08 03:32:17 +00:00
|
|
|
REQUIRED_VARS Protobuf_PROTOC_EXECUTABLE Protobuf_LIBRARIES Protobuf_INCLUDE_DIRS
|
2016-06-01 14:00:08 +00:00
|
|
|
VERSION_VAR Protobuf_VERSION
|
|
|
|
)
|
|
|
|
|
|
|
|
# Backwards compatibility
|
|
|
|
# Define upper case versions of output variables
|
|
|
|
foreach(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()
|