Skip to content

Instantly share code, notes, and snippets.

@bseddon
Last active October 15, 2022 23:29
Show Gist options
  • Save bseddon/c4938ce07d2e11cdecb744db0d06fc99 to your computer and use it in GitHub Desktop.
Save bseddon/c4938ce07d2e11cdecb744db0d06fc99 to your computer and use it in GitHub Desktop.
Building ZeroMQ on Windows

The Zero MQ extension for PHP is not available as a Windows PECL package for PHP versions later than 7.2. So for later PHP versions it's necessary to build the extension. That also means building libzmq. The Zero MQ team have dropped the Visual Studio solutions files in favour using CMake. So how do users on Windows build Zero MQ? Here's how (and it's not hard).

Install Visual Studio. While installing, opt to install C++ and make sure the option to install the CMake tools for C++ is selected.

If VS is already installed because you use it for another project type, then use the Visual Studio Installer tool (available from the start menu) to modify the installation to add C++ and the CMake tools. Note tha in Visual Studio Installer the CMake tools will appears an option in the 'individual packages' (you'll know what I mean when you get there).

Download the ZeroMQ zip from GitHub and extract it. In whatever folder you chose to extract the zip file there will be a file called CMakeFiles.txt. Edit this file and make three changes:

  1. Around line 1305 there will be a line defining an option to BUILD_STATIC. Set this to OFF. If building shared AND static options are enabled it will cause a CMake error.
  2. Around line 1631 there will be a line defining an option to BUILD_TESTS. Set this to OFF. Of course you can build tests if you want. Disabling them will save you some time.
  3. Around line 259 there will be a line defining an option to WITH_LIBSODIUM. Set this to OFF unless you know libsodium is install in your environment.

Now start VS. From the File menu, select Open and the CMake... Using the file selection dialog to select the CMakeFiles.txt file you modified and open it. Now VS will start doing things. Nothing seems to happen straight away but its working. First a list of the Zero MQ project folder and files will appear in the solution explorer (don't do anything). The a CMake page will appear (don't do anything). Then messages will start appearing in the output window. After a minute or so, the output window messages will stop with last one confirming it's finished. There maybe some warnings in the error window. You can ignore these.

What CMake has done is create a VS project. It can be found in the 'out' sub-folder of the folder into which the Zero MQ project file were extracted.

Now select Build All from the Build menu. After a few minutes a message in the output window will confirm the build is complete. The '.\out\build\x64-Debug\bin' folder will contain .dll, .lib and .pdb files.

That's it. If you figure out how to modify CMakeFiles.txt to create a release build please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment