Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: Failed to build czmq on Windows via CMake #2012

Merged
merged 2 commits into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
########################################################################
# Project setup
########################################################################
cmake_minimum_required(VERSION 2.8.8)
cmake_minimum_required(VERSION 2.8.12)
project(czmq)
enable_language(C)
enable_testing()
Expand Down Expand Up @@ -138,7 +138,8 @@ ENDIF (LIBZMQ_FOUND)
# UUID dependency
########################################################################
find_package(uuid)
IF (UUID_FOUND)
option(CZMQ_WITH_UUID "Build czmq with uuid" ${UUID_FOUND})
IF (CZMQ_WITH_UUID AND UUID_FOUND)
include_directories(${UUID_INCLUDE_DIRS})
list(APPEND MORE_LIBRARIES ${UUID_LIBRARIES})
IF (PC_UUID_FOUND)
Expand All @@ -149,13 +150,14 @@ IF (UUID_FOUND)
ENDIF (PC_UUID_FOUND)
add_definitions(-DHAVE_UUID)
list(APPEND OPTIONAL_LIBRARIES ${UUID_LIBRARIES})
ENDIF (UUID_FOUND)
ENDIF (CZMQ_WITH_UUID AND UUID_FOUND)

########################################################################
# SYSTEMD dependency
########################################################################
find_package(systemd)
IF (SYSTEMD_FOUND)
option(CZMQ_WITH_SYSTEMD "Build czmq with systemd" ${SYSTEMD_FOUND})
IF (CZMQ_WITH_SYSTEMD AND SYSTEMD_FOUND)
include_directories(${SYSTEMD_INCLUDE_DIRS})
list(APPEND MORE_LIBRARIES ${SYSTEMD_LIBRARIES})
IF (PC_SYSTEMD_FOUND)
Expand All @@ -166,13 +168,14 @@ IF (SYSTEMD_FOUND)
ENDIF (PC_SYSTEMD_FOUND)
add_definitions(-DHAVE_LIBSYSTEMD)
list(APPEND OPTIONAL_LIBRARIES ${SYSTEMD_LIBRARIES})
ENDIF (SYSTEMD_FOUND)
ENDIF (CZMQ_WITH_SYSTEMD AND SYSTEMD_FOUND)

########################################################################
# LZ4 dependency
########################################################################
find_package(lz4)
IF (LZ4_FOUND)
option(CZMQ_WITH_LZ4 "Build czmq with lz4" ${LZ4_FOUND})
IF (CZMQ_WITH_LZ4 AND LZ4_FOUND)
include_directories(${LZ4_INCLUDE_DIRS})
list(APPEND MORE_LIBRARIES ${LZ4_LIBRARIES})
IF (PC_LZ4_FOUND)
Expand All @@ -183,13 +186,14 @@ IF (LZ4_FOUND)
ENDIF (PC_LZ4_FOUND)
add_definitions(-DHAVE_LIBLZ4)
list(APPEND OPTIONAL_LIBRARIES ${LZ4_LIBRARIES})
ENDIF (LZ4_FOUND)
ENDIF (CZMQ_WITH_LZ4 AND LZ4_FOUND)

########################################################################
# LIBCURL dependency
########################################################################
find_package(libcurl)
IF (LIBCURL_FOUND)
option(CZMQ_WITH_LIBCURL "Build czmq with libcurl" ${LIBCURL_FOUND})
IF (CZMQ_WITH_LIBCURL AND LIBCURL_FOUND)
include_directories(${LIBCURL_INCLUDE_DIRS})
list(APPEND MORE_LIBRARIES ${LIBCURL_LIBRARIES})
IF (PC_LIBCURL_FOUND)
Expand All @@ -200,13 +204,14 @@ IF (LIBCURL_FOUND)
ENDIF (PC_LIBCURL_FOUND)
add_definitions(-DHAVE_LIBCURL)
list(APPEND OPTIONAL_LIBRARIES ${LIBCURL_LIBRARIES})
ENDIF (LIBCURL_FOUND)
ENDIF (CZMQ_WITH_LIBCURL AND LIBCURL_FOUND)

########################################################################
# LIBMICROHTTPD dependency
########################################################################
find_package(libmicrohttpd)
IF (LIBMICROHTTPD_FOUND)
option(CZMQ_WITH_LIBMICROHTTPD "Build czmq with libmicrohttpd" ${LIBMICROHTTPD_FOUND})
IF (CZMQ_WITH_LIBMICROHTTPD AND LIBMICROHTTPD_FOUND)
include_directories(${LIBMICROHTTPD_INCLUDE_DIRS})
list(APPEND MORE_LIBRARIES ${LIBMICROHTTPD_LIBRARIES})
IF (PC_LIBMICROHTTPD_FOUND)
Expand All @@ -217,7 +222,7 @@ IF (LIBMICROHTTPD_FOUND)
ENDIF (PC_LIBMICROHTTPD_FOUND)
add_definitions(-DHAVE_LIBMICROHTTPD)
list(APPEND OPTIONAL_LIBRARIES ${LIBMICROHTTPD_LIBRARIES})
ENDIF (LIBMICROHTTPD_FOUND)
ENDIF (CZMQ_WITH_LIBMICROHTTPD AND LIBMICROHTTPD_FOUND)

########################################################################
# version
Expand Down
2 changes: 1 addition & 1 deletion Findlibcurl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ find_path (

find_library (
LIBCURL_LIBRARIES
NAMES curl
NAMES libcurl curl
HINTS ${PC_LIBCURL_LIBRARY_HINTS}
)

Expand Down
2 changes: 1 addition & 1 deletion Findlibmicrohttpd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ find_path (

find_library (
LIBMICROHTTPD_LIBRARIES
NAMES microhttpd
NAMES libmicrohttpd microhttpd
HINTS ${PC_LIBMICROHTTPD_LIBRARY_HINTS}
)

Expand Down
21 changes: 5 additions & 16 deletions Findlibzmq.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ if (MSVC)

set(_zmq_version ${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH})

set(_zmq_debug_names)
set(_zmq_release_names)

set(_zmq_debug_names
"libzmq${MSVC_TOOLSET}-mt-gd-${_zmq_version}" # Debug, BUILD_SHARED
"libzmq${MSVC_TOOLSET}-mt-sgd-${_zmq_version}" # Debug, BUILD_STATIC
Expand All @@ -61,30 +58,22 @@ if (MSVC)
"libzmq-mt-s-${_zmq_version}" # Release|RelWithDebInfo|MinSizeRel, BUILD_STATIC
)

find_library (ZeroMQ_LIBRARY_DEBUG
find_library (LIBZMQ_LIBRARY_DEBUG
NAMES ${_zmq_debug_names}
)

find_library (ZeroMQ_LIBRARY_RELEASE
find_library (LIBZMQ_LIBRARY_RELEASE
NAMES ${_zmq_release_names}
)

if (ZeroMQ_LIBRARY_RELEASE AND ZeroMQ_LIBRARY_DEBUG)
set(LIBZMQ_LIBRARIES
debug ${ZeroMQ_LIBRARY_DEBUG}
optimized ${ZeroMQ_LIBRARY_RELEASE}
)
elseif (ZeroMQ_LIBRARY_RELEASE)
set(LIBZMQ_LIBRARIES ${ZeroMQ_LIBRARY_RELEASE})
elseif (ZeroMQ_LIBRARY_DEBUG)
set(LIBZMQ_LIBRARIES ${ZeroMQ_LIBRARY_DEBUG})
endif ()
include(SelectLibraryConfigurations)
select_library_configurations(LIBZMQ)
endif ()

if (NOT LIBZMQ_LIBRARIES)
find_library (
LIBZMQ_LIBRARIES
NAMES zmq libzmq
NAMES libzmq zmq
HINTS ${PC_LIBZMQ_LIBRARY_HINTS}
)
endif ()
Expand Down
2 changes: 1 addition & 1 deletion Findlz4.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ find_path (

find_library (
LZ4_LIBRARIES
NAMES lz4
NAMES liblz4 lz4
HINTS ${PC_LZ4_LIBRARY_HINTS}
)

Expand Down
2 changes: 1 addition & 1 deletion Findsystemd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ find_path (

find_library (
SYSTEMD_LIBRARIES
NAMES systemd
NAMES libsystemd systemd
HINTS ${PC_SYSTEMD_LIBRARY_HINTS}
)

Expand Down
74 changes: 71 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,80 @@ You will need the pkg-config, libtool, and autoreconf packages. After building,
To start with, you need MS Visual Studio (C/C++). The free community edition works well.

Then, install git, and make sure it works from a DevStudio command prompt:

```
git
```

Now let's build CZMQ from GitHub:
#### Using vcpkg

If you are already using [vcpkg](https://github.com/Microsoft/vcpkg/), you can download and install `czmq` with one single command:
```
.\vcpkg.exe install czmq
```
this will build `czmq` as a 32-bit shared library.
```
.\vcpkg.exe install czmq:x64-windows-static
```
this will build `czmq` as a 64-bit static library.

You may also build `czmq` with one or more optional libraries:
```
.\vcpkg.exe install czmq[curl,httpd,lz4]:x64-windows
```
this will build `czmq` with `libcurl`, `libmicrohttpd`, `lz4`, as a 64-bit shared library.

To use the draft APIs, you may build `czmq` with `draft` feature:
```
.\vcpkg install czmq[draft]
```

If you are an adventurer, and want to always use the lastest version of `czmq`, pass an extra `--head` option:
```
.\vcpkg.exe install czmq --head
```

These commands will also print out instructions on how to use the library from your MSBuild or CMake-based projects.

#### Using CMake

`czmq` requires `libzmq`, so we need to build `libzmq` first. For `libzmq`, you can optionally use [libsodium](https://github.com/jedisct1/libsodium) as the curve encryption library. So we will start from building `libsodium` in the following (and you can bypass the building of `libsodium` if you are ok with libzmq's default curve encryption library):
```
git clone --depth 1 -b stable https://github.com/jedisct1/libsodium.git
cd libsodium\builds\msvc\build
buildall.bat
cd ..\..\..\..
```
Once done, you can find the library files under `libsodium\bin\<Win32|x64>\<Debug|Release>\<Platform Toolset>\<dynamic|ltcg|static>`.

Here, the `<Platform Toolset>` is the platform toolset you are using: `v100` for `VS2010`, `v140` for `VS2015`, `v141` for `VS2017`, etc.

```
git clone git://github.com/zeromq/libzmq.git
cd libzmq
mkdir build
cd build
cmake .. -DBUILD_STATIC=OFF -DBUILD_SHARED=ON -DZMQ_BUILD_TESTS=ON -DWITH_LIBSODIUM=ON -DCMAKE_INCLUDE_PATH=..\libsodium\src\libsodium\include -DCMAKE_LIBRARY_PATH=..\libsodium\bin\Win32\Release\<Platform Toolset>\dynamic -DCMAKE_INSTALL_PREFIX=C:\libzmq
cmake --build . --config Release --target install
cd ..\..\
```
`-DWITH_LIBSODIUM=ON` is necessary if you want to build `libzmq` with `libsodium`. `CMAKE_INCLUDE_PATH` option tells `libzmq` where to search for `libsodium`'s header files. And the `CMAKE_LIBRARY_PATH` option tells where to search for libsodium library files. If you don't need `libsodium` support, you can omit these three options.

`-DCMAKE_INSTALL_PREFIX=C:\libzmq` means we want to install `libzmq` into the `C:\libzmq`. You may need to run your shell with administrator privilege in order to write to the system disk.

Now, it is time to build `czmq`:
```
git clone git://github.com/zeromq/czmq.git
cd czmq
mkdir build
cd build
cmake .. -DCZMQ_BUILD_SHARED=ON -DCZMQ_BUILD_STATIC=OFF -DCMAKE_PREFIX_PATH=C:\libzmq
cmake --build . --config Release
```
Remember that we install `libzmq` to `C:\libzmq` through specifying `-DCMAKE_INSTALL_PREFIX=C:\libzmq` in the previous step. We here use `-DCMAKE_PREFIX_PATH=C:\libzmq` to tell `czmq` where to search for `libzmq`.

That is not the whole story. We didn't mention the building of `libcurl`, `lz4`, `libuuid` and other `czmq` optional libraries above. In fact, to build all of these optional libraries successfully is really tricky. Please refer issue [#1972](https://github.com/zeromq/czmq/issues/1972) for more details.

#### Using MSBuild (Out of date, may not work now!)

```
git clone --depth 1 -b stable https://github.com/jedisct1/libsodium.git
Expand All @@ -203,7 +271,7 @@ Now let's build CZMQ from GitHub:

:: if libsodium is on disk, the Windows build of libzmq will automatically use it
git clone git://github.com/zeromq/libzmq.git
cd libzmq\builds\msvc
cd libzmq\builds\deprecated-msvc
configure.bat
cd build
buildall.bat
Expand Down