-
Notifications
You must be signed in to change notification settings - Fork 219
Add CMake configuration file and export installed targets #204
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
Conversation
cb3eec5 to
cf1fbad
Compare
|
Hi @azat, can you please try this branch and see that it fixes all your issues? Thanks! |
|
Looks like all needable bits are there, so I'm fine with it (I cannot test it right now, since I do not have neither of |
You can simply build rdkafka with cmake. This will ensure that both files are generated and installed correctly. See included |
|
I'll have a look at this over the weekend but regarding requiring to use an rdkafka version built using CMake, I don't think we should go that way. The rdkafka CMake build system is not maintained by the autor but by the community instead (e.g. read their README which states "NOTE: See CMake instructions for experimental CMake build (unsupported)"). We should have our own find script so we can ensure we find it no matter which build system it was built with. |
|
@mfontanini Agreed, however the cmake way is pretty much the future. The only thing which I haven't thought about is if you install the DPKG from some distro, they don't seem to include the CMAKE target files. So I think that the best way would be to keep your FindRdKafka.cmake script and use a CMAKE flag to either discover using RdKafkaConfig.cmake or your file |
I can, but I cannot force others to do so, take a look at debian for instance
How?
+1, otherwise this will existing setups |
|
BTW, the |
|
Ok the cmake behavior was changed to the following:
|
|
There is one cmake warning (in 3.14.5) Apart from that everything is works, thanks! |
|
Policy warning fixed. |
|
|
||
| if (RdKafka_ROOT) | ||
| if (NOT IS_ABSOLUTE ${RdKafka_ROOT}) | ||
| set(RdKafka_ROOT "${CMAKE_SOURCE_DIR}/${RdKafka_ROOT}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed? I think I've used -Dsomething=../../x and it works IIRC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It didn't for me. Seems that find_package() expects a proper relative path from the point where it's being evaluated. In this case it was evaluated from cppkafka/cmake which made Travis fail. The second thing is that when using the CppkafkaConfig.cmake, which in turn calls FindRdKafka.cmake , you have no control of where it will be accessed from. This is meant to be used by 3rd party libs linking CppKafka. So FindRdKafka.cmake should have a proper path to the RdKafka root.
cmake/FindRdKafka.cmake
Outdated
| set(RdKafka_DEPENDENCIES ${RdKafka_LIBNAME} pthread) | ||
| endif() | ||
| include_directories(SYSTEM ${RdKafka_INCLUDE_DIR}) | ||
| link_directories(${RdKafka_LIBRARY_DIR}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The include and library path shouldn't be polluted by including this script. Since this is exporting a target for rdkafka, you should be using target-specific options (e.g. target_include_directories)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm but this script is used by CppKafka and also by any 3rd party library linking to CppKafka and using the CppKafkaConfig.cmake. So which target are we adding the include directories for? You can't say target_include_directories(RdKafka...) since we're not building this target, we are just importing it. Maybe I can do add_library(RdKafka IMPORTED) and then set the properties on the imported target. This is not something I have tried....will try and let you know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've packaged a bunch of libraries at work using conan + CMake and we normally have the Find*.cmake script create an imported target and add all dependencies in there. This works great and lets you have all dependencies defined per target rather than having to remember to link with your dependencies' dependencies. We do something like
add_library(foo INTERFACE IMPORTED)
set_target_properties(foo PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${FOO_INCLUDE_DIRS}
INTERFACE_LINK_LIBRARIES "${FOO_LIBRARY};dep1;dep2;..."
)Then you just import the library and link to it, ignoring dependencies (e.g. via find_package and target_link_libraries).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is what I just did. See my commit.
cmake/config.cmake.in
Outdated
| find_dependency(RdKafka QUIET CONFIG) | ||
| set(RDKAFKA_TARGET_IMPORTS ${RdKafka_FOUND}) | ||
| if (NOT RdKafka_FOUND) | ||
| message(STATUS "RdKafkaConfig.cmake not found. Please set RDKAFKA_ROOT or RDKAFKA_DIR if a config file is installed. Attempting to find module instead...") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following up on the comment in the top level CMakeLists.txt file, this shouldn't be here either unless there's an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK...see my previous comment. Since the find_package searches config and module, it's good for debugging to know what's going on. Maybe I can put this under CMAKE_VERBOSE_MAKEFILE or something like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want it for debugging purposes, this probably shouldn't be in this file but in the main CMake file instead (under some flag). A user importing cppkafka on their project (via this script) shouldn't care at all about how rdkafka is being found: they just care about the cppkafka target either being there or not after running the script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I can leave it outside the CppKafkaConfig.cmake and only include it in the top CMakeLists of the CppKafka project itself. In that case you do want to know why you can't find RdKafka.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW the REQUIRE makes sure that an error message will be printed if the module is not found.
…Boost path since it's automatically pulled in via Boost::headers
…GETS, the COMPONENT cannot appear after INCLUDES DESTINATION as it will be considered part of the destination.
…t to allow discoverability of the RdKafka.so w/o having to update LD_LIBRARY_PATH
…est code. Changed find_dependency to find_package for the RdKafka config so that the script is not automatically exited on failure
|
@mfontanini this feature is pretty much complete now. Lmk if there's anything else you want me to look at. I can squash the commits into a single one as there are too many. |
|
Hi @mfontanini, can you please take a look when you get a chance? Thanks! |
|
Thanks for all this great work @accelerated ! Any other concern? I see you just pushed something. I tried it locally and everything seems to work fine. |
|
@mfontanini at this point it should be all good. If there are any issues they will be fixed pretty soon since we're making heavy use of all these cmake features for internal builds, etc. My only question was if you want to squash all this into a single commit. There's a lot of noise from all the back and forth. |
|
Nah, don't worry about it. At least this way we know things changed progressively towards the state it's in now. Merging this now, let me know if there's any other problems. Sorry it took me a while, there's just so many issue emails coming in on this and another library I maintain that I just feel a bit overwhelmed some days and don't even get to open them. |
Description
CMake improvements which aim at modernizing and simplifying the use of CppKafka and the discover-ability of installed files when linked by other projects. This also prevents from having to manually add dependent libraries and include directories.
GNUInstallDirsfunctionality proposed by @azat! Thanks for the improvement! The PR#200 is no longer needed.find_package(RdKafka). This loads in all the exported targets, dependencies, include directories which are needed by this project. By doing this we no longer need a specificFindRdKafka.cmakemodule as well as manually specifying include directories and lib paths to RdKafka library. This is handled seamlessly by the exported targets. The only thing that needs to be done is addingRdKafka::rdkafkaas a dependency to thecppkafkatarget.If RdKafka is installed in a non-standard directory,
RDKAFKA_ROOTorCMAKE_INSTALL_PREFIXcan be defined to point to it.find_package(RdKafka "0.9.4" REQUIRED). This prevents depending on a non-compatible version of RdKafka.find_package(CppKafka "0.3.1")for instance and link against it by usingCppKafka::cppkafkaas a dependency. Furthermore because of the transitive nature of exported targets, when includingCppKafka::cppkafkaall its dependencies are automatically included as well:RdKafka::rdkafka(and it's dependencies such aslibssl, libuv, libz, etc...) andBoost::boost (optional.hpp header).CppKafka_ROOT, CppKafka_INSTALL_INCLUDE_DIR and CppKafka_INSTALL_LIB_DIR.cppkafka/cmakedirectory so that everything is in the same directory. The auto-generated files from these templates are stored under the temporarycppkafka/packagedirectory prior to installation.testsandexamplestargets to use theRdKafka::rdkafkadependency instead.CPPKAFKA_CONFIG_DIRCmake option can allow installing the CppKafka config files elsewhere.include/CMakeLists.txtsince it was only a redirect to the directory below it. Instead we calladd_subdirectory(include/cppkafka)directly.RDKAFKA_ROOT_DIRhas been superseded byRDKAFKA_ROOT. The previous option is still used for backwards compatibility.