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
CMake: pkg-config Fallback #133
Conversation
I'm unsure if pkg-config is a good solution. But you could use the variables instead of the targets. But you need to call find_path to detect the include path. I would recommand a FindZeroMQ.cmake and append its path to the CMAKE_MODULE_PATH. This could be installed by this project and could be used from the CMakeLists.txt and the cppzmqConfig.cmake.in. Otherwise you have to add the pkg-config fallback to both files. You could also use the add_library function together with the IMPORTED signature. Therefore you have to copy and adapt more or less the code from the generated target files of libzmq. |
Thanks a lot for the feedback! I guess the first option is unlikely to happen since it was already dismissed in #110 & #127.
thanks, likely a add_library(libzmq SHARED IMPORTED)
set_property(TARGET libzmq PROPERTY IMPORTED_LOCATION ZeroMQ_LIBRARY)
add_library(libzmq-static STATIC IMPORTED)
set_property(TARGET libzmq-static PROPERTY IMPORTED_LOCATION ZeroMQ_STATIC_LIBRARY) will already solve it. |
fcfc53b
to
ec91af0
Compare
ec91af0
to
3015f67
Compare
@bluca it works! :) export PKG_CONFIG_PATH=$LIBZMQ_PREFIX/lib/pkgconfig
cmake ..
make install and off it goes :) |
Great stuff, thanks! |
Are you sure that it is correct to use the variables without You don't touch the package configuration cppzmqConfig.cmake.in. Have you test to compile an external package which use find_package(cppzmq)? Additionally you need to add the header path to the targets. |
Thanks again for the review!
True, following this example page it should use
I didn't think that's not necessary when looking into it, but checking the installed
I just tested I now tested also a dependent project with a # project
cmake_minimum_required(VERSION 3.0.0)
project(ZeroMQexample)
# dependencies
find_package(cppzmq REQUIRED)
# executable
add_executable(main main.cpp)
target_link_libraries(main cppzmq) which still fails while looking for a
Sure, can you show me how please? :) |
3015f67
to
3e1c649
Compare
Try to find installs of `libzmq` that were performed with autotools with a `pkg-config` fallback.
3e1c649
to
217985a
Compare
Instead of the duplicated code I would recommend to move the code into its own cmake file and install and include this file in both files. Even better would be a FindZeroMQ.cmake module. This would reduce the changes inside the I just released that there is already a FindZeroMQ.cmake inside an other ZeroMQ project which works without pkg-config: |
Isn't the point of a lot of recent cmake changes in libzmq to remove the need for dependencies to ship a findzeromq file? |
@bluca The FindZeroMQ file is only needed for the autotools build system. |
Rather than shipping additional files which look like are needed by cmake but are actually for autotools, isn't it better to just use pkg-config which autotools already ships? |
move the new logic to a simple file so we do not add code duplication
Sure, I just removed the code duplication. |
One could also make this a module, but in such case rather a I think the solution for now is a good bridge between the autotools and the CMake world, so dependent projects can build safely with CMake. For the long run, it's not a good idea to support two build systems in |
The FindZeroMQ.cmake is needed by cmake and not by autotools. The problem is that libzmq support different build systems and the autotools build don't install any cmake support. Hence all follow-up project needs do deal with the different build systems. Best would be to remove the autotools support from libzmq or let autotools install a FindZeroMQ.cmake. Because of its limitations it isn't recommended to use pkg-config inside a cmake project. |
@ax3l You are right. You need to call |
Sorry, autotools is not going anywhere. Also work was recently done to remove the findzeromq file, so that's not coming back either. pkgconfig is universal and well supported, so I would suggest sticking with that as the fallback, when the cmake files are not found. |
I think we can live with that, now that we have a marvelous bridge in place 🦄 |
@bluca @herbrechtsmeier are you ok with the current state of the PR for a merge? :) |
CMake targets / interfaces need at least CMake 3.0
@bluca What is the reason to support two build systems with different outputs? Why the autotools build don't provide also a native CMake support? With this patch you use different code to detected libzmq inside czmq and cppzmq. The first project use a find package and the second project bypass the find package function but do similar things. This could be avoid with a common cmake support inside libzmq. What do you mean by pkg-config is universal and well supported? There is a reason why cmake avoid the usage of pkg-config inside its modules. |
@herbrechtsmeier I do understand your pain but discussing this here goes off-topic for this PR. Is it ok for you to just open a proposal in the issues of https://github.com/zeromq/libzmq ? :) |
|
Isn't visual studio supported by CMake? How many distributions don't offer a CMake package? CMake even supports bare metal cross compilation. Additionally the packages are relocatable and support dependency tracking. And nobody needs to use CMake for its project even if this project use CMake. But even if you support different build systems you should support a common build system interface for follow up projects. You should really add CMake support to autotools. Otherwise you should remove the CMake package generation and only support pkg-config. But even this leads to a cmake file if it is called Autotools could provide generated CMake files without CMake because it only needs to replace some variables inside a ZeroMQConfig.cmake text file like it does for pkg-config. This project requires a three year old CMake version. Attentionally the pkg-config file could also be generated by CMake. With your changes you bring the FindZeroMQ.cmake file back. You only rename the file and use an include instead of the find_package(ZeroMQ) function. Additionally you distribute the file over different projects. I could open a new issue in libzmq but this makes only sense if there is interests in an autotools support for CMake. |
@bluca just to stay on topic of the PR: can you ping me pls when a |
Try to find installs of
libzmq
that were performed with autotools with apkg-config
fallback. Close #132@herbrechtsmeier we are trying to add a
pkg-config
fallback forcppzmq
'sCMakeLists.txt
to findlibzmq
installs that were done with autotools and thus have no ZeroMQ cmake module around.Do you have an idea how we can re-introduce the targets you are using for the libs when found via
pkg-config
?