6

In the past I’ve used the Visual Studio solution files to build zeromq (libzmq) on Windows. I just noticed that the Visual Studio solutions have been deprecated because they are too difficult to maintain.

The alternative is to use CMake; trouble is I’ve no experience of how to invoke the build this way. Is anyone please able to demonstrate the necessary commands, step-by-step?

I’d like to achieve 32 & 64bit libzmq binaries using libsodium and compiled with VS2015 on Windows 10. (I’ve installed CMake 64bit and allowed it to add to the system path at installation.)

Thanks

GoFaster
  • 835
  • 1
  • 12
  • 23
  • Have you consult [INSTALL](https://github.com/zeromq/libzmq/blob/master/INSTALL) file of the project? Its "Windows Builds" section describes building the project for VS2015 on Windows 10. – Tsyvarev Aug 28 '18 at 11:27
  • I did see that but it is not clear enough to get me started. Never used CMake before, do I use the GUI or on the command line? How do I specify to build 32/64bit, use libsodium etc. – GoFaster Aug 28 '18 at 11:39
  • 1
    The command `cmake -H ...` is for command line. But you may build the project from CMake GUI, its general usage is described in many places (in short: 1. Select source and build directories. 2. Select proper generator. 3. Press "Configure". 4. Possibly adjust options and press "Configure" again). Selecting between 32 and 64bit libraries is achieved by using proper generator, "Visual Studio 14 2015" or "Visual Studio 14 2015 Win64". – Tsyvarev Aug 28 '18 at 11:49
  • 1
    As for using libsodium, It should be described somewhere in the project's documentation. In [CMakeLists.txt](https://github.com/zeromq/libzmq/blob/master/CMakeLists.txt#L66) I have found line `option (WITH_LIBSODIUM "Use libsodium instead of built-in tweetnacl" OFF)` which is probably what do you want: in CMake GUI you need to check "WITH_LIBSODIUM" option. – Tsyvarev Aug 28 '18 at 11:52

2 Answers2

8

So eventually I managed to build zeromq on Windows 10 from source using CMake.

CMake is used to set the various zeromq project options; in this case to use the libsodium library for cryptography and to provide the necessary include & linker paths for the build. Once the options are configured CMake is used to generate a Visual Studio solution from which to build the libzmq binaries.

Briefly this is how I did it using the CMake GUI:

  1. Specify to where the libzmq source code was cloned and tell CMake where to build the binaries. Hint; make a separate folder for each Visual Studio version & 32/64bit as necessary, see screenshot below.

  2. Click Configure to load the project options. From the pop up window choose the compiler you wish to use from the list. Set the necessary project options and click Configure again.

  3. If all is well click Generate to create the Visual Studio files.

  4. Click Open Project; once loaded in Visual Studio choose Debug/Release as you need and click Build Solution.

  5. Repeat the process for other architectures eg. choose the 32bit compiler as you require. Remember to adjust build output location & libsodium linker path to reflect that architecture.

Screenshot: Cmake screenshot

GoFaster
  • 835
  • 1
  • 12
  • 23
  • I upvoted this answer because it reflects what I also did to build the library. However, I had to disable libsodium and TLS because I was not able to install those packages in such a way they were found by cmake. More in depth explanations on this point would be appreciated. – Alkhwarizmi Jul 15 '21 at 12:57
2
  1. VS2015 Toolbar -> Open -> CMake -> ZMQ folder

  2. Toolbar -> CMake -> Cache -> Generate -> ZeroMQ

  3. Toolbar -> CMake -> Install -> ZeroMQ

You can find builds in /Users/UserName/CMakeBuilds/...

Alko
  • 21
  • 2
  • Tried this, but Visual Studio 2017's CMake parsing doesn't appear to be up to the task. Switched to standalone CMake installer and generated a vs2017 sln, per the answer below, and it worked. – Phillip Jun 27 '19 at 04:14
  • Me too. I tried using Visual Studio 2019. When you create new project via git clone within Visual Studio, it immediately opens up Visual Studio's CMake program. `CMake Error: failed with: ninja: error: build.ninja:1253: multiple rules generate precompiled.hpp [-w dupbuild=err]` and `CMake Generate step failed. Build files cannot be regenerated correctly.` But it is nice to know CMake is built in there.. thx. – zipzit Apr 07 '21 at 09:00
  • In case it helps anyone - the following is in the CMakeLists.txt for zmq "The problem is, both libzmq-static libzmq try to use/generate # precompiled.pch at the same time Add a dependency, so they run in order and so they dont get in each others way TODO # still generates warning "build\x64-Debug\ninja : warning : multiple rules generate precompiled.hpp. builds involving # this target will not be correct; continuing anyway [-w dupbuild=warn]" And i was able to get around it by hacking around in the file a bit to remove references to BUILD_STATIC so that there wasn't a conflict – Crackerjack55 Jun 25 '21 at 14:02