From 4eb02fe31edf655f736c68ac91acdbdfd24b550f Mon Sep 17 00:00:00 2001 From: Dennis Cappendijk Date: Mon, 29 May 2017 17:34:08 +0200 Subject: Add headers as part of cmake project tested only on windows with visual studio 2015 as generator --- cmake/libprotobuf-lite.cmake | 26 +++++++++- cmake/libprotobuf.cmake | 58 +++++++++++++++++++++- cmake/libprotoc.cmake | 111 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 192 insertions(+), 3 deletions(-) (limited to 'cmake') 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 b663e354..51226540 100644 --- a/cmake/libprotoc.cmake +++ b/cmake/libprotoc.cmake @@ -95,6 +95,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 @@ -108,7 +217,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 -- cgit v1.2.3 From ae85cb8ef3c763eb506c945fe68f8bf0f95f3728 Mon Sep 17 00:00:00 2001 From: Walter Gray Date: Tue, 30 May 2017 14:07:34 -0700 Subject: Fix find module not working when no version number was given --- cmake/protobuf-config-version.cmake.in | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'cmake') diff --git a/cmake/protobuf-config-version.cmake.in b/cmake/protobuf-config-version.cmake.in index 0036c9ef..8d391254 100644 --- a/cmake/protobuf-config-version.cmake.in +++ b/cmake/protobuf-config-version.cmake.in @@ -17,20 +17,22 @@ 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() -- cgit v1.2.3 From a183a0df61d1b505356c2befa9c2fb9d0fddd770 Mon Sep 17 00:00:00 2001 From: Walter Gray Date: Tue, 30 May 2017 14:11:46 -0700 Subject: Fix the check_and_save_build_option macro never evaluating to true --- cmake/protobuf-config-version.cmake.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmake') diff --git a/cmake/protobuf-config-version.cmake.in b/cmake/protobuf-config-version.cmake.in index 8d391254..e11e9fbb 100644 --- a/cmake/protobuf-config-version.cmake.in +++ b/cmake/protobuf-config-version.cmake.in @@ -39,7 +39,7 @@ 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}) -- cgit v1.2.3 From faa53989cb430b5c67ab35a29255a16881d4fb4a Mon Sep 17 00:00:00 2001 From: Walter Gray Date: Tue, 30 May 2017 14:56:02 -0700 Subject: fix check_and_save_build_option not correctly exporting build options --- cmake/protobuf-config-version.cmake.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmake') diff --git a/cmake/protobuf-config-version.cmake.in b/cmake/protobuf-config-version.cmake.in index e11e9fbb..ca6da09a 100644 --- a/cmake/protobuf-config-version.cmake.in +++ b/cmake/protobuf-config-version.cmake.in @@ -42,7 +42,7 @@ macro(_check_and_save_build_option OPTION 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@) -- cgit v1.2.3 From 0336770801c53543f4b1f3ebfd28dfc65e331c5c Mon Sep 17 00:00:00 2001 From: Walter Gray Date: Tue, 30 May 2017 16:49:18 -0700 Subject: add protobuf_generate function, allows use of target_sources where available --- cmake/protobuf-config.cmake.in | 99 ++++++++++++++++++++++++++++++++++++++++++ cmake/protobuf-module.cmake.in | 85 ++++++++---------------------------- examples/CMakeLists.txt | 17 +------- 3 files changed, 117 insertions(+), 84 deletions(-) (limited to 'cmake') 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 diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 2cd2acc0..3e8e6541 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -32,22 +32,6 @@ foreach(example add_person list_people) if(protobuf_MODULE_COMPATIBLE) #Legacy Support protobuf_generate_cpp(${example}_PROTO_SRCS ${example}_PROTO_HDRS ${${example}_PROTOS}) list(APPEND ${example}_SRCS ${${example}_PROTO_SRCS} ${${example}_PROTO_HDRS}) - else() - - foreach(proto_file ${${example}_PROTOS}) - get_filename_component(proto_file_abs ${proto_file} ABSOLUTE) - get_filename_component(basename ${proto_file} NAME_WE) - set(generated_files ${basename}.pb.cc ${basename}.pb.h) - list(APPEND ${example}_SRCS ${generated_files}) - - add_custom_command( - OUTPUT ${generated_files} - COMMAND protobuf::protoc - ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} -I ${CMAKE_CURRENT_SOURCE_DIR} ${proto_file_abs} - COMMENT "Generating ${generated_files} from ${proto_file}" - VERBATIM - ) - endforeach() endif() #Executable setup @@ -58,6 +42,7 @@ foreach(example add_person list_people) target_link_libraries(${executable_name} ${PROTOBUF_LIBRARIES}) else() target_link_libraries(${executable_name} protobuf::libprotobuf) + protobuf_generate(TARGET ${executable_name}) endif() endforeach() -- cgit v1.2.3 From 8f367c0b2df941d494c2bbea76b3a461321fb11b Mon Sep 17 00:00:00 2001 From: yjjnls Date: Mon, 19 Jun 2017 14:15:22 +0800 Subject: replenish missed header files in install step install 'generated_message_table_driven.h' and 'metadata_lite.h', they are included when compiling the files generated using protoc.exe 3.3.0 --- cmake/extract_includes.bat.in | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cmake') diff --git a/cmake/extract_includes.bat.in b/cmake/extract_includes.bat.in index 245e917f..1278ee87 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_reflec copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_enum_util.h" include\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_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 @@ -70,6 +71,7 @@ copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_type_handler.h" i copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\message.h" include\google\protobuf\message.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\message_lite.h" include\google\protobuf\message_lite.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\metadata.h" include\google\protobuf\metadata.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\metadata_lite.h" include\google\protobuf\metadata_lite.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\reflection.h" include\google\protobuf\reflection.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\reflection_ops.h" include\google\protobuf\reflection_ops.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\repeated_field.h" include\google\protobuf\repeated_field.h -- cgit v1.2.3