| OLD | NEW |
| 1 # Functions | 1 if(PROTOBUF_SRC_ROOT_FOLDER) |
| 2 message(AUTHOR_WARNING "Variable PROTOBUF_SRC_ROOT_FOLDER defined, but not" |
| 3 " used in CONFIG mode") |
| 4 endif() |
| 2 | 5 |
| 3 function(PROTOBUF_GENERATE_CPP SRCS HDRS) | 6 function(PROTOBUF_GENERATE_CPP SRCS HDRS) |
| 4 if(NOT ARGN) | 7 if(NOT ARGN) |
| 5 message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto
files") | 8 message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto
files") |
| 6 return() | 9 return() |
| 7 endif() | 10 endif() |
| 8 | 11 |
| 9 if(PROTOBUF_GENERATE_CPP_APPEND_PATH) | 12 if(PROTOBUF_GENERATE_CPP_APPEND_PATH) |
| 10 # Create an include path for each file specified | 13 # Create an include path for each file specified |
| 11 foreach(FIL ${ARGN}) | 14 foreach(FIL ${ARGN}) |
| 12 get_filename_component(ABS_FIL ${FIL} ABSOLUTE) | 15 get_filename_component(ABS_FIL ${FIL} ABSOLUTE) |
| 13 get_filename_component(ABS_PATH ${ABS_FIL} PATH) | 16 get_filename_component(ABS_PATH ${ABS_FIL} PATH) |
| 14 list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) | 17 list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) |
| 15 if(${_contains_already} EQUAL -1) | 18 if(${_contains_already} EQUAL -1) |
| 16 list(APPEND _protobuf_include_path -I ${ABS_PATH}) | 19 list(APPEND _protobuf_include_path -I ${ABS_PATH}) |
| 17 endif() | 20 endif() |
| 18 endforeach() | 21 endforeach() |
| 19 else() | 22 else() |
| 20 set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR}) | 23 set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR}) |
| 21 endif() | 24 endif() |
| 22 | 25 |
| 23 if(DEFINED Protobuf_IMPORT_DIRS) | 26 # Add well-known type protos include path |
| 24 foreach(DIR ${Protobuf_IMPORT_DIRS}) | 27 list(APPEND _protobuf_include_path |
| 28 -I "${_PROTOBUF_IMPORT_PREFIX}/@CMAKE_INSTALL_INCLUDEDIR@") |
| 29 |
| 30 if(DEFINED PROTOBUF_IMPORT_DIRS) |
| 31 foreach(DIR ${PROTOBUF_IMPORT_DIRS}) |
| 25 get_filename_component(ABS_PATH ${DIR} ABSOLUTE) | 32 get_filename_component(ABS_PATH ${DIR} ABSOLUTE) |
| 26 list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) | 33 list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) |
| 27 if(${_contains_already} EQUAL -1) | 34 if(${_contains_already} EQUAL -1) |
| 28 list(APPEND _protobuf_include_path -I ${ABS_PATH}) | 35 list(APPEND _protobuf_include_path -I ${ABS_PATH}) |
| 29 endif() | 36 endif() |
| 30 endforeach() | 37 endforeach() |
| 31 endif() | 38 endif() |
| 32 | 39 |
| 33 set(${SRCS}) | 40 set(${SRCS}) |
| 34 set(${HDRS}) | 41 set(${HDRS}) |
| 35 foreach(FIL ${ARGN}) | 42 foreach(FIL ${ARGN}) |
| 36 get_filename_component(ABS_FIL ${FIL} ABSOLUTE) | 43 get_filename_component(ABS_FIL ${FIL} ABSOLUTE) |
| 37 get_filename_component(FIL_WE ${FIL} NAME_WE) | 44 get_filename_component(FIL_WE ${FIL} NAME_WE) |
| 38 | 45 |
| 39 list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc") | 46 list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc") |
| 40 list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h") | 47 list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h") |
| 41 | 48 |
| 42 add_custom_command( | 49 add_custom_command( |
| 43 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc" | 50 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc" |
| 44 "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h" | 51 "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h" |
| 45 COMMAND ${Protobuf_PROTOC_EXECUTABLE} | 52 COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} |
| 46 ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${AB
S_FIL} | 53 ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${AB
S_FIL} |
| 47 DEPENDS ${ABS_FIL} ${Protobuf_PROTOC_EXECUTABLE} | 54 DEPENDS ${ABS_FIL} ${PROTOBUF_PROTOC_EXECUTABLE} |
| 48 COMMENT "Running C++ protocol buffer compiler on ${FIL}" | 55 COMMENT "Running C++ protocol buffer compiler on ${FIL}" |
| 49 VERBATIM ) | 56 VERBATIM) |
| 50 endforeach() | 57 endforeach() |
| 51 | 58 |
| 52 set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE) | 59 set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE) |
| 53 set(${SRCS} ${${SRCS}} PARENT_SCOPE) | 60 set(${SRCS} ${${SRCS}} PARENT_SCOPE) |
| 54 set(${HDRS} ${${HDRS}} PARENT_SCOPE) | 61 set(${HDRS} ${${HDRS}} PARENT_SCOPE) |
| 55 endfunction() | 62 endfunction() |
| 56 | 63 |
| 57 function(PROTOBUF_GENERATE_PYTHON SRCS) | |
| 58 if(NOT ARGN) | |
| 59 message(SEND_ERROR "Error: PROTOBUF_GENERATE_PYTHON() called without any pro
to files") | |
| 60 return() | |
| 61 endif() | |
| 62 | |
| 63 if(PROTOBUF_GENERATE_CPP_APPEND_PATH) | |
| 64 # Create an include path for each file specified | |
| 65 foreach(FIL ${ARGN}) | |
| 66 get_filename_component(ABS_FIL ${FIL} ABSOLUTE) | |
| 67 get_filename_component(ABS_PATH ${ABS_FIL} PATH) | |
| 68 list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) | |
| 69 if(${_contains_already} EQUAL -1) | |
| 70 list(APPEND _protobuf_include_path -I ${ABS_PATH}) | |
| 71 endif() | |
| 72 endforeach() | |
| 73 else() | |
| 74 set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR}) | |
| 75 endif() | |
| 76 | |
| 77 if(DEFINED Protobuf_IMPORT_DIRS) | |
| 78 foreach(DIR ${Protobuf_IMPORT_DIRS}) | |
| 79 get_filename_component(ABS_PATH ${DIR} ABSOLUTE) | |
| 80 list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) | |
| 81 if(${_contains_already} EQUAL -1) | |
| 82 list(APPEND _protobuf_include_path -I ${ABS_PATH}) | |
| 83 endif() | |
| 84 endforeach() | |
| 85 endif() | |
| 86 | |
| 87 set(${SRCS}) | |
| 88 foreach(FIL ${ARGN}) | |
| 89 get_filename_component(ABS_FIL ${FIL} ABSOLUTE) | |
| 90 get_filename_component(FIL_WE ${FIL} NAME_WE) | |
| 91 | |
| 92 list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}_pb2.py") | |
| 93 add_custom_command( | |
| 94 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}_pb2.py" | |
| 95 COMMAND ${Protobuf_PROTOC_EXECUTABLE} --python_out ${CMAKE_CURRENT_BINARY
_DIR} ${_protobuf_include_path} ${ABS_FIL} | |
| 96 DEPENDS ${ABS_FIL} ${Protobuf_PROTOC_EXECUTABLE} | |
| 97 COMMENT "Running Python protocol buffer compiler on ${FIL}" | |
| 98 VERBATIM ) | |
| 99 endforeach() | |
| 100 | |
| 101 set(${SRCS} ${${SRCS}} PARENT_SCOPE) | |
| 102 endfunction() | |
| 103 | |
| 104 # Environment | |
| 105 | |
| 106 # Backwards compatibility | |
| 107 # Define camel case versions of input variables | |
| 108 foreach(UPPER | |
| 109 PROTOBUF_SRC_ROOT_FOLDER | |
| 110 PROTOBUF_IMPORT_DIRS | |
| 111 PROTOBUF_DEBUG | |
| 112 PROTOBUF_LIBRARY | |
| 113 PROTOBUF_PROTOC_LIBRARY | |
| 114 PROTOBUF_INCLUDE_DIR | |
| 115 PROTOBUF_PROTOC_EXECUTABLE | |
| 116 PROTOBUF_LIBRARY_DEBUG | |
| 117 PROTOBUF_PROTOC_LIBRARY_DEBUG | |
| 118 PROTOBUF_LITE_LIBRARY | |
| 119 PROTOBUF_LITE_LIBRARY_DEBUG | |
| 120 ) | |
| 121 if (DEFINED ${UPPER}) | |
| 122 string(REPLACE "PROTOBUF_" "Protobuf_" Camel ${UPPER}) | |
| 123 if (NOT DEFINED ${Camel}) | |
| 124 set(${Camel} ${${UPPER}}) | |
| 125 endif() | |
| 126 endif() | |
| 127 endforeach() | |
| 128 | |
| 129 if(DEFINED Protobuf_SRC_ROOT_FOLDER) | |
| 130 message(AUTHOR_WARNING "Variable Protobuf_SRC_ROOT_FOLDER defined, but not" | |
| 131 " used in CONFIG mode") | |
| 132 endif() | |
| 133 | |
| 134 include(SelectLibraryConfigurations) | |
| 135 | |
| 136 # Internal function: search for normal library as well as a debug one | 64 # Internal function: search for normal library as well as a debug one |
| 137 # if the debug one is specified also include debug/optimized keywords | 65 # if the debug one is specified also include debug/optimized keywords |
| 138 # in *_LIBRARIES variable | 66 # in *_LIBRARIES variable |
| 139 function(_protobuf_find_libraries name filename) | 67 function(_protobuf_find_libraries name filename) |
| 140 if(${name}_LIBRARIES) | 68 get_target_property(${name}_LIBRARY lib${filename} |
| 141 # Use result recorded by a previous call. | 69 IMPORTED_LOCATION_RELEASE) |
| 142 elseif(${name}_LIBRARY) | 70 set(${name}_LIBRARY "${${name}_LIBRARY}" PARENT_SCOPE) |
| 143 # Honor cache entry used by CMake 3.5 and lower. | 71 get_target_property(${name}_LIBRARY_DEBUG lib${filename} |
| 144 set(${name}_LIBRARIES "${${name}_LIBRARY}" PARENT_SCOPE) | 72 IMPORTED_LOCATION_DEBUG) |
| 145 else() | 73 set(${name}_LIBRARY_DEBUG "${${name}_LIBRARY_DEBUG}" PARENT_SCOPE) |
| 146 get_target_property(${name}_LIBRARY_RELEASE protobuf::lib${filename} | |
| 147 LOCATION_RELEASE) | |
| 148 get_target_property(${name}_LIBRARY_DEBUG protobuf::lib${filename} | |
| 149 LOCATION_DEBUG) | |
| 150 | 74 |
| 151 select_library_configurations(${name}) | 75 if(NOT ${name}_LIBRARY_DEBUG) |
| 152 set(${name}_LIBRARY ${${name}_LIBRARY} PARENT_SCOPE) | 76 # There is no debug library |
| 153 set(${name}_LIBRARIES ${${name}_LIBRARIES} PARENT_SCOPE) | 77 set(${name}_LIBRARY_DEBUG ${${name}_LIBRARY} PARENT_SCOPE) |
| 154 endif() | 78 set(${name}_LIBRARIES ${${name}_LIBRARY} PARENT_SCOPE) |
| 79 else() |
| 80 # There IS a debug library |
| 81 set(${name}_LIBRARIES |
| 82 optimized ${${name}_LIBRARY} |
| 83 debug ${${name}_LIBRARY_DEBUG} |
| 84 PARENT_SCOPE |
| 85 ) |
| 86 endif() |
| 155 endfunction() | 87 endfunction() |
| 156 | 88 |
| 157 # Internal function: find threads library | 89 # Internal function: find threads library |
| 158 function(_protobuf_find_threads) | 90 function(_protobuf_find_threads) |
| 159 set(CMAKE_THREAD_PREFER_PTHREAD TRUE) | 91 set(CMAKE_THREAD_PREFER_PTHREAD TRUE) |
| 160 find_package(Threads) | 92 find_package(Threads) |
| 161 if(Threads_FOUND) | 93 if(Threads_FOUND) |
| 162 list(APPEND PROTOBUF_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) | 94 list(APPEND PROTOBUF_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) |
| 163 set(PROTOBUF_LIBRARIES "${PROTOBUF_LIBRARIES}" PARENT_SCOPE) | 95 set(PROTOBUF_LIBRARIES "${PROTOBUF_LIBRARIES}" PARENT_SCOPE) |
| 164 endif() | 96 endif() |
| 165 endfunction() | 97 endfunction() |
| 166 | 98 |
| 167 # | 99 # |
| 168 # Main. | 100 # Main. |
| 169 # | 101 # |
| 170 | 102 |
| 171 # By default have PROTOBUF_GENERATE_CPP macro pass -I to protoc | 103 # By default have PROTOBUF_GENERATE_CPP macro pass -I to protoc |
| 172 # for each directory where a proto file is referenced. | 104 # for each directory where a proto file is referenced. |
| 173 if(NOT DEFINED PROTOBUF_GENERATE_CPP_APPEND_PATH) | 105 if(NOT DEFINED PROTOBUF_GENERATE_CPP_APPEND_PATH) |
| 174 set(PROTOBUF_GENERATE_CPP_APPEND_PATH TRUE) | 106 set(PROTOBUF_GENERATE_CPP_APPEND_PATH TRUE) |
| 175 endif() | 107 endif() |
| 176 | 108 |
| 177 # The Protobuf library | 109 # The Protobuf library |
| 178 _protobuf_find_libraries(Protobuf protobuf) | 110 _protobuf_find_libraries(PROTOBUF protobuf) |
| 179 | 111 |
| 180 # The Protobuf Lite library | 112 # The Protobuf Lite library |
| 181 _protobuf_find_libraries(Protobuf_LITE protobuf-lite) | 113 _protobuf_find_libraries(PROTOBUF_LITE protobuf-lite) |
| 182 | 114 |
| 183 # The Protobuf Protoc Library | 115 # The Protobuf Protoc Library |
| 184 _protobuf_find_libraries(Protobuf_PROTOC protoc) | 116 _protobuf_find_libraries(PROTOBUF_PROTOC protoc) |
| 185 | 117 |
| 186 if(UNIX) | 118 if(UNIX) |
| 187 _protobuf_find_threads() | 119 _protobuf_find_threads() |
| 188 endif() | 120 endif() |
| 189 | 121 |
| 190 # Set the include directory | 122 # Set the include directory |
| 191 get_target_property(Protobuf_INCLUDE_DIRS protobuf::libprotobuf | 123 set(PROTOBUF_INCLUDE_DIR "${_PROTOBUF_IMPORT_PREFIX}/@CMAKE_INSTALL_INCLUDEDIR@"
) |
| 192 INTERFACE_INCLUDE_DIRECTORIES) | |
| 193 | 124 |
| 194 # Set the protoc Executable | 125 # Set the protoc Executable |
| 195 get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc | 126 get_target_property(PROTOBUF_PROTOC_EXECUTABLE protoc |
| 196 IMPORTED_LOCATION_RELEASE) | 127 IMPORTED_LOCATION_RELEASE) |
| 197 if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}") | 128 if(NOT PROTOBUF_PROTOC_EXECUTABLE) |
| 198 get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc | 129 get_target_property(PROTOBUF_PROTOC_EXECUTABLE protoc |
| 199 IMPORTED_LOCATION_DEBUG) | 130 IMPORTED_LOCATION_DEBUG) |
| 200 endif() | 131 endif() |
| 201 | 132 |
| 202 # Version info variable | 133 include(FindPackageHandleStandardArgs) |
| 203 set(Protobuf_VERSION "@protobuf_VERSION@") | 134 FIND_PACKAGE_HANDLE_STANDARD_ARGS(PROTOBUF DEFAULT_MSG |
| 135 PROTOBUF_LIBRARY PROTOBUF_INCLUDE_DIR) |
| 204 | 136 |
| 205 include(FindPackageHandleStandardArgs) | 137 if(PROTOBUF_FOUND) |
| 206 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Protobuf | 138 set(PROTOBUF_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIR}) |
| 207 REQUIRED_VARS Protobuf_PROTOC_EXECUTABLE Protobuf_LIBRARIES Protobuf_INCLUDE
_DIRS | 139 endif() |
| 208 VERSION_VAR Protobuf_VERSION | |
| 209 ) | |
| 210 | |
| 211 # Backwards compatibility | |
| 212 # Define upper case versions of output variables | |
| 213 foreach(Camel | |
| 214 Protobuf_VERSION | |
| 215 Protobuf_SRC_ROOT_FOLDER | |
| 216 Protobuf_IMPORT_DIRS | |
| 217 Protobuf_DEBUG | |
| 218 Protobuf_INCLUDE_DIRS | |
| 219 Protobuf_LIBRARIES | |
| 220 Protobuf_PROTOC_LIBRARIES | |
| 221 Protobuf_LITE_LIBRARIES | |
| 222 Protobuf_LIBRARY | |
| 223 Protobuf_PROTOC_LIBRARY | |
| 224 Protobuf_INCLUDE_DIR | |
| 225 Protobuf_PROTOC_EXECUTABLE | |
| 226 Protobuf_LIBRARY_DEBUG | |
| 227 Protobuf_PROTOC_LIBRARY_DEBUG | |
| 228 Protobuf_LITE_LIBRARY | |
| 229 Protobuf_LITE_LIBRARY_DEBUG | |
| 230 ) | |
| 231 string(TOUPPER ${Camel} UPPER) | |
| 232 set(${UPPER} ${${Camel}}) | |
| 233 endforeach() | |
| OLD | NEW |