diff options
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/CMakeLists.txt | 78 | ||||
-rw-r--r-- | cmake/README.md | 127 | ||||
-rw-r--r-- | cmake/config.h.in | 4 | ||||
-rw-r--r-- | cmake/extract_includes.bat.in | 105 | ||||
-rw-r--r-- | cmake/find_hash_map.cmake | 119 | ||||
-rw-r--r-- | cmake/libprotobuf-lite.cmake | 23 | ||||
-rw-r--r-- | cmake/libprotobuf.cmake | 42 | ||||
-rw-r--r-- | cmake/libprotoc.cmake | 95 | ||||
-rw-r--r-- | cmake/pbconfig.h.in | 9 | ||||
-rw-r--r-- | cmake/protoc.cmake | 6 | ||||
-rw-r--r-- | cmake/tests.cmake | 148 | ||||
-rwxr-xr-x | cmake/update_file_lists.sh | 121 |
12 files changed, 877 insertions, 0 deletions
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt new file mode 100644 index 00000000..727864ba --- /dev/null +++ b/cmake/CMakeLists.txt @@ -0,0 +1,78 @@ +cmake_minimum_required(VERSION 2.8) + +project(protobuf C CXX) + +option(BUILD_TESTING "Build tests" ON) +option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) +if (MSVC) + option(ZLIB "Build with zlib support" OFF) +endif (MSVC) + +find_package(Threads REQUIRED) +if (CMAKE_USE_PTHREADS_INIT) + set(HAVE_PTHREAD 1) +else (CMAKE_USE_PTHREADS_INIT) + set(HAVE_PTHREAD 0) +endif (CMAKE_USE_PTHREADS_INIT) + +if (MSVC) + if (ZLIB) + set(HAVE_ZLIB 1) + find_path(ZLIB_INCLUDE_DIRECTORIES zlib.h ${protobuf_SOURCE_DIR}) + find_library(ZLIB_LIBRARIES zdll ${protobuf_SOURCE_DIR}) + else (ZLIB) + set(HAVE_ZLIB 0) + endif (ZLIB) +else (MSVC) + find_package(ZLIB) + if (ZLIB_FOUND) + set(HAVE_ZLIB 1) + else (ZLIB_FOUND) + set(HAVE_ZLIB 0) + # Explicitly set these to empty (override NOT_FOUND) so cmake doesn't + # complain when we use them later. + set(ZLIB_INCLUDE_DIRECTORIES) + set(ZLIB_LIBRARIES) + endif (ZLIB_FOUND) +endif (MSVC) + +if (MSVC) + if (BUILD_SHARED_LIBS) + add_definitions(-DPROTOBUF_USE_DLLS) + endif (BUILD_SHARED_LIBS) + add_definitions(/wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146 /wd4305) +endif (MSVC) + +include(find_hash_map.cmake) + +configure_file(config.h.in config.h) +configure_file(pbconfig.h.in google/protobuf/stubs/pbconfig.h) +if (MSVC) + string(REPLACE "/" "\\" PROTOBUF_SOURCE_WIN32_PATH ${protobuf_SOURCE_DIR}) + string(REPLACE "/" "\\" PROTOBUF_BINARY_WIN32_PATH ${protobuf_BINARY_DIR}) + configure_file(extract_includes.bat.in extract_includes.bat) +endif (MSVC) + +get_filename_component(protobuf_source_dir ${protobuf_SOURCE_DIR} PATH) + +include_directories( + ${ZLIB_INCLUDE_DIRECTORIES} + ${protobuf_BINARY_DIR} + ${protobuf_source_dir}/src) + +if (MSVC) + # Add the "lib" prefix for generated .lib outputs. + set(LIB_PREFIX lib) +else (MSVC) + # When building with "make", "lib" prefix will be added automatically by + # the build tool. + set(LIB_PREFIX) +endif (MSVC) + +include(libprotobuf-lite.cmake) +include(libprotobuf.cmake) +include(libprotoc.cmake) +include(protoc.cmake) +if (BUILD_TESTING) + include(tests.cmake) +endif (BUILD_TESTING) diff --git a/cmake/README.md b/cmake/README.md new file mode 100644 index 00000000..02798b63 --- /dev/null +++ b/cmake/README.md @@ -0,0 +1,127 @@ +This directory contains cmake files that can be used to generate MSVC project +files in order to build protobuf on windows. You need to have cmake installed +on your computer before proceeding. + +Compiling and Installing +======================== + +1. Check whether a gtest directory exists in the upper level directory. If + you checkout the code from github via "git clone", this gtest directory + won't exist and you won't be able to build the tests described below. To + avoid this problem consider downloading one of the release tar balls which + contains gtest already and copying the gest directory from there to your + protobuf directory: + + https://github.com/google/protobuf/releases + +2. Use cmake to generate MSVC project files. Running the following commands + in a command shell will generate project files for Visual Studio 2008 in + a sub-directory named "build". + + $ cd path/to/protobuf/cmake + $ mkdir build + $ cd build + $ cmake -G "Visual Studio 9 2008" .. + +3. Open the generated protobuf.sln file in Microsoft Visual Studio. +4. Choose "Debug" or "Release" configuration as desired. +5. From the Build menu, choose "Build Solution". Wait for compiling to finish. +6. From a command shell, run tests.exe and lite-test.exe and check that all + tests pass. Make sure you have changed the working directory to the output + directory because tests.exe will try to find and run test_plugin.exe + in the working directory. +7. Run extract_includes.bat to copy all the public headers into a separate + "include" directory (under the top-level package directory). +8. Copy the contents of the include directory to wherever you want to put + headers. +9. Copy protoc.exe wherever you put build tools (probably somewhere in your + PATH). +10. Copy libprotobuf.lib, libprotobuf-lite.lib, and libprotoc.lib wherever you + put libraries. + + To avoid conflicts between the MSVC debug and release runtime libraries, when + compiling a debug build of your application, you may need to link against a + debug build of libprotobuf.lib. Similarly, release builds should link against + release libs. + +DLLs vs. static linking +======================= + +Static linking is now the default for the Protocol Buffer libraries. Due to +issues with Win32's use of a separate heap for each DLL, as well as binary +compatibility issues between different versions of MSVC's STL library, it is +recommended that you use static linkage only. However, it is possible to +build libprotobuf and libprotoc as DLLs if you really want. To do this, +do the following: + + 1. Add an additional flag "-DBUILD_SHARED_LIBS=ON" when invoking cmake: + + $ cmake -G "Visual Studio 9 2008" -DBUILD_SHARED_LIBS=ON .. + + 2. Follow the same steps as described in the above section. + 3. When compiling your project, make sure to #define PROTOBUF_USE_DLLS. + +When distributing your software to end users, we strongly recommend that you +do NOT install libprotobuf.dll or libprotoc.dll to any shared location. +Instead, keep these libraries next to your binaries, in your application's +own install directory. C++ makes it very difficult to maintain binary +compatibility between releases, so it is likely that future versions of these +libraries will *not* be usable as drop-in replacements. + +If your project is itself a DLL intended for use by third-party software, we +recommend that you do NOT expose protocol buffer objects in your library's +public interface, and that you statically link protocol buffers into your +library. + +ZLib support +============ + +If you want to include GzipInputStream and GzipOutputStream +(google/protobuf/io/gzip_stream.h) in libprotobuf, you will need to do a few +additional steps: + +1. Obtain a copy of the zlib library. The pre-compiled DLL at zlib.net works. +2. Make sure zlib's two headers are in your include path and that the .lib file + is in your library path. You could place all three files directly into this + cmake directory to compile libprotobuf, but they need to be visible to + your own project as well, so you should probably just put them into the + VC shared icnlude and library directories. +3. Add flag "-DZLIB=ON" when invoking cmake: + + $ cmake -G "Visual Studio 9 2008" -DZLIB=ON .. + + If it reports NOTFOUND for zlib_include or zlib_lib, you might haven't put + the headers or the .lib file in the right directory. +4) Open the generated protobuf.sln file and build as usual. + +Notes on Compiler Warnings +========================== + +The following warnings have been disabled while building the protobuf libraries +and compiler. You may have to disable some of them in your own project as +well, or live with them. + +* C4018 - 'expression' : signed/unsigned mismatch +* C4146 - unary minus operator applied to unsigned type, result still unsigned +* C4244 - Conversion from 'type1' to 'type2', possible loss of data. +* C4251 - 'identifier' : class 'type' needs to have dll-interface to be used by + clients of class 'type2' +* C4267 - Conversion from 'size_t' to 'type', possible loss of data. +* C4305 - 'identifier' : truncation from 'type1' to 'type2' +* C4355 - 'this' : used in base member initializer list +* C4800 - 'type' : forcing value to bool 'true' or 'false' (performance warning) +* C4996 - 'function': was declared deprecated + +C4251 is of particular note, if you are compiling the Protocol Buffer library +as a DLL (see previous section). The protocol buffer library uses templates in +its public interfaces. MSVC does not provide any reasonable way to export +template classes from a DLL. However, in practice, it appears that exporting +templates is not necessary anyway. Since the complete definition of any +template is available in the header files, anyone importing the DLL will just +end up compiling instances of the templates into their own binary. The +Protocol Buffer implementation does not rely on static template members being +unique, so there should be no problem with this, but MSVC prints warning +nevertheless. So, we disable it. Unfortunately, this warning will also be +produced when compiling code which merely uses protocol buffers, meaning you +may have to disable it in your code too. + diff --git a/cmake/config.h.in b/cmake/config.h.in new file mode 100644 index 00000000..bca1cbba --- /dev/null +++ b/cmake/config.h.in @@ -0,0 +1,4 @@ +#define GOOGLE_PROTOBUF_CMAKE_BUILD + +#define HAVE_PTHREAD ${HAVE_PTHREAD} +#define HAVE_ZLIB ${HAVE_ZLIB} diff --git a/cmake/extract_includes.bat.in b/cmake/extract_includes.bat.in new file mode 100644 index 00000000..b2e9444d --- /dev/null +++ b/cmake/extract_includes.bat.in @@ -0,0 +1,105 @@ +mkdir include +mkdir include\google +mkdir include\google\protobuf +mkdir include\google\protobuf\compiler +mkdir include\google\protobuf\compiler\cpp +mkdir include\google\protobuf\compiler\csharp +mkdir include\google\protobuf\compiler\java +mkdir include\google\protobuf\compiler\javanano +mkdir include\google\protobuf\compiler\objectivec +mkdir include\google\protobuf\compiler\python +mkdir include\google\protobuf\compiler\ruby +mkdir include\google\protobuf\io +mkdir include\google\protobuf\stubs +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\any.h include\google\protobuf\any.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\any.pb.h include\google\protobuf\any.pb.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\api.pb.h include\google\protobuf\api.pb.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\arena.h include\google\protobuf\arena.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\arenastring.h include\google\protobuf\arenastring.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\code_generator.h include\google\protobuf\compiler\code_generator.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\command_line_interface.h include\google\protobuf\compiler\command_line_interface.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\cpp\cpp_generator.h include\google\protobuf\compiler\cpp\cpp_generator.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\csharp\csharp_generator.h include\google\protobuf\compiler\csharp\csharp_generator.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\importer.h include\google\protobuf\compiler\importer.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\java_generator.h include\google\protobuf\compiler\java\java_generator.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\java_names.h include\google\protobuf\compiler\java\java_names.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\javanano\javanano_generator.h include\google\protobuf\compiler\javanano\javanano_generator.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\objectivec\objectivec_generator.h include\google\protobuf\compiler\objectivec\objectivec_generator.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\objectivec\objectivec_helpers.h include\google\protobuf\compiler\objectivec\objectivec_helpers.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\parser.h include\google\protobuf\compiler\parser.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\plugin.h include\google\protobuf\compiler\plugin.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\plugin.pb.h include\google\protobuf\compiler\plugin.pb.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\python\python_generator.h include\google\protobuf\compiler\python\python_generator.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\ruby\ruby_generator.h include\google\protobuf\compiler\ruby\ruby_generator.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\descriptor.h include\google\protobuf\descriptor.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\descriptor.pb.h include\google\protobuf\descriptor.pb.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\descriptor_database.h include\google\protobuf\descriptor_database.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\duration.pb.h include\google\protobuf\duration.pb.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\dynamic_message.h include\google\protobuf\dynamic_message.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\empty.pb.h include\google\protobuf\empty.pb.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\extension_set.h include\google\protobuf\extension_set.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\field_mask.pb.h include\google\protobuf\field_mask.pb.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_enum_reflection.h include\google\protobuf\generated_enum_reflection.h +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\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 +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\printer.h include\google\protobuf\io\printer.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\strtod.h include\google\protobuf\io\strtod.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\tokenizer.h include\google\protobuf\io\tokenizer.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\zero_copy_stream.h include\google\protobuf\io\zero_copy_stream.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\zero_copy_stream_impl.h include\google\protobuf\io\zero_copy_stream_impl.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\zero_copy_stream_impl_lite.h include\google\protobuf\io\zero_copy_stream_impl_lite.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map.h include\google\protobuf\map.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_entry.h include\google\protobuf\map_entry.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_entry_lite.h include\google\protobuf\map_entry_lite.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_field.h include\google\protobuf\map_field.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_field_inl.h include\google\protobuf\map_field_inl.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_field_lite.h include\google\protobuf\map_field_lite.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_type_handler.h include\google\protobuf\map_type_handler.h +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\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 +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\repeated_field_reflection.h include\google\protobuf\repeated_field_reflection.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\service.h include\google\protobuf\service.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\source_context.pb.h include\google\protobuf\source_context.pb.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\struct.pb.h include\google\protobuf\struct.pb.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomic_sequence_num.h include\google\protobuf\stubs\atomic_sequence_num.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops.h include\google\protobuf\stubs\atomicops.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_aix.h include\google\protobuf\stubs\atomicops_internals_aix.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_arm64_gcc.h include\google\protobuf\stubs\atomicops_internals_arm64_gcc.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_arm_gcc.h include\google\protobuf\stubs\atomicops_internals_arm_gcc.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_arm_qnx.h include\google\protobuf\stubs\atomicops_internals_arm_qnx.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_atomicword_compat.h include\google\protobuf\stubs\atomicops_internals_atomicword_compat.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_generic_gcc.h include\google\protobuf\stubs\atomicops_internals_generic_gcc.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_macosx.h include\google\protobuf\stubs\atomicops_internals_macosx.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_mips_gcc.h include\google\protobuf\stubs\atomicops_internals_mips_gcc.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_pnacl.h include\google\protobuf\stubs\atomicops_internals_pnacl.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_solaris.h include\google\protobuf\stubs\atomicops_internals_solaris.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_tsan.h include\google\protobuf\stubs\atomicops_internals_tsan.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_x86_gcc.h include\google\protobuf\stubs\atomicops_internals_x86_gcc.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_x86_msvc.h include\google\protobuf\stubs\atomicops_internals_x86_msvc.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\casts.h include\google\protobuf\stubs\casts.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\common.h include\google\protobuf\stubs\common.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\fastmem.h include\google\protobuf\stubs\fastmem.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\hash.h include\google\protobuf\stubs\hash.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\once.h include\google\protobuf\stubs\once.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\platform_macros.h include\google\protobuf\stubs\platform_macros.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\shared_ptr.h include\google\protobuf\stubs\shared_ptr.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\singleton.h include\google\protobuf\stubs\singleton.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\stl_util.h include\google\protobuf\stubs\stl_util.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\template_util.h include\google\protobuf\stubs\template_util.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\type_traits.h include\google\protobuf\stubs\type_traits.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\text_format.h include\google\protobuf\text_format.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\timestamp.pb.h include\google\protobuf\timestamp.pb.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\type.pb.h include\google\protobuf\type.pb.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\unknown_field_set.h include\google\protobuf\unknown_field_set.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\wire_format.h include\google\protobuf\wire_format.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\wire_format_lite.h include\google\protobuf\wire_format_lite.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\wire_format_lite_inl.h include\google\protobuf\wire_format_lite_inl.h +copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\wrappers.pb.h include\google\protobuf\wrappers.pb.h +copy ${PROTOBUF_BINARY_WIN32_PATH}\google\protobuf\stubs\pbconfig.h include\google\protobuf\stubs\pbconfig.h diff --git a/cmake/find_hash_map.cmake b/cmake/find_hash_map.cmake new file mode 100644 index 00000000..22796fb8 --- /dev/null +++ b/cmake/find_hash_map.cmake @@ -0,0 +1,119 @@ +include(CheckCXXSourceCompiles) + +function(find_hash_map) + set(HAVE_HASH_MAP 1 PARENT_SCOPE) + set(HAVE_HASH_SET 1 PARENT_SCOPE) + # Search for hash_map in the following order: + # 1. <unordered_map> ::std::unordered_map + # 2. <tr1/unordered_map> ::std::tr1::unordered_map + # 3. <hash_map> ::hash_map + # 4. <hash_map> ::stdext::hash_map + # 5. <ext/hash_map> ::std::hash_map + # 6. <ext/hash_map> ::__gnu_cxx::hash_map + check_cxx_source_compiles(" + #include <unordered_map> + int main() { ::std::unordered_map<int, int> v; return v[0]; } + " HAS_STD_UNORDERED_MAP) + if (HAS_STD_UNORDERED_MAP) + set(HASH_NAMESPACE ::std PARENT_SCOPE) + set(HASH_MAP_H <unordered_map> PARENT_SCOPE) + set(HASH_MAP_CLASS unordered_map PARENT_SCOPE) + set(HASH_SET_H <unordered_set> PARENT_SCOPE) + set(HASH_SET_CLASS unordered_set PARENT_SCOPE) + return() + endif (HAS_STD_UNORDERED_MAP) + + check_cxx_source_compiles(" + #include <tr1/unordered_map> + int main() { ::std::tr1::unordered_map<int, int> v; return v[0]; } + " HAS_STD_TR1_UNORDERED_MAP) + if (HAS_STD_TR1_UNORDERED_MAP) + set(HASH_NAMESPACE ::std::tr1 PARENT_SCOPE) + set(HASH_MAP_H <tr1/unordered_map> PARENT_SCOPE) + set(HASH_MAP_CLASS unordered_map PARENT_SCOPE) + set(HASH_SET_H <tr1/unordered_set> PARENT_SCOPE) + set(HASH_SET_CLASS unordered_set PARENT_SCOPE) + return() + endif (HAS_STD_TR1_UNORDERED_MAP) + + check_cxx_source_compiles(" + #include <hash_map> + int main() { ::hash_map<int, int> v; return v[0]; } + " HAS_HASH_MAP) + if (HAS_HASH_MAP) + set(HASH_NAMESPACE :: PARENT_SCOPE) + set(HASH_MAP_H <hash_map> PARENT_SCOPE) + set(HASH_MAP_CLASS hash_map PARENT_SCOPE) + set(HASH_SET_H <hash_set> PARENT_SCOPE) + set(HASH_SET_CLASS hash_set PARENT_SCOPE) + return() + endif (HAS_HASH_MAP) + + check_cxx_source_compiles(" + #include <hash_map> + int main() { ::stdext::hash_map<int, int> v; return v[0]; } + " HAS_STDEXT_HASH_MAP) + if (HAS_STDEXT_HASH_MAP) + set(HASH_NAMESPACE ::stdext PARENT_SCOPE) + set(HASH_MAP_H <hash_map> PARENT_SCOPE) + set(HASH_MAP_CLASS hash_map PARENT_SCOPE) + set(HASH_SET_H <hash_set> PARENT_SCOPE) + set(HASH_SET_CLASS hash_set PARENT_SCOPE) + return() + endif (HAS_STDEXT_HASH_MAP) + + check_cxx_source_compiles(" + #include <ext/hash_map> + int main() { ::std::hash_map<int, int> v; return v[0]; } + " HAS_STD_HASH_MAP) + if (HAS_STD_HASH_MAP) + set(HASH_NAMESPACE ::std PARENT_SCOPE) + set(HASH_MAP_H <ext/hash_map> PARENT_SCOPE) + set(HASH_MAP_CLASS hash_map PARENT_SCOPE) + set(HASH_SET_H <ext/hash_set> PARENT_SCOPE) + set(HASH_SET_CLASS hash_set PARENT_SCOPE) + return() + endif (HAS_STD_HASH_MAP) + + check_cxx_source_compiles(" + #include <ext/hash_map> + int main() { ::__gnu_cxx::hash_map<int, int> v; return v[0]; } + " HAS_GNU_CXX_HASH_MAP) + if (HAS_GNU_CXX_HASH_MAP) + set(HASH_NAMESPACE ::gnu_cxx PARENT_SCOPE) + set(HASH_MAP_H <ext/hash_map> PARENT_SCOPE) + set(HASH_MAP_CLASS hash_map PARENT_SCOPE) + set(HASH_SET_H <ext/hash_set> PARENT_SCOPE) + set(HASH_SET_CLASS hash_set PARENT_SCOPE) + return() + endif (HAS_GNU_CXX_HASH_MAP) + + set(HAVE_HASH_MAP 0 PARENT_SCOPE) + set(HAVE_HASH_SET 0 PARENT_SCOPE) +endfunction() + +function(find_hash_compare) + if (MSVC) + check_cxx_source_compiles(" + #include ${HASH_MAP_H} + int main() { ::std::hash_compare<int> cp; return cp(0); } + " HAS_STD_HASH_COMPARE) + if (HAS_STD_HASH_COMPARE) + set(HASH_COMPARE ::std::hash_compare PARENT_SCOPE) + return() + endif (HAS_STD_HASH_COMPARE) + + check_cxx_source_compiles(" + #include ${HASH_MAP_H} + int main() { ::stdext::hash_compare<int> cp; return cp(0); } + " HAS_STDEXT_HASH_COMPARE) + if (HAS_STDEXT_HASH_COMPARE) + set(HASH_COMPARE ::stdext::hash_compare PARENT_SCOPE) + return() + endif (HAS_STDEXT_HASH_COMPARE) + endif (MSVC) + set(HASH_COMPARE PARENT_SCOPE) +endfunction() + +find_hash_map() +find_hash_compare() diff --git a/cmake/libprotobuf-lite.cmake b/cmake/libprotobuf-lite.cmake new file mode 100644 index 00000000..32c2d026 --- /dev/null +++ b/cmake/libprotobuf-lite.cmake @@ -0,0 +1,23 @@ +set(libprotobuf_lite_files + ${protobuf_source_dir}/src/google/protobuf/arena.cc + ${protobuf_source_dir}/src/google/protobuf/arenastring.cc + ${protobuf_source_dir}/src/google/protobuf/extension_set.cc + ${protobuf_source_dir}/src/google/protobuf/generated_message_util.cc + ${protobuf_source_dir}/src/google/protobuf/io/coded_stream.cc + ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream.cc + ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl_lite.cc + ${protobuf_source_dir}/src/google/protobuf/message_lite.cc + ${protobuf_source_dir}/src/google/protobuf/repeated_field.cc + ${protobuf_source_dir}/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc + ${protobuf_source_dir}/src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc + ${protobuf_source_dir}/src/google/protobuf/stubs/common.cc + ${protobuf_source_dir}/src/google/protobuf/stubs/once.cc + ${protobuf_source_dir}/src/google/protobuf/stubs/stringprintf.cc + ${protobuf_source_dir}/src/google/protobuf/wire_format_lite.cc +) + +add_library(libprotobuf-lite ${libprotobuf_lite_files}) +target_link_libraries(libprotobuf-lite ${CMAKE_THREAD_LIBS_INIT}) +set_target_properties(libprotobuf-lite PROPERTIES + COMPILE_DEFINITIONS LIBPROTOBUF_EXPORTS + OUTPUT_NAME ${LIB_PREFIX}protobuf-lite) diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake new file mode 100644 index 00000000..b1f2dc3e --- /dev/null +++ b/cmake/libprotobuf.cmake @@ -0,0 +1,42 @@ +set(libprotobuf_files + ${protobuf_source_dir}/src/google/protobuf/any.cc + ${protobuf_source_dir}/src/google/protobuf/any.pb.cc + ${protobuf_source_dir}/src/google/protobuf/api.pb.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/importer.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/parser.cc + ${protobuf_source_dir}/src/google/protobuf/descriptor.cc + ${protobuf_source_dir}/src/google/protobuf/descriptor.pb.cc + ${protobuf_source_dir}/src/google/protobuf/descriptor_database.cc + ${protobuf_source_dir}/src/google/protobuf/duration.pb.cc + ${protobuf_source_dir}/src/google/protobuf/dynamic_message.cc + ${protobuf_source_dir}/src/google/protobuf/empty.pb.cc + ${protobuf_source_dir}/src/google/protobuf/extension_set_heavy.cc + ${protobuf_source_dir}/src/google/protobuf/field_mask.pb.cc + ${protobuf_source_dir}/src/google/protobuf/generated_message_reflection.cc + ${protobuf_source_dir}/src/google/protobuf/io/gzip_stream.cc + ${protobuf_source_dir}/src/google/protobuf/io/printer.cc + ${protobuf_source_dir}/src/google/protobuf/io/strtod.cc + ${protobuf_source_dir}/src/google/protobuf/io/tokenizer.cc + ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl.cc + ${protobuf_source_dir}/src/google/protobuf/map_field.cc + ${protobuf_source_dir}/src/google/protobuf/message.cc + ${protobuf_source_dir}/src/google/protobuf/reflection_ops.cc + ${protobuf_source_dir}/src/google/protobuf/service.cc + ${protobuf_source_dir}/src/google/protobuf/source_context.pb.cc + ${protobuf_source_dir}/src/google/protobuf/struct.pb.cc + ${protobuf_source_dir}/src/google/protobuf/stubs/structurally_valid.cc + ${protobuf_source_dir}/src/google/protobuf/stubs/strutil.cc + ${protobuf_source_dir}/src/google/protobuf/stubs/substitute.cc + ${protobuf_source_dir}/src/google/protobuf/text_format.cc + ${protobuf_source_dir}/src/google/protobuf/timestamp.pb.cc + ${protobuf_source_dir}/src/google/protobuf/type.pb.cc + ${protobuf_source_dir}/src/google/protobuf/unknown_field_set.cc + ${protobuf_source_dir}/src/google/protobuf/wire_format.cc + ${protobuf_source_dir}/src/google/protobuf/wrappers.pb.cc +) + +add_library(libprotobuf ${libprotobuf_lite_files} ${libprotobuf_files}) +target_link_libraries(libprotobuf ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES}) +set_target_properties(libprotobuf PROPERTIES + COMPILE_DEFINITIONS LIBPROTOBUF_EXPORTS + OUTPUT_NAME ${LIB_PREFIX}protobuf) diff --git a/cmake/libprotoc.cmake b/cmake/libprotoc.cmake new file mode 100644 index 00000000..8caa9e9e --- /dev/null +++ b/cmake/libprotoc.cmake @@ -0,0 +1,95 @@ +set(libprotoc_files + ${protobuf_source_dir}/src/google/protobuf/compiler/code_generator.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/command_line_interface.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_enum.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_enum_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_extension.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_file.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_generator.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_helpers.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_map_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_message.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_message_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_service.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_string_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_enum.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_enum_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_extension.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_field_base.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_generator.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_helpers.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_message.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_message_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_umbrella_class.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_writer.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_context.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_doc_comment.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_enum.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_enum_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_enum_field_lite.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_extension.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_file.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_generator.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_generator_factory.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_helpers.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_lazy_message_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_map_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_map_field_lite.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message_builder.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message_builder_lite.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message_field_lite.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message_lite.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_name_resolver.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_primitive_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_primitive_field_lite.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_service.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_shared_code_generator.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_string_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_string_field_lite.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_enum.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_enum_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_extension.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_file.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_generator.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_helpers.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_map_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_message.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_message_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_enum.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_extension.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_file.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_generator.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_message.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/plugin.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/plugin.pb.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/python/python_generator.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/ruby/ruby_generator.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/subprocess.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/zip_writer.cc +) + +add_library(libprotoc ${libprotoc_files}) +target_link_libraries(libprotoc libprotobuf) +set_target_properties(libprotoc PROPERTIES + COMPILE_DEFINITIONS LIBPROTOC_EXPORTS + OUTPUT_NAME ${LIB_PREFIX}protoc) diff --git a/cmake/pbconfig.h.in b/cmake/pbconfig.h.in new file mode 100644 index 00000000..fdc59686 --- /dev/null +++ b/cmake/pbconfig.h.in @@ -0,0 +1,9 @@ +#define GOOGLE_PROTOBUF_HAVE_HASH_MAP ${HAVE_HASH_MAP} +#define GOOGLE_PROTOBUF_HAVE_HASH_SET ${HAVE_HASH_MAP} + +#define GOOGLE_PROTOBUF_HASH_NAMESPACE ${HASH_NAMESPACE} +#define GOOGLE_PROTOBUF_HASH_MAP_H ${HASH_MAP_H} +#define GOOGLE_PROTOBUF_HASH_MAP_CLASS ${HASH_MAP_CLASS} +#define GOOGLE_PROTOBUF_HASH_SET_H ${HASH_SET_H} +#define GOOGLE_PROTOBUF_HASH_SET_CLASS ${HASH_SET_CLASS} +#define GOOGLE_PROTOBUF_HASH_COMPARE ${HASH_COMPARE} diff --git a/cmake/protoc.cmake b/cmake/protoc.cmake new file mode 100644 index 00000000..4f07c389 --- /dev/null +++ b/cmake/protoc.cmake @@ -0,0 +1,6 @@ +set(protoc_files + ${protobuf_source_dir}/src/google/protobuf/compiler/main.cc +) + +add_executable(protoc ${protoc_files}) +target_link_libraries(protoc libprotobuf libprotoc) diff --git a/cmake/tests.cmake b/cmake/tests.cmake new file mode 100644 index 00000000..24891521 --- /dev/null +++ b/cmake/tests.cmake @@ -0,0 +1,148 @@ +include_directories( + ${protobuf_source_dir}/gtest/include + ${protobuf_source_dir}/gtest) + +add_library(gtest STATIC ${protobuf_source_dir}/gtest/src/gtest-all.cc) +add_library(gtest_main STATIC ${protobuf_source_dir}/gtest/src/gtest_main.cc) +target_link_libraries(gtest_main gtest) + +set(lite_test_protos + google/protobuf/map_lite_unittest.proto + google/protobuf/unittest_import_lite.proto + google/protobuf/unittest_import_public_lite.proto + google/protobuf/unittest_lite.proto +) + +set(tests_protos + google/protobuf/any_test.proto + google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto + google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto + google/protobuf/map_proto2_unittest.proto + google/protobuf/map_unittest.proto + google/protobuf/unittest.proto + google/protobuf/unittest_arena.proto + google/protobuf/unittest_custom_options.proto + google/protobuf/unittest_drop_unknown_fields.proto + google/protobuf/unittest_embed_optimize_for.proto + google/protobuf/unittest_empty.proto + google/protobuf/unittest_import.proto + google/protobuf/unittest_import_public.proto + google/protobuf/unittest_lite_imports_nonlite.proto + google/protobuf/unittest_mset.proto + google/protobuf/unittest_no_arena.proto + google/protobuf/unittest_no_arena_import.proto + google/protobuf/unittest_no_field_presence.proto + google/protobuf/unittest_no_generic_services.proto + google/protobuf/unittest_optimize_for.proto + google/protobuf/unittest_preserve_unknown_enum.proto + google/protobuf/unittest_preserve_unknown_enum2.proto + google/protobuf/unittest_proto3_arena.proto + google/protobuf/unittest_well_known_types.proto +) + +macro(compile_proto_file filename) + get_filename_component(dirname ${filename} PATH) + get_filename_component(basename ${filename} NAME_WE) + add_custom_command( + OUTPUT ${protobuf_source_dir}/src/${dirname}/${basename}.pb.cc + COMMAND protoc ${protobuf_source_dir}/src/${dirname}/${basename}.proto + --proto_path=${protobuf_source_dir}/src + --cpp_out=${protobuf_source_dir}/src + DEPENDS protoc + ) +endmacro(compile_proto_file) + +set(lite_test_proto_files) +foreach(proto_file ${lite_test_protos}) + compile_proto_file(${proto_file}) + string(REPLACE .proto .pb.cc pb_file ${proto_file}) + set(lite_test_proto_files ${lite_test_proto_files} + ${protobuf_source_dir}/src/${pb_file}) +endforeach(proto_file) + +set(tests_proto_files) +foreach(proto_file ${tests_protos}) + compile_proto_file(${proto_file}) + string(REPLACE .proto .pb.cc pb_file ${proto_file}) + set(tests_proto_files ${tests_proto_files} + ${protobuf_source_dir}/src/${pb_file}) +endforeach(proto_file) + +set(common_test_files + ${protobuf_source_dir}/src/google/protobuf/arena_test_util.cc + ${protobuf_source_dir}/src/google/protobuf/map_test_util.cc + ${protobuf_source_dir}/src/google/protobuf/test_util.cc + ${protobuf_source_dir}/src/google/protobuf/testing/file.cc + ${protobuf_source_dir}/src/google/protobuf/testing/googletest.cc +) + +set(tests_files + ${protobuf_source_dir}/src/google/protobuf/any_test.cc + ${protobuf_source_dir}/src/google/protobuf/arena_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/arenastring_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/command_line_interface_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/importer_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_plugin_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/mock_code_generator.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/parser_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/python/python_plugin_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/descriptor_database_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/descriptor_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/drop_unknown_fields_test.cc + ${protobuf_source_dir}/src/google/protobuf/dynamic_message_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/extension_set_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/generated_message_reflection_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/io/coded_stream_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/io/printer_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/io/tokenizer_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/map_field_test.cc + ${protobuf_source_dir}/src/google/protobuf/map_test.cc + ${protobuf_source_dir}/src/google/protobuf/message_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/no_field_presence_test.cc + ${protobuf_source_dir}/src/google/protobuf/preserve_unknown_enum_test.cc + ${protobuf_source_dir}/src/google/protobuf/proto3_arena_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/reflection_ops_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/repeated_field_reflection_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/repeated_field_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/stubs/common_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/stubs/once_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/stubs/stringprintf_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/stubs/structurally_valid_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/stubs/strutil_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/stubs/template_util_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/stubs/type_traits_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/text_format_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/unknown_field_set_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/well_known_types_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/wire_format_unittest.cc +) + +add_executable(tests ${tests_files} ${common_test_files} ${tests_proto_files} ${lite_test_proto_files}) +target_link_libraries(tests libprotoc libprotobuf gtest_main) + +set(test_plugin_files + ${protobuf_source_dir}/src/google/protobuf/compiler/mock_code_generator.cc + ${protobuf_source_dir}/src/google/protobuf/testing/file.cc + ${protobuf_source_dir}/src/google/protobuf/testing/file.h + ${protobuf_source_dir}/src/google/protobuf/compiler/test_plugin.cc +) + +add_executable(test_plugin ${test_plugin_files}) +target_link_libraries(test_plugin libprotoc libprotobuf gtest) + +set(lite_test_files + ${protobuf_source_dir}/src/google/protobuf/arena_test_util.cc + ${protobuf_source_dir}/src/google/protobuf/lite_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/map_lite_test_util.cc + ${protobuf_source_dir}/src/google/protobuf/test_util_lite.cc +) +add_executable(lite-test ${lite_test_files} ${lite_test_proto_files}) +target_link_libraries(lite-test libprotobuf-lite) diff --git a/cmake/update_file_lists.sh b/cmake/update_file_lists.sh new file mode 100755 index 00000000..4466c021 --- /dev/null +++ b/cmake/update_file_lists.sh @@ -0,0 +1,121 @@ +#!/bin/sh + +# This script copies source file lists from src/Makefile.am to cmake files. + +get_variable_value() { + FILENAME=$1 + VARNAME=$2 + awk " + BEGIN { start = 0; } + /^$VARNAME =/ { start = 1; } + { if (start) { print \$0; } } + /\\\\\$/ { next; } + { start = 0; } + " $FILENAME \ + | sed "s/^$VARNAME =//" \ + | sed "s/[ \\]//g" \ + | grep -v "^\\$" \ + | grep -v "^$" \ + | LC_ALL=C sort | uniq +} + +get_source_files() { + get_variable_value $@ | grep "cc$" +} + +get_proto_files() { + get_variable_value $@ | grep "pb.cc$" | sed "s/pb.cc/proto/" +} + +set_variable_value() { + FILENAME=$1 + VARNAME=$2 + PREFIX=$3 + shift + shift + shift + awk -v values="$*" -v prefix="$PREFIX" " + BEGIN { start = 0; } + /^set\\($VARNAME/ { + start = 1; + print \$0; + len = split(values, vlist, \" \"); + for (i = 1; i <= len; ++i) { + printf(\" %s%s\\n\", prefix, vlist[i]); + } + next; + } + start && /^\\)/ { + start = 0; + } + !start { + print \$0; + } + " $FILENAME > /tmp/$$ + cp /tmp/$$ $FILENAME +} + +sort_files() { + for FILE in $@; do + echo $FILE + done | LC_ALL=C sort | uniq +} + +MAKEFILE=../src/Makefile.am +CMAKE_DIR=. +EXTRACT_INCLUDES_BAT=extract_includes.bat.in + +[ -f "$MAKEFILE" ] || { + echo "Cannot find: $MAKEFILE" + exit 1 +} + +[ -d "$CMAKE_DIR" ] || { + echo "Cannot find: $CMAKE_DIR" + exit 1 +} + +[ -f "$EXTRACT_INCLUDES_BAT" ] || { + echo "Cannot find: $EXTRACT_INCLUDES_BAT" + exit 1 +} + +# Extract file lists from src/Makefile.am +GZHEADERS=$(get_variable_value $MAKEFILE GZHEADERS) +HEADERS=$(get_variable_value $MAKEFILE nobase_include_HEADERS) +PUBLIC_HEADERS=$(sort_files $GZHEADERS $HEADERS) +LIBPROTOBUF_LITE_SOURCES=$(get_source_files $MAKEFILE libprotobuf_lite_la_SOURCES) +LIBPROTOBUF_SOURCES=$(get_source_files $MAKEFILE libprotobuf_la_SOURCES) +LIBPROTOC_SOURCES=$(get_source_files $MAKEFILE libprotoc_la_SOURCES) +LITE_PROTOS=$(get_proto_files $MAKEFILE protoc_lite_outputs) +PROTOS=$(get_proto_files $MAKEFILE protoc_outputs) +COMMON_TEST_SOURCES=$(get_source_files $MAKEFILE COMMON_TEST_SOURCES) +TEST_SOURCES=$(get_source_files $MAKEFILE protobuf_test_SOURCES) +LITE_TEST_SOURCES=$(get_source_files $MAKEFILE protobuf_lite_test_SOURCES) + +# Replace file lists in cmake files. +COMMON_PREFIX="\${protobuf_source_dir}/src/" +set_variable_value $CMAKE_DIR/libprotobuf-lite.cmake libprotobuf_lite_files $COMMON_PREFIX $LIBPROTOBUF_LITE_SOURCES +set_variable_value $CMAKE_DIR/libprotobuf.cmake libprotobuf_files $COMMON_PREFIX $LIBPROTOBUF_SOURCES +set_variable_value $CMAKE_DIR/libprotoc.cmake libprotoc_files $COMMON_PREFIX $LIBPROTOC_SOURCES +set_variable_value $CMAKE_DIR/tests.cmake lite_test_protos "" $LITE_PROTOS +set_variable_value $CMAKE_DIR/tests.cmake tests_protos "" $PROTOS +set_variable_value $CMAKE_DIR/tests.cmake common_test_files $COMMON_PREFIX $COMMON_TEST_SOURCES +set_variable_value $CMAKE_DIR/tests.cmake tests_files $COMMON_PREFIX $TEST_SOURCES +set_variable_value $CMAKE_DIR/tests.cmake lite_test_files $COMMON_PREFIX $LITE_TEST_SOURCES + +# Generate extract_includes.bat +echo "mkdir include" > $EXTRACT_INCLUDES_BAT +for HEADER in $PUBLIC_HEADERS; do + HEADER_DIR=$(dirname $HEADER) + while [ ! "$HEADER_DIR" = "." ]; do + echo $HEADER_DIR | sed "s/\\//\\\\/g" + HEADER_DIR=$(dirname $HEADER_DIR) + done +done | sort | uniq | sed "s/^/mkdir include\\\\/" >> $EXTRACT_INCLUDES_BAT +for HEADER in $PUBLIC_HEADERS; do + WINPATH=$(echo $HEADER | sed 's;/;\\;g') + echo "copy \${PROTOBUF_SOURCE_WIN32_PATH}\\..\\src\\$WINPATH include\\$WINPATH" >> $EXTRACT_INCLUDES_BAT +done +# Add pbconfig.h. +echo "copy \${PROTOBUF_BINARY_WIN32_PATH}\\google\\protobuf\\stubs\\pbconfig.h include\\google\\protobuf\\stubs\\pbconfig.h" >> $EXTRACT_INCLUDES_BAT |