zeromq / azmq

C++ language binding library integrating ZeroMQ with Boost Asio
Boost Software License 1.0
319 stars 109 forks source link

Included FindZeroMQ.cmake only works if ZeroMQ built with Visual Studio IDE #198

Open rhvonlehe opened 2 years ago

rhvonlehe commented 2 years ago

In FindZeroMQ.cmake, the below section assumes there will be a variable ${CMAKE_VS_PLATFORM_TOOLSET} defined. If not, the find_library calls fail. I built ZeroMQ with a Visual Studio compiler, but not with the IDE. This leaves ${CMAKE_VS_PLATFORM_TOOLSET} empty. My ZeroMQ library is installed with the filename: libzmq-mt-gd-4_3_5.lib. The finder can't identify this.

My non-azmq project is able to find ZeroMQ just fine, however, by relying on the ZeroMQConfig.cmake that is provided by ZeroMQ and installed alongside the library artifacts.

All it would take to fix this is to add a 3rd line in each of the NAMES section for Windows without the ${CMAKE_VS_PLATFORM_TOOLSET}- to the FindZeroMQ.cmake provided in azmq.

    if (NOT ${CMAKE_CXX_PLATFORM_ID} STREQUAL "Windows")
        find_library(ZeroMQ_LIBRARIES NAMES zmq HINTS ${_ZeroMQ_ROOT}/lib)
    else()
        message("CMAKE_VS_PLATFORM_TOOLSET: ${CMAKE_VS_PLATFORM_TOOLSET}")
        find_library(
            ZeroMQ_LIBRARY_RELEASE
            NAMES
                libzmq
                "libzmq-${CMAKE_VS_PLATFORM_TOOLSET}-mt-${ZeroMQ_VERSION_MAJOR}_${ZeroMQ_VERSION_MINOR}_${ZeroMQ_VERSION_PATCH}"
            HINTS
                ${_ZeroMQ_ROOT}/lib
            )

        find_library(
            ZeroMQ_LIBRARY_DEBUG
            NAMES
                libzmq_d
                "libzmq-${CMAKE_VS_PLATFORM_TOOLSET}-mt-gd-${ZeroMQ_VERSION_MAJOR}_${ZeroMQ_VERSION_MINOR}_${ZeroMQ_VERSION_PATCH}"
            HINTS
                ${_ZeroMQ_ROOT}/lib)

        # On Windows we have to use corresponding version (i.e. Release or Debug) of ZeroMQ because of `errno` CRT global variable
        # See more at http://www.drdobbs.com/avoiding-the-visual-c-runtime-library/184416623
        set(ZeroMQ_LIBRARIES optimized "${ZeroMQ_LIBRARY_RELEASE}" debug "${ZeroMQ_LIBRARY_DEBUG}")
    endif()
aboseley commented 1 year ago

@rhvonlehe , please let us know if the updated cmake changes now work better for you