1ffe3c632Sopenharmony_ci# This file contains backwards compatibility patches for various legacy functions and variables 2ffe3c632Sopenharmony_ci# Functions 3ffe3c632Sopenharmony_ci 4ffe3c632Sopenharmony_cifunction(PROTOBUF_GENERATE_CPP SRCS HDRS) 5ffe3c632Sopenharmony_ci cmake_parse_arguments(protobuf_generate_cpp "" "EXPORT_MACRO" "" ${ARGN}) 6ffe3c632Sopenharmony_ci 7ffe3c632Sopenharmony_ci set(_proto_files "${protobuf_generate_cpp_UNPARSED_ARGUMENTS}") 8ffe3c632Sopenharmony_ci if(NOT _proto_files) 9ffe3c632Sopenharmony_ci message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto files") 10ffe3c632Sopenharmony_ci return() 11ffe3c632Sopenharmony_ci endif() 12ffe3c632Sopenharmony_ci 13ffe3c632Sopenharmony_ci if(PROTOBUF_GENERATE_CPP_APPEND_PATH) 14ffe3c632Sopenharmony_ci set(_append_arg APPEND_PATH) 15ffe3c632Sopenharmony_ci endif() 16ffe3c632Sopenharmony_ci 17ffe3c632Sopenharmony_ci if(DEFINED Protobuf_IMPORT_DIRS) 18ffe3c632Sopenharmony_ci set(_import_arg IMPORT_DIRS ${Protobuf_IMPORT_DIRS}) 19ffe3c632Sopenharmony_ci endif() 20ffe3c632Sopenharmony_ci 21ffe3c632Sopenharmony_ci set(_outvar) 22ffe3c632Sopenharmony_ci protobuf_generate(${_append_arg} LANGUAGE cpp EXPORT_MACRO ${protobuf_generate_cpp_EXPORT_MACRO} OUT_VAR _outvar ${_import_arg} PROTOS ${_proto_files}) 23ffe3c632Sopenharmony_ci 24ffe3c632Sopenharmony_ci set(${SRCS}) 25ffe3c632Sopenharmony_ci set(${HDRS}) 26ffe3c632Sopenharmony_ci foreach(_file ${_outvar}) 27ffe3c632Sopenharmony_ci if(_file MATCHES "cc$") 28ffe3c632Sopenharmony_ci list(APPEND ${SRCS} ${_file}) 29ffe3c632Sopenharmony_ci else() 30ffe3c632Sopenharmony_ci list(APPEND ${HDRS} ${_file}) 31ffe3c632Sopenharmony_ci endif() 32ffe3c632Sopenharmony_ci endforeach() 33ffe3c632Sopenharmony_ci set(${SRCS} ${${SRCS}} PARENT_SCOPE) 34ffe3c632Sopenharmony_ci set(${HDRS} ${${HDRS}} PARENT_SCOPE) 35ffe3c632Sopenharmony_ciendfunction() 36ffe3c632Sopenharmony_ci 37ffe3c632Sopenharmony_cifunction(PROTOBUF_GENERATE_PYTHON SRCS) 38ffe3c632Sopenharmony_ci if(NOT ARGN) 39ffe3c632Sopenharmony_ci message(SEND_ERROR "Error: PROTOBUF_GENERATE_PYTHON() called without any proto files") 40ffe3c632Sopenharmony_ci return() 41ffe3c632Sopenharmony_ci endif() 42ffe3c632Sopenharmony_ci 43ffe3c632Sopenharmony_ci if(PROTOBUF_GENERATE_CPP_APPEND_PATH) 44ffe3c632Sopenharmony_ci set(_append_arg APPEND_PATH) 45ffe3c632Sopenharmony_ci endif() 46ffe3c632Sopenharmony_ci 47ffe3c632Sopenharmony_ci if(DEFINED Protobuf_IMPORT_DIRS) 48ffe3c632Sopenharmony_ci set(_import_arg IMPORT_DIRS ${Protobuf_IMPORT_DIRS}) 49ffe3c632Sopenharmony_ci endif() 50ffe3c632Sopenharmony_ci 51ffe3c632Sopenharmony_ci set(_outvar) 52ffe3c632Sopenharmony_ci protobuf_generate(${_append_arg} LANGUAGE python OUT_VAR _outvar ${_import_arg} PROTOS ${ARGN}) 53ffe3c632Sopenharmony_ci set(${SRCS} ${_outvar} PARENT_SCOPE) 54ffe3c632Sopenharmony_ciendfunction() 55ffe3c632Sopenharmony_ci 56ffe3c632Sopenharmony_ci# Environment 57ffe3c632Sopenharmony_ci 58ffe3c632Sopenharmony_ci# Backwards compatibility 59ffe3c632Sopenharmony_ci# Define camel case versions of input variables 60ffe3c632Sopenharmony_ciforeach(UPPER 61ffe3c632Sopenharmony_ci PROTOBUF_SRC_ROOT_FOLDER 62ffe3c632Sopenharmony_ci PROTOBUF_IMPORT_DIRS 63ffe3c632Sopenharmony_ci PROTOBUF_DEBUG 64ffe3c632Sopenharmony_ci PROTOBUF_LIBRARY 65ffe3c632Sopenharmony_ci PROTOBUF_PROTOC_LIBRARY 66ffe3c632Sopenharmony_ci PROTOBUF_INCLUDE_DIR 67ffe3c632Sopenharmony_ci PROTOBUF_PROTOC_EXECUTABLE 68ffe3c632Sopenharmony_ci PROTOBUF_LIBRARY_DEBUG 69ffe3c632Sopenharmony_ci PROTOBUF_PROTOC_LIBRARY_DEBUG 70ffe3c632Sopenharmony_ci PROTOBUF_LITE_LIBRARY 71ffe3c632Sopenharmony_ci PROTOBUF_LITE_LIBRARY_DEBUG 72ffe3c632Sopenharmony_ci ) 73ffe3c632Sopenharmony_ci if (DEFINED ${UPPER}) 74ffe3c632Sopenharmony_ci string(REPLACE "PROTOBUF_" "Protobuf_" Camel ${UPPER}) 75ffe3c632Sopenharmony_ci if (NOT DEFINED ${Camel}) 76ffe3c632Sopenharmony_ci set(${Camel} ${${UPPER}}) 77ffe3c632Sopenharmony_ci endif() 78ffe3c632Sopenharmony_ci endif() 79ffe3c632Sopenharmony_ciendforeach() 80ffe3c632Sopenharmony_ci 81ffe3c632Sopenharmony_ciif(DEFINED Protobuf_SRC_ROOT_FOLDER) 82ffe3c632Sopenharmony_ci message(AUTHOR_WARNING "Variable Protobuf_SRC_ROOT_FOLDER defined, but not" 83ffe3c632Sopenharmony_ci " used in CONFIG mode") 84ffe3c632Sopenharmony_ciendif() 85ffe3c632Sopenharmony_ci 86ffe3c632Sopenharmony_ciinclude(SelectLibraryConfigurations) 87ffe3c632Sopenharmony_ci 88ffe3c632Sopenharmony_ci# Internal function: search for normal library as well as a debug one 89ffe3c632Sopenharmony_ci# if the debug one is specified also include debug/optimized keywords 90ffe3c632Sopenharmony_ci# in *_LIBRARIES variable 91ffe3c632Sopenharmony_cifunction(_protobuf_find_libraries name filename) 92ffe3c632Sopenharmony_ci if(${name}_LIBRARIES) 93ffe3c632Sopenharmony_ci # Use result recorded by a previous call. 94ffe3c632Sopenharmony_ci elseif(${name}_LIBRARY) 95ffe3c632Sopenharmony_ci # Honor cache entry used by CMake 3.5 and lower. 96ffe3c632Sopenharmony_ci set(${name}_LIBRARIES "${${name}_LIBRARY}" PARENT_SCOPE) 97ffe3c632Sopenharmony_ci else() 98ffe3c632Sopenharmony_ci get_target_property(${name}_LIBRARY_RELEASE protobuf::lib${filename} 99ffe3c632Sopenharmony_ci LOCATION_RELEASE) 100ffe3c632Sopenharmony_ci get_target_property(${name}_LIBRARY_DEBUG protobuf::lib${filename} 101ffe3c632Sopenharmony_ci LOCATION_DEBUG) 102ffe3c632Sopenharmony_ci 103ffe3c632Sopenharmony_ci select_library_configurations(${name}) 104ffe3c632Sopenharmony_ci set(${name}_LIBRARY ${${name}_LIBRARY} PARENT_SCOPE) 105ffe3c632Sopenharmony_ci set(${name}_LIBRARIES ${${name}_LIBRARIES} PARENT_SCOPE) 106ffe3c632Sopenharmony_ci endif() 107ffe3c632Sopenharmony_ciendfunction() 108ffe3c632Sopenharmony_ci 109ffe3c632Sopenharmony_ci# Internal function: find threads library 110ffe3c632Sopenharmony_cifunction(_protobuf_find_threads) 111ffe3c632Sopenharmony_ci set(CMAKE_THREAD_PREFER_PTHREAD TRUE) 112ffe3c632Sopenharmony_ci find_package(Threads) 113ffe3c632Sopenharmony_ci if(Threads_FOUND) 114ffe3c632Sopenharmony_ci list(APPEND PROTOBUF_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) 115ffe3c632Sopenharmony_ci set(PROTOBUF_LIBRARIES "${PROTOBUF_LIBRARIES}" PARENT_SCOPE) 116ffe3c632Sopenharmony_ci endif() 117ffe3c632Sopenharmony_ciendfunction() 118ffe3c632Sopenharmony_ci 119ffe3c632Sopenharmony_ci# 120ffe3c632Sopenharmony_ci# Main. 121ffe3c632Sopenharmony_ci# 122ffe3c632Sopenharmony_ci 123ffe3c632Sopenharmony_ci# By default have PROTOBUF_GENERATE_CPP macro pass -I to protoc 124ffe3c632Sopenharmony_ci# for each directory where a proto file is referenced. 125ffe3c632Sopenharmony_ciif(NOT DEFINED PROTOBUF_GENERATE_CPP_APPEND_PATH) 126ffe3c632Sopenharmony_ci set(PROTOBUF_GENERATE_CPP_APPEND_PATH TRUE) 127ffe3c632Sopenharmony_ciendif() 128ffe3c632Sopenharmony_ci 129ffe3c632Sopenharmony_ci# The Protobuf library 130ffe3c632Sopenharmony_ci_protobuf_find_libraries(Protobuf protobuf) 131ffe3c632Sopenharmony_ci 132ffe3c632Sopenharmony_ci# The Protobuf Lite library 133ffe3c632Sopenharmony_ci_protobuf_find_libraries(Protobuf_LITE protobuf-lite) 134ffe3c632Sopenharmony_ci 135ffe3c632Sopenharmony_ci# The Protobuf Protoc Library 136ffe3c632Sopenharmony_ci_protobuf_find_libraries(Protobuf_PROTOC protoc) 137ffe3c632Sopenharmony_ci 138ffe3c632Sopenharmony_ciif(UNIX) 139ffe3c632Sopenharmony_ci _protobuf_find_threads() 140ffe3c632Sopenharmony_ciendif() 141ffe3c632Sopenharmony_ci 142ffe3c632Sopenharmony_ci# Set the include directory 143ffe3c632Sopenharmony_ciget_target_property(Protobuf_INCLUDE_DIRS protobuf::libprotobuf 144ffe3c632Sopenharmony_ci INTERFACE_INCLUDE_DIRECTORIES) 145ffe3c632Sopenharmony_ci 146ffe3c632Sopenharmony_ci# Set the protoc Executable 147ffe3c632Sopenharmony_ciget_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc 148ffe3c632Sopenharmony_ci IMPORTED_LOCATION_RELEASE) 149ffe3c632Sopenharmony_ciif(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}") 150ffe3c632Sopenharmony_ci get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc 151ffe3c632Sopenharmony_ci IMPORTED_LOCATION_DEBUG) 152ffe3c632Sopenharmony_ciendif() 153ffe3c632Sopenharmony_ciif(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}") 154ffe3c632Sopenharmony_ci get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc 155ffe3c632Sopenharmony_ci IMPORTED_LOCATION_NOCONFIG) 156ffe3c632Sopenharmony_ciendif() 157ffe3c632Sopenharmony_ci 158ffe3c632Sopenharmony_ci# Version info variable 159ffe3c632Sopenharmony_ciset(Protobuf_VERSION "@protobuf_VERSION@") 160ffe3c632Sopenharmony_ci 161ffe3c632Sopenharmony_ciinclude(FindPackageHandleStandardArgs) 162ffe3c632Sopenharmony_ciFIND_PACKAGE_HANDLE_STANDARD_ARGS(Protobuf 163ffe3c632Sopenharmony_ci REQUIRED_VARS Protobuf_PROTOC_EXECUTABLE Protobuf_LIBRARIES Protobuf_INCLUDE_DIRS 164ffe3c632Sopenharmony_ci VERSION_VAR Protobuf_VERSION 165ffe3c632Sopenharmony_ci) 166ffe3c632Sopenharmony_ci 167ffe3c632Sopenharmony_ci# Backwards compatibility 168ffe3c632Sopenharmony_ci# Define upper case versions of output variables 169ffe3c632Sopenharmony_ciforeach(Camel 170ffe3c632Sopenharmony_ci Protobuf_VERSION 171ffe3c632Sopenharmony_ci Protobuf_SRC_ROOT_FOLDER 172ffe3c632Sopenharmony_ci Protobuf_IMPORT_DIRS 173ffe3c632Sopenharmony_ci Protobuf_DEBUG 174ffe3c632Sopenharmony_ci Protobuf_INCLUDE_DIRS 175ffe3c632Sopenharmony_ci Protobuf_LIBRARIES 176ffe3c632Sopenharmony_ci Protobuf_PROTOC_LIBRARIES 177ffe3c632Sopenharmony_ci Protobuf_LITE_LIBRARIES 178ffe3c632Sopenharmony_ci Protobuf_LIBRARY 179ffe3c632Sopenharmony_ci Protobuf_PROTOC_LIBRARY 180ffe3c632Sopenharmony_ci Protobuf_INCLUDE_DIR 181ffe3c632Sopenharmony_ci Protobuf_PROTOC_EXECUTABLE 182ffe3c632Sopenharmony_ci Protobuf_LIBRARY_DEBUG 183ffe3c632Sopenharmony_ci Protobuf_PROTOC_LIBRARY_DEBUG 184ffe3c632Sopenharmony_ci Protobuf_LITE_LIBRARY 185ffe3c632Sopenharmony_ci Protobuf_LITE_LIBRARY_DEBUG 186ffe3c632Sopenharmony_ci ) 187ffe3c632Sopenharmony_ci string(TOUPPER ${Camel} UPPER) 188ffe3c632Sopenharmony_ci set(${UPPER} ${${Camel}}) 189ffe3c632Sopenharmony_ciendforeach() 190