-
Notifications
You must be signed in to change notification settings - Fork 526
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
Failed to build czmq on Windows via CMake #1972
Comments
We can (and should) fix (2) upstream in vcpkg by encoding |
You don't need to add |
@ras0219-msft Just like this? if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
file(READ ${CURRENT_PACKAGES_DIR}/include/zmq.h _contents)
string(REPLACE "defined ZMQ_STATIC" "1 //defined ZMQ_STATIC" _contents "${_contents}")
file(WRITE ${CURRENT_PACKAGES_DIR}/include/zmq.h "${_contents}")
endif() I am considering to add these line to @remyabel Thanks for telling me that. :-) |
Note that libsodium is not a dependency of CZMQ, so there's no need for an option for it |
This issue has been automatically marked as stale because it has not had recent activity for 90 days. It will be closed if no further activity occurs within 21 days. Thank you for your contributions. |
Do not close yet. I'd like to tackle this issue. |
A quick fix of this problem: First, build and install
Then, clone
The CI configuration file has this line: https://github.com/zeromq/czmq/blob/master/appveyor.yml#L53 |
|
I think we may have three ways to fix the
I personally think solution 3 is the best, since it uses modern cmake. Update: |
To close out on my question for #2004 which was redirected here I have attached the manual steps that I got working on my VS 2013 system. Thanks for pointing me to he appveyor.yml file for hints:
|
Findlibzmq.cmake should be regenerated to fix CMake build error on Win32 (zeromq#1972).
Finally, I am able to build ZeroMQ, for example, can use #----------------------------------------------------------------
# Generated CMake target import file for configuration "Debug".
#----------------------------------------------------------------
# Commands may need to know the format version.
set(CMAKE_IMPORT_FILE_VERSION 1)
# Import target "libzmq" for configuration "Debug"
set_property(TARGET libzmq APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(libzmq PROPERTIES
IMPORTED_IMPLIB_DEBUG "${_IMPORT_PREFIX}/debug/lib/libzmq-mt-gd-4_3_2.lib"
IMPORTED_LINK_INTERFACE_LIBRARIES_DEBUG "${_IMPORT_PREFIX}/debug/lib/libsodium.lib;ws2_32;rpcrt4;iphlpapi"
IMPORTED_LOCATION_DEBUG "${_IMPORT_PREFIX}/debug/bin/libzmq-mt-gd-4_3_2.dll"
)
list(APPEND _IMPORT_CHECK_TARGETS libzmq )
list(APPEND _IMPORT_CHECK_FILES_FOR_libzmq "${_IMPORT_PREFIX}/debug/lib/libzmq-mt-gd-4_3_2.lib" "${_IMPORT_PREFIX}/debug/bin/libzmq-mt-gd-4_3_2.dll" )
# Commands beyond this point should not need to know the version.
set(CMAKE_IMPORT_FILE_VERSION) If the users use the exported CMake module in a CMake-based project like this: find_package(ZeroMQ CONFIG REQUIRED)
target_link_libraries(main PRIVATE libzmq) then they don't worry about the If the users use find_package(ZeroMQ CONFIG REQUIRED)
set(LIBZMQ_INCLUDE_DIRS ${ZeroMQ_INCLUDE_DIR})
set(LIBZMQ_LIBRARIES libzmq libzmq-static)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
LIBZMQ
REQUIRED_VARS LIBZMQ_LIBRARIES LIBZMQ_INCLUDE_DIRS
) and apply this patch to the cmake/Config.cmake.in: diff --git a/builds/cmake/Config.cmake.in b/builds/cmake/Config.cmake.in
index 9c15f36a..e1475cd6 100644
--- a/builds/cmake/Config.cmake.in
+++ b/builds/cmake/Config.cmake.in
@@ -1,4 +1,14 @@
@PACKAGE_INIT@
+include(CMakeFindDependencyMacro)
+
+find_dependency(ZeroMQ)
+
+if (@CZMQ_WITH_LIBCURL@ AND @LIBCURL_FOUND@)
+ find_dependency(OpenSSL)
+ find_dependency(ZLIB)
+endif ()
+
+
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
check_required_components("@PROJECT_NAME@") I noticed the existence of #1939, and totally understand @bluca's concern. So a better solution should take both of the two cases into consideration: find_package(ZeroMQ CONFIG QUIET)
if (ZeroMQ_FOUND)
set(ZMQ_CMAKE_MODULE_AVAILABLE 1)
else ()
set(ZMQ_CMAKE_MODULE_AVAILABLE 0)
# Fall back to find_library
......
endif () and in the
czmq's another optional dependency, libcurl, also faces this problem. libcurl itself may depends on OpenSSL, zlib, and others. So: find_library (
LIBCURL_LIBRARIES
NAMES curl
HINTS ${PC_LIBCURL_LIBRARY_HINTS}
) is not enough when libcurl is built as a static library. Besides, on Windows, the lib name of libcurl is not always libcurl.lib, so I have to take care of them this way: find_library(
LIBCURL_LIBRARY_DEBUG
NAMES libcurl-d_imp libcurl-d curl-d curl
)
find_library(
LIBCURL_LIBRARY_RELEASE
NAMES libcurl_imp libcurl curl
) google-cloud-cpp handles libcurl dependency this way: https://github.com/googleapis/google-cloud-cpp/pull/2407/files So you see, a generic Find*.cmake template sounds great, but it doesn't work all the time. If we can mantain those Find*.cmake standalone, then we may refine them freely. Otherwise, we have to use a bounch of If we do not want to go that far currently:
|
OK. Before I close this issue, I want to do two more things:
|
This patch also: 1. Simplify Findlibzmq.cmake 2. Use both libname and linkname when they are not identical Related issue: zeromq/czmq#1972
Hey, guys! I am back again.
I am trying to add
czmq
tovcpkg
these days(microsoft/vcpkg#4979). When buildingczmq
with CMake, I encountered several problems.CMAKE_CURRENT_SOURCE_DIR
isn't inCMAKE_MODULE_PATH
.https://github.com/zeromq/czmq/blob/master/CMakeLists.txt#L19soFindlibzmq.cmake
,Findlibsodium.cmake
, .etc. may not be called.When built as a static library, libzmq will set an additional compiler flag-DZMQ_STATIC
throughset_target_properties
:https://github.com/zeromq/libzmq/blob/master/CMakeLists.txt#L1060so if we want to buildczmq
as a static library on Windows, we should defineZMQ_STATIC
manually(Maybe we can define it inFindlibzmq.cmake
). Otherwise, the build will fail: undefined reference in mingw when link static library. libzmq#3318Findlibzmq.cmake
is not be able to findlibzmq
on Windows.libzmq dll/lib built with MSVC is named using the Boost convention(something like
libzmq-mt-4_3_1.lib
,libzmq-mt-4_3_1.dll
). Sofind_library (LIBZMQ_LIBRARIES NAMES zmq HINTS ${PC_LIBZMQ_LIBRARY_HINTS})
will not work.Here is a patch for solving this problem: https://bitbucket.org/ignitionrobotics/ign-transport/pull-requests/19/detec-zmq-under-windows-using-a-findzmq/diff
Findlibsodium.cmake
will not foundlibsodium
on WindowsWhen built with MSVC,
libsodium
will generate a library namedlibsodium.dll/lib
. In this case,find_library(LIBSODIUM_LIBRARY NAMES sodium)
is not able to find the library. I found thatfind_library(LIBSODIUM_LIBRARY NAMES sodium libsodium)
works.By the way,
Findlibcurl.cmake
has this problem too.Maybe we can add some options like:
WITH_LIBSODIUM
WITH_LIBCURL
WITH_LZ4
WITH_UUID
BUILD_TESTS
(For example: Create a configuration flag to disable tests. googleapis/google-cloud-cpp#1617)BUILD_TOOLS
(zmakecret)The text was updated successfully, but these errors were encountered: