• Home
  • Raw
  • Download

Lines Matching +full:cmake +full:- +full:build +full:- +full:and +full:- +full:test +full:- +full:check

1 This directory contains *CMake* files that can be used to build protobuf
2 with *MSVC* on *Windows*. You can build the project from *Command Prompt*
3 and using an *Visual Studio* IDE.
5 You need to have [CMake](http://www.cmake.org), [Visual Studio](https://www.visualstudio.com)
6 and optionally [Git](http://git-scm.com) installed on your computer before proceeding.
31 If *cmake* command is not available from *Command Prompt*, add it to system *PATH* variable:
33 C:\Path\to>set PATH=%PATH%;C:\Program Files (x86)\CMake\bin
39 Optionally, you will want to download [ninja](https://ninja-build.org/) and add it to your *PATH* v…
52 For example: if you only need C++, download `protobuf-cpp-[VERSION].tar.gz`; if
53 you need C++ and Java, download `protobuf-java-[VERSION].tar.gz` (every package
54 contains C++ source already); if you need C++ and multiple other languages,
55 download `protobuf-all-[VERSION].tar.gz`.
60 C:\Path\to\src> git clone -b [release_tag] https://github.com/protocolbuffers/protobuf.git
62 Where *[release_tag]* is a git tag like *v3.0.0-beta-1* or a branch name like *main*
74 C:\Path\to\src\protobuf> git submodule update --init --recursive
77 Good. Now you are ready for *CMake* configuration.
79 CMake Configuration
82 *CMake* supports a lot of different
83 [generators](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html)
84 for various native build systems.
88 * [Makefile](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#makefile-generat…
91 * [Visual Studio](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#visual-stud…
94 * [Ninja](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#ninja-generator)
95 …This uses the external tool [Ninja](https://ninja-build.org/) to build. It is the fastest solution…
98 [support for opening directly CMake-based projects](https://docs.microsoft.com/en-us/cpp/build/cmak…
100 It is considered good practice not to build CMake projects in the source tree but in a separate fol…
102 Create a temporary *build* folder and change your working directory to it:
104 mkdir C:\Path\to\build\protobuf
105 cd C:\Path\to\build\protobuf
106 C:\Path\to\build\protobuf>
108 The *Makefile* and *Ninja* generators can build the project in only one configuration, so you need …
113 C:\Path\to\build\protobuf>mkdir release & cd release
114 C:\Path\to\build\protobuf\release>cmake -G "NMake Makefiles" ^
115 -DCMAKE_BUILD_TYPE=Release ^
116 -DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
123 C:\Path\to\build\protobuf>mkdir debug & cd debug
124 C:\Path\to\build\protobuf\debug>cmake -G "Ninja" ^
125 -DCMAKE_BUILD_TYPE=Debug ^
126 -DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
129 It will generate *Ninja* build scripts in current directory.
131 …sual Studio* generator is multi-configuration: it will generate a single *.sln* file that can be u…
133 C:\Path\to\build\protobuf>mkdir solution & cd solution
134 C:\Path\to\build\protobuf\solution>cmake -G "Visual Studio 16 2019" ^
135 -DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
141 ----------
143 …lt along with the rest of protobuf. The unit tests require Google Mock (now a part of Google Test).
145 A copy of [Google Test](https://github.com/google/googletest) is included as a Git submodule in the…
148 …ernately, you may want to use protobuf in a larger set-up, you may want to use that standard CMake
149 you build and install a shared copy of Google Test.
151 After you've built and installed your Google Test copy, you need add the following definition to yo…
152 during the configuration step: `-Dprotobuf_USE_EXTERNAL_GTEST=ON`.
153 This will cause the standard CMake `find_package(GTest REQUIRED)` to be used.
155 [find_package](https://cmake.org/cmake/help/latest/command/find_package.html) will search in a defa…
157 Google Test in your project's root directory (i.e. the same directory you've passed to `CMAKE_INSTA…
158 building Google Test). For this, you need to set the `CMAKE_PREFIX_PATH` CMake variable. (There are…
159 see the [manual](https://cmake.org/cmake/help/latest/command/find_package.html) for details.)
163 C:\Path\to\build\protobuf>mkdir solution & cd solution
164 C:\Path\to\build\protobuf\solution>cmake -G "Visual Studio 16 2019" ^
165 -DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
166 -DCMAKE_PREFIX_PATH=C:\Path\to\my_big_project ^
167 -Dprotobuf_USE_EXTERNAL_GTEST=ON ^
170 In most cases, `CMAKE_PREFIX_PATH` and `CMAKE_INSTALL_PREFIX` will point to the same directory.
172 …sting completely, you need to add the following argument to you *cmake* command line: `-Dprotobuf_…
176 C:\Path\to\build\protobuf\solution>cmake -G "Visual Studio 16 2019" ^
177 -DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
178 -Dprotobuf_BUILD_TESTS=OFF ^
184 The standard way to compile a *CMake* project is `cmake --build <directory>`.
187 …r generator supports multiple configurations, you will probably want to specify which one to build:
189 cmake --build C:\Path\to\build\protobuf\solution --config Release
191 You can also run directly the build tool you've configured:
193 C:\Path\to\build\protobuf\release>nmake
197 C:\Path\to\build\protobuf\debug>ninja
199 And wait for the compilation to finish.
205 * From the Build menu, choose "Build Solution".
207 And wait for the compilation to finish.
212 To run unit-tests, first you must compile protobuf as described above.
215 C:\Path\to\protobuf\cmake\build\release>ctest --progress --output-on-failure
217 You can also build the `check` target (not idiomatic CMake usage, though):
219 C:\Path\to\protobuf\cmake\build\release>cmake --build . --target check
223 C:\Path\to\build\protobuf\release>ninja check
225 You can also build project *check* from Visual Studio solution.
231 [==========] Running 1546 tests from 165 test cases.
235 [==========] 1546 tests from 165 test cases ran. (2529 ms total)
238 To run specific tests, you need to pass some command line arguments to the test program itself:
240 C:\Path\to\build\protobuf\release>tests.exe --gtest_filter=AnyTest*
242 Note: Google Test filter = AnyTest*
243 [==========] Running 3 tests from 1 test case.
244 [----------] Global test environment set-up.
245 [----------] 3 tests from AnyTest
252 [----------] 3 tests from AnyTest (1 ms total)
254 [----------] Global test environment tear-down
255 [==========] 3 tests from 1 test case ran. (2 ms total)
265 … *install* folder you've specified in the configuration step, you need to build the `install` targ…
267 cmake --build C:\Path\to\build\protobuf\solution --config Release --target install
271 C:\Path\to\build\protobuf\release>nmake install
275 C:\Path\to\build\protobuf\debug>ninja install
277 You can also build project *INSTALL* from Visual Studio solution.
278 It sounds not so strange and it works.
281 * bin - that contains protobuf *protoc.exe* compiler;
282 * include - that contains C++ headers and protobuf *.proto files;
283 * lib - that contains linking libraries and *CMake* configuration files for *protobuf* package.
287 * Copy protoc.exe wherever you put build tools (probably somewhere in your PATH).
288 …* Copy linking libraries libprotobuf[d].lib, libprotobuf-lite[d].lib, and libprotoc[d].lib whereve…
290 To avoid conflicts between the MSVC debug and release runtime libraries, when
291 compiling a debug build of your application, you may need to link against a
292 debug build of libprotobufd.lib with "d" postfix. Similarly, release builds should link against
302 build libprotobuf and libprotoc as DLLs if you really want. To do this,
305 * Add an additional flag `-Dprotobuf_BUILD_SHARED_LIBS=ON` when invoking cmake
314 libraries will *not* be usable as drop-in replacements.
316 If your project is itself a DLL intended for use by third-party software, we
318 public interface, and that you statically link protocol buffers into your
324 If you want to include GzipInputStream and GzipOutputStream
328 Obtain a copy of the zlib library. The pre-compiled DLL at zlib.net works.
339 C:\Path\to\src>git clone -b v1.2.8 https://github.com/madler/zlib.git
342 Compiling and Installing:
344 C:\Path\to\src\zlib>mkdir C:\Path\to\build\zlib & cd C:\Path\to\build\zlib
345 C:\Path\to\build\zlib>mkdir release & cd release
346 C:\Path\to\build\zlib\release>cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release ^
347 -DCMAKE_INSTALL_PREFIX=C:\Path\to\install C:\Path\to\src\zlib
348 C:\Path\to\src\zlib\build\release>cmake --build . --target install
357 You need reconfigure protobuf with flag `-Dprotobuf_WITH_ZLIB=ON` when invoking cmake.
360 further disable the option `-Dprotobuf_MSVC_STATIC_RUNTIME=OFF`.
365 If you already have ZLIB library and headers at some other location on your system then alternative…
367 -DZLIB_INCLUDE_DIR=<path to dir containing zlib headers>
368 -DZLIB_LIB=<path to dir containing zlib>
370 Build and testing protobuf as usual.
376 and compiler. You may have to disable some of them in your own project as
379 * C4244 - Conversion from 'type1' to 'type2', possible loss of data.
380 * C4251 - 'identifier' : class 'type' needs to have dll-interface to be used by
382 * C4267 - Conversion from 'size_t' to 'type', possible loss of data.
383 * C4305 - 'identifier' : truncation from 'type1' to 'type2'
384 * C4355 - 'this' : used in base member initializer list
385 * C4800 - 'type' : forcing value to bool 'true' or 'false' (performance warning)
386 * C4996 - 'function': was declared deprecated