aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmake
diff options
context:
space:
mode:
authorGravatar Jisi Liu <jisi.liu@gmail.com>2017-07-18 16:26:16 -0700
committerGravatar Jisi Liu <jisi.liu@gmail.com>2017-07-18 16:26:16 -0700
commit3af881c7e2db0553207876acbdb91c6e77974e44 (patch)
tree35e2a96cce802d4235bd29afa396e28ead892fa2 /cmake
parent86975301f1876ce1934612777b8ca6c76520f5cc (diff)
parent942a29cecd36f2a4b22fdd2179635cd548e6bd27 (diff)
Merge master into 3.4.x
Diffstat (limited to 'cmake')
-rw-r--r--cmake/extract_includes.bat.in1
-rw-r--r--cmake/libprotobuf-lite.cmake26
-rw-r--r--cmake/libprotobuf.cmake58
-rw-r--r--cmake/libprotoc.cmake111
-rw-r--r--cmake/protobuf-config-version.cmake.in30
-rw-r--r--cmake/protobuf-config.cmake.in99
-rw-r--r--cmake/protobuf-module.cmake.in85
7 files changed, 325 insertions, 85 deletions
diff --git a/cmake/extract_includes.bat.in b/cmake/extract_includes.bat.in
index 0359b54f..baafeb97 100644
--- a/cmake/extract_includes.bat.in
+++ b/cmake/extract_includes.bat.in
@@ -51,6 +51,7 @@ copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_enum_util.h
copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_reflection.h" include\google\protobuf\generated_message_reflection.h
copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_table_driven.h" include\google\protobuf\generated_message_table_driven.h
copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_util.h" include\google\protobuf\generated_message_util.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_table_driven.h" include\google\protobuf\generated_message_table_driven.h
copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\has_bits.h" include\google\protobuf\has_bits.h
copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\coded_stream.h" include\google\protobuf\io\coded_stream.h
copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\gzip_stream.h" include\google\protobuf\io\gzip_stream.h
diff --git a/cmake/libprotobuf-lite.cmake b/cmake/libprotobuf-lite.cmake
index 036b0517..1ee9b9c5 100644
--- a/cmake/libprotobuf-lite.cmake
+++ b/cmake/libprotobuf-lite.cmake
@@ -24,8 +24,32 @@ set(libprotobuf_lite_files
${protobuf_source_dir}/src/google/protobuf/wire_format_lite.cc
)
+set(libprotobuf_lite_includes
+ ${protobuf_source_dir}/src/google/protobuf/arena.h
+ ${protobuf_source_dir}/src/google/protobuf/arenastring.h
+ ${protobuf_source_dir}/src/google/protobuf/extension_set.h
+ ${protobuf_source_dir}/src/google/protobuf/generated_message_util.h
+ ${protobuf_source_dir}/src/google/protobuf/io/coded_stream.h
+ ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream.h
+ ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl_lite.h
+ ${protobuf_source_dir}/src/google/protobuf/message_lite.h
+ ${protobuf_source_dir}/src/google/protobuf/repeated_field.h
+ ${protobuf_source_dir}/src/google/protobuf/stubs/atomicops_internals_x86_msvc.h
+ ${protobuf_source_dir}/src/google/protobuf/stubs/bytestream.h
+ ${protobuf_source_dir}/src/google/protobuf/stubs/common.h
+ ${protobuf_source_dir}/src/google/protobuf/stubs/int128.h
+ ${protobuf_source_dir}/src/google/protobuf/stubs/once.h
+ ${protobuf_source_dir}/src/google/protobuf/stubs/status.h
+ ${protobuf_source_dir}/src/google/protobuf/stubs/statusor.h
+ ${protobuf_source_dir}/src/google/protobuf/stubs/stringpiece.h
+ ${protobuf_source_dir}/src/google/protobuf/stubs/stringprintf.h
+ ${protobuf_source_dir}/src/google/protobuf/stubs/strutil.h
+ ${protobuf_source_dir}/src/google/protobuf/stubs/time.h
+ ${protobuf_source_dir}/src/google/protobuf/wire_format_lite.h
+)
+
add_library(libprotobuf-lite ${protobuf_SHARED_OR_STATIC}
- ${libprotobuf_lite_files})
+ ${libprotobuf_lite_files} ${libprotobuf_lite_includes})
target_link_libraries(libprotobuf-lite ${CMAKE_THREAD_LIBS_INIT})
target_include_directories(libprotobuf-lite PUBLIC ${protobuf_source_dir}/src)
if(MSVC AND protobuf_BUILD_SHARED_LIBS)
diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake
index 5313d39e..030924d2 100644
--- a/cmake/libprotobuf.cmake
+++ b/cmake/libprotobuf.cmake
@@ -55,8 +55,64 @@ set(libprotobuf_files
${protobuf_source_dir}/src/google/protobuf/wrappers.pb.cc
)
+set(libprotobuf_includes
+ ${protobuf_source_dir}/src/google/protobuf/any.h
+ ${protobuf_source_dir}/src/google/protobuf/any.pb.h
+ ${protobuf_source_dir}/src/google/protobuf/api.pb.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/importer.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/parser.h
+ ${protobuf_source_dir}/src/google/protobuf/descriptor.h
+ ${protobuf_source_dir}/src/google/protobuf/descriptor.pb.h
+ ${protobuf_source_dir}/src/google/protobuf/descriptor_database.h
+ ${protobuf_source_dir}/src/google/protobuf/duration.pb.h
+ ${protobuf_source_dir}/src/google/protobuf/dynamic_message.h
+ ${protobuf_source_dir}/src/google/protobuf/empty.pb.h
+ ${protobuf_source_dir}/src/google/protobuf/field_mask.pb.h
+ ${protobuf_source_dir}/src/google/protobuf/generated_message_reflection.h
+ ${protobuf_source_dir}/src/google/protobuf/io/gzip_stream.h
+ ${protobuf_source_dir}/src/google/protobuf/io/printer.h
+ ${protobuf_source_dir}/src/google/protobuf/io/strtod.h
+ ${protobuf_source_dir}/src/google/protobuf/io/tokenizer.h
+ ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl.h
+ ${protobuf_source_dir}/src/google/protobuf/map_field.h
+ ${protobuf_source_dir}/src/google/protobuf/message.h
+ ${protobuf_source_dir}/src/google/protobuf/reflection_ops.h
+ ${protobuf_source_dir}/src/google/protobuf/service.h
+ ${protobuf_source_dir}/src/google/protobuf/source_context.pb.h
+ ${protobuf_source_dir}/src/google/protobuf/struct.pb.h
+ ${protobuf_source_dir}/src/google/protobuf/stubs/mathlimits.h
+ ${protobuf_source_dir}/src/google/protobuf/stubs/substitute.h
+ ${protobuf_source_dir}/src/google/protobuf/text_format.h
+ ${protobuf_source_dir}/src/google/protobuf/timestamp.pb.h
+ ${protobuf_source_dir}/src/google/protobuf/type.pb.h
+ ${protobuf_source_dir}/src/google/protobuf/unknown_field_set.h
+ ${protobuf_source_dir}/src/google/protobuf/util/delimited_message_util.h
+ ${protobuf_source_dir}/src/google/protobuf/util/field_comparator.h
+ ${protobuf_source_dir}/src/google/protobuf/util/field_mask_util.h
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/datapiece.h
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/default_value_objectwriter.h
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/error_listener.h
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/field_mask_utility.h
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/json_escaping.h
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/json_objectwriter.h
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/json_stream_parser.h
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/object_writer.h
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/proto_writer.h
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectsource.h
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectwriter.h
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/type_info.h
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/type_info_test_helper.h
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/utility.h
+ ${protobuf_source_dir}/src/google/protobuf/util/json_util.h
+ ${protobuf_source_dir}/src/google/protobuf/util/message_differencer.h
+ ${protobuf_source_dir}/src/google/protobuf/util/time_util.h
+ ${protobuf_source_dir}/src/google/protobuf/util/type_resolver_util.h
+ ${protobuf_source_dir}/src/google/protobuf/wire_format.h
+ ${protobuf_source_dir}/src/google/protobuf/wrappers.pb.h
+)
+
add_library(libprotobuf ${protobuf_SHARED_OR_STATIC}
- ${libprotobuf_lite_files} ${libprotobuf_files})
+ ${libprotobuf_lite_files} ${libprotobuf_files} ${libprotobuf_includes})
target_link_libraries(libprotobuf ${CMAKE_THREAD_LIBS_INIT})
if(protobuf_WITH_ZLIB)
target_link_libraries(libprotobuf ${ZLIB_LIBRARIES})
diff --git a/cmake/libprotoc.cmake b/cmake/libprotoc.cmake
index 29b32538..eb408576 100644
--- a/cmake/libprotoc.cmake
+++ b/cmake/libprotoc.cmake
@@ -94,6 +94,115 @@ set(libprotoc_files
${protobuf_source_dir}/src/google/protobuf/compiler/zip_writer.cc
)
+set(libprotoc_headers
+ ${protobuf_source_dir}/src/google/protobuf/compiler/code_generator.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/command_line_interface.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/importer.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/mock_code_generator.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/package_info.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/parser.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/plugin.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/plugin.pb.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/profile.pb.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/subprocess.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/zip_writer.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_enum.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_enum_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_extension.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_file.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_generator.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_helpers.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_map_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_message.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_message_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_options.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_primitive_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_service.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_string_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_unittest.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_doc_comment.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_enum.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_enum_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_field_base.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_generator.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_helpers.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_map_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_message.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_message_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_names.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_options.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_primitive_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_reflection_class.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_source_generator_base.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_context.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_doc_comment.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_enum.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_enum_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_enum_field_lite.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_enum_lite.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_extension.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_extension_lite.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_file.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_generator.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_generator_factory.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_helpers.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_lazy_message_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_lazy_message_field_lite.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_map_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_map_field_lite.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message_builder.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message_builder_lite.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message_field_lite.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message_lite.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_names.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_name_resolver.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_options.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_primitive_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_primitive_field_lite.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_service.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_shared_code_generator.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_string_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_string_field_lite.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_enum.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_enum_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_extension.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_file.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_generator.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_helpers.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_map_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_message.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_message_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_params.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_primitive_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/js/js_generator.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/js/well_known_types_embed.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_enum.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_extension.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_file.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_generator.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_helpers.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_map_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_message.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_message_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_oneof.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/php/php_generator.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/python/python_generator.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/ruby/ruby_generator.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/plugin.pb.h
+)
+
set(js_well_known_types_sources
${protobuf_source_dir}/src/google/protobuf/compiler/js/well_known_types/any.js
${protobuf_source_dir}/src/google/protobuf/compiler/js/well_known_types/struct.js
@@ -107,7 +216,7 @@ add_custom_command(
)
add_library(libprotoc ${protobuf_SHARED_OR_STATIC}
- ${libprotoc_files})
+ ${libprotoc_files} ${libprotoc_headers})
target_link_libraries(libprotoc libprotobuf)
if(MSVC AND protobuf_BUILD_SHARED_LIBS)
target_compile_definitions(libprotoc
diff --git a/cmake/protobuf-config-version.cmake.in b/cmake/protobuf-config-version.cmake.in
index 0036c9ef..ca6da09a 100644
--- a/cmake/protobuf-config-version.cmake.in
+++ b/cmake/protobuf-config-version.cmake.in
@@ -17,30 +17,32 @@ endif()
set(PACKAGE_VERSION_COMPATIBLE TRUE) #Assume true until shown otherwise
-if(NOT PACKAGE_FIND_VERSION_MAJOR EQUAL "@protobuf_VERSION_MAJOR@")
- set(PACKAGE_VERSION_COMPATIBLE FALSE)
-elseif(PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION)
- set(PACKAGE_VERSION_COMPATIBLE FALSE)
-elseif(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
- # Do not match prerelease versions to non-prerelease version requests.
- if(NOT "@protobuf_VERSION_PRERELEASE@" STREQUAL "" AND PACKAGE_FIND_VERSION_PRERELEASE STREQUAL "")
- message(AUTHOR_WARNING "To use this prerelease version of ${PACKAGE_FIND_NAME}, set ${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE to '@protobuf_VERSION_PRERELEASE@' or greater.")
+if(PACKAGE_FIND_VERSION) #Only perform version checks if one is given
+ if(NOT PACKAGE_FIND_VERSION_MAJOR EQUAL "@protobuf_VERSION_MAJOR@")
set(PACKAGE_VERSION_COMPATIBLE FALSE)
- endif()
-
- # Not robustly SemVer compliant, but protobuf never uses '.' separated prerelease identifiers.
- if(PACKAGE_FIND_VERSION_PRERELEASE STRGREATER "@protobuf_VERSION_PRERELEASE@")
+ elseif(PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
+ elseif(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
+ # Do not match prerelease versions to non-prerelease version requests.
+ if(NOT "@protobuf_VERSION_PRERELEASE@" STREQUAL "" AND PACKAGE_FIND_VERSION_PRERELEASE STREQUAL "")
+ message(AUTHOR_WARNING "To use this prerelease version of ${PACKAGE_FIND_NAME}, set ${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE to '@protobuf_VERSION_PRERELEASE@' or greater.")
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+ endif()
+
+ # Not robustly SemVer compliant, but protobuf never uses '.' separated prerelease identifiers.
+ if(PACKAGE_FIND_VERSION_PRERELEASE STRGREATER "@protobuf_VERSION_PRERELEASE@")
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+ endif()
endif()
endif()
# Check and save build options used to create this package
macro(_check_and_save_build_option OPTION VALUE)
if(DEFINED ${PACKAGE_FIND_NAME}_${OPTION} AND
- NOT ${PACKAGE_FIND_NAME}_${OPTION} EQUAL VALUE)
+ NOT ${PACKAGE_FIND_NAME}_${OPTION} STREQUAL ${VALUE})
set(PACKAGE_VERSION_UNSUITABLE TRUE)
endif()
- set(${PACKAGE_FIND_NAME}_${OPTION} ${VALUE})
+ set(${PACKAGE_FIND_NAME}_${OPTION} ${VALUE} PARENT_SCOPE)
endmacro()
_check_and_save_build_option(WITH_ZLIB @protobuf_WITH_ZLIB@)
_check_and_save_build_option(MSVC_STATIC_RUNTIME @protobuf_MSVC_STATIC_RUNTIME@)
diff --git a/cmake/protobuf-config.cmake.in b/cmake/protobuf-config.cmake.in
index a044fe5c..83213547 100644
--- a/cmake/protobuf-config.cmake.in
+++ b/cmake/protobuf-config.cmake.in
@@ -7,6 +7,105 @@ include("${CMAKE_CURRENT_LIST_DIR}/protobuf-options.cmake")
# Imported targets
include("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake")
+function(protobuf_generate)
+ include(CMakeParseArguments)
+ set(_singleargs LANGUAGE OUT_VAR)
+ if(COMMAND target_sources)
+ list(APPEND _singleargs TARGET)
+ endif()
+
+ cmake_parse_arguments(protobuf_generate "APPEND_PATH" "${_singleargs}" "PROTOS IMPORT_DIRS GENERATE_EXTENSIONS" "${ARGN}")
+
+ if(protobuf_generate_PROTOS AND NOT protobuf_generate_TARGET)
+ message(SEND_ERROR "Error: protobuf_generate called without any targets or source files")
+ return()
+ endif()
+
+ if(NOT protobuf_generate_OUT_VAR AND NOT protobuf_generate_TARGET)
+ message(SEND_ERROR "Error: protobuf_generate called without a target or output variable")
+ return()
+ endif()
+
+ if(NOT protobuf_generate_LANGUAGE)
+ set(protobuf_generate_LANGUAGE cpp)
+ endif()
+ string(TOLOWER ${protobuf_generate_LANGUAGE} protobuf_generate_LANGUAGE)
+
+ if(NOT protobuf_GENERATE_EXTENSIONS)
+ if(protobuf_generate_LANGUAGE STREQUAL cpp)
+ set(protobuf_GENERATE_EXTENSIONS .pb.h .pb.cc)
+ elseif(protobuf_generate_LANGUAGE STREQUAL python)
+ set(protobuf_GENERATE_EXTENSIONS _pb2.py)
+ else()
+ message(SEND_ERROR "Error: protobuf_generate given unknown Language ${LANGUAGE}, please provide a value for GENERATE_EXTENSIONS")
+ return()
+ endif()
+ endif()
+
+ if(protobuf_generate_APPEND_PATH)
+ # Create an include path for each file specified
+ foreach(_file ${ARGN})
+ get_filename_component(_abs_file ${_file} ABSOLUTE)
+ get_filename_component(_abs_path ${_abs_file} 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()
+
+ foreach(DIR ${protobuf_generate_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()
+
+ if(protobuf_generate_TARGET)
+ get_target_property(_source_list ${protobuf_generate_TARGET} SOURCES)
+ foreach(_file ${_source_list})
+ if(_file MATCHES "proto$")
+ list(APPEND protobuf_generate_PROTOS ${_file})
+ endif()
+ endforeach()
+ endif()
+
+ if(NOT protobuf_generate_PROTOS)
+ message(SEND_ERROR "Error: protobuf_generate could not find any .proto files")
+ return()
+ endif()
+
+ set(_generated_srcs)
+ foreach(_proto ${protobuf_generate_PROTOS})
+ get_filename_component(_abs_file ${_proto} ABSOLUTE)
+ get_filename_component(_basename ${_proto} NAME_WE)
+
+ foreach(_ext ${_output_extensions})
+ list(APPEND _generated_srcs "${CMAKE_CURRENT_BINARY_DIR}/${_basename}${_ext}")
+ endforeach()
+
+ add_custom_command(
+ OUTPUT ${_generated_srcs}
+ COMMAND protobuf::protoc
+ ARGS --${protobuf_generate_LANGUAGE}_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${_abs_file}
+ DEPENDS ${ABS_FIL} protobuf::protoc
+ COMMENT "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}"
+ VERBATIM )
+ endforeach()
+
+ set_source_files_properties(${_generated_srcs} PROPERTIES GENERATED TRUE)
+ if(protobuf_generate_OUT_VAR)
+ set(${protobuf_generate_OUT_VAR} ${_generated_srcs} PARENT_SCOPE)
+ endif()
+ if(protobuf_generate_TARGET)
+ target_sources(${protobuf_generate_TARGET} PUBLIC ${_generated_srcs})
+ endif()
+
+endfunction()
+
# CMake FindProtobuf module compatible file
if(protobuf_MODULE_COMPATIBLE)
include("${CMAKE_CURRENT_LIST_DIR}/protobuf-module.cmake")
diff --git a/cmake/protobuf-module.cmake.in b/cmake/protobuf-module.cmake.in
index 614e4c04..8e4920aa 100644
--- a/cmake/protobuf-module.cmake.in
+++ b/cmake/protobuf-module.cmake.in
@@ -1,3 +1,4 @@
+# This file contains backwards compatibility patches for various legacy functions and variables
# Functions
function(PROTOBUF_GENERATE_CPP SRCS HDRS)
@@ -7,49 +8,25 @@ function(PROTOBUF_GENERATE_CPP SRCS HDRS)
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})
+ set(_append_arg APPEND_PATH)
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()
+ set(_import_arg IMPORT_DIRS ${Protobuf_IMPORT_DIRS})
endif()
+ set(_outvar)
+ protobuf_generate(${append_arg} LANGUAGE cpp OUT_VAR _outvar ${_import_arg} PROTOS ${ARGN})
+
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 )
+ foreach(_file ${_outvar})
+ if(_file MATCHES "cc$")
+ list(APPEND ${SRCS} ${_file})
+ else()
+ list(APPEND ${HDRS} ${_file})
+ endif()
endforeach()
-
- set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
set(${SRCS} ${${SRCS}} PARENT_SCOPE)
set(${HDRS} ${${HDRS}} PARENT_SCOPE)
endfunction()
@@ -61,44 +38,16 @@ function(PROTOBUF_GENERATE_PYTHON SRCS)
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})
+ set(_append_arg APPEND_PATH)
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()
+ set(_import_arg IMPORT_DIRS ${Protobuf_IMPORT_DIRS})
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)
+ set(_outvar)
+ protobuf_generate(${append_arg} LANGUAGE cpp OUT_VAR _outvar ${_import_arg} PROTOS ${ARGN})
+ set(${SRCS} ${_outvar} PARENT_SCOPE)
endfunction()
# Environment