| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
Sorry, something went wrong.
Rewrites abseil and googletest to use targets and find_package Adds support for install target to opencensus
|
CLAs look good, thanks! |
Sorry, something went wrong.
|
With the current structure, abseil and googletest targets have to be built prior to building any opencensus libs/tests. I think the "best practice" way to get around this is something like the answer in https://stackoverflow.com/questions/44990964/how-to-perform-cmakefind-package-at-build-stage-only . If I implement this - and building works properly - would this be acceptable to you? |
Sorry, something went wrong.
|
The approach in cmake/Findabseil.cmake doesn't seem right to me: we shouldn't be enumerating build targets inside of abseil. @coryan, what do you think? Especially as a consumer of opencensus-cpp as a library. What's the right approach here? |
Sorry, something went wrong.
|
@meastp: Would you like to split out "Replace OPENCENSUS_INCLUDE_DIR with CMAKE_SOURCE_DIR" into its own PR? (and please convert to Unix line endings) If that doesn't break an out-of-tree example, I'd be happy to merge that. |
Sorry, something went wrong.
TL;DR; if you want to use ExternalProject_Add() then yes. Longer version, these are the most common, (there are many more) choices for dependency management in CMake
I believe, and this is just like My Opinion:tm:, that you should let folks configure how the dependencies are found. Your first-time users will prefer the simplicity of ExternalProject_Add(), the folks that create packages based on your library would prefer if you did not dynamically downloaded things. |
Sorry, something went wrong.
There was a problem hiding this comment.
Drive-by comments, take them with a grain of salt, feel free to ignore them too.
Sorry, something went wrong.
|
|
||
| option(BUILD_SHARED_LIBS "Build shared libraries" OFF) | ||
|
|
||
| IF(MSVC) |
There was a problem hiding this comment.
nit: be consistent IF or if everywhere (I think the trend is towards lowercase).
Sorry, something went wrong.
| option(BUILD_SHARED_LIBS "Build shared libraries" OFF) | ||
|
|
||
| IF(MSVC) | ||
| add_definitions(-DNOMINMAX) |
There was a problem hiding this comment.
I think you want target_compile_definitions() in the targets that need this definition, not need to push it on everybody.
Sorry, something went wrong.
| add_definitions(-DNOMINMAX) | ||
| ENDIF() | ||
|
|
||
| if(CMAKE_BUILD_TYPE STREQUAL "Release") |
There was a problem hiding this comment.
This is unusual... is that to avoid installing the headers twice?
Sorry, something went wrong.
There was a problem hiding this comment.
I think so. To be honest I took that example from somewhere else. What is the proper way to do it? :)
Sorry, something went wrong.
|
|
||
| list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) | ||
|
|
||
| find_package(googletest REQUIRED) |
There was a problem hiding this comment.
CMake has a native module to find gtest:
https://cmake.org/cmake/help/latest/module/FindGTest.html
why not use it here?
Sorry, something went wrong.
There was a problem hiding this comment.
Ah, because you want to download it.
Sorry, something went wrong.
There was a problem hiding this comment.
Well, this is the rationale for changing from "inline" ExternalProject_Add to doing it via find_package
Sorry, something went wrong.
| FILE opencensus-config.cmake | ||
| NAMESPACE opencensus:: | ||
| DESTINATION share/opencensus | ||
| ) No newline at end of file |
There was a problem hiding this comment.
nit: newline at end of file.
Sorry, something went wrong.
| @@ -0,0 +1,278 @@ | |||
| # Copyright 2018 The Cartographer Authors | |||
There was a problem hiding this comment.
Is this the right copyright?
Sorry, something went wrong.
I'm a beginner with cmake, so feel free to correct me, but: The reason I did this to support find_package for the external dependencies was to be able to support install/export opencensus targets. I think that from cmake's pow the targets from the external dependencies were part of the build, and thus those targets had to be exported as well - I didn't think this made sense, so I wrote a kind of FindModule.cmake that also builds with ExternalProject_Add to support the current workflow. However: Also, to be able to support vcpkg, using find_package is kind of required (because the dependencies already exist as packages in vcpkg). (However, it is possible to patch opencensus cmake definition before building with vcpkg). |
Sorry, something went wrong.
|
@meastp: Regarding the out-of-tree example, I've updated https://github.com/census-ecosystem/opencensus-cpp-example to have a CMake version of the build system. Feel free to use that for testing from the point of view of a user of the opencensus-cpp library. |
Sorry, something went wrong.
|
Regarding https://stackoverflow.com/questions/44990964/how-to-perform-cmakefind-package-at-build-stage-only - this seems a little odd, but IMO much less bad than enumerating all of our dependencies' targets. What do other folks think? @coryan? @fancl20? @isaachier? |
Sorry, something went wrong.
I agree with this. How about if we add a knob via set() so the user can choose between three alternatives:
|
Sorry, something went wrong.
CMake has historically been more interested in supporting existing patterns than setting a standard for third party dependencies. CMake 3.11 actually started supporting something similar to Bazel's http_archive, but it fetches at configuration time, which is better for CMake's configuration overall. See more about it here: https://cmake.org/cmake/help/latest/module/FetchContent.html#module:FetchContent. |
Sorry, something went wrong.
|
@isaachier Thanks for the pointers to FetchContent I did not know about it. It seems that it only works with add_subdirectory() which unfortunately brings all the targets in the dependency into the (single, global) target namespace, so you have to avoid conflicts "somehow". Did I get that right? If so, it strikes me as similar to using git submodules. |
Sorry, something went wrong.
|
@coryan I imagine git submodules works just as well for this sort of thing, just a bit annoying to maintain correctly, especially with transitive dependencies. Actually, reading the documentation I linked above, I see there is a great example describing multiple projects that depend on each other and how the top-level project "wins" in terms of determining the transitive dependencies. @g-easy, if you like the idea of FetchContent but not sure if you can use that new feature in CMake (only available in >= v3.11), you can actually just copy FetchContent.cmake and FetchContent.cmake.in into your project and it should work. |
Sorry, something went wrong.
|
Thanks for the pointer, @isaachier ! CMake 3.11 looks a bit too new today but that will change: https://packages.debian.org/search?keywords=cmake Good to know we can just import the implementation though.
I'm sorry but I don't understand how this helps. I think we still want the user to specify how opencensus-cpp should find its dependencies, e.g. find_package vs download its own. |
Sorry, something went wrong.
|
@meastp: In the interest of keeping things moving, would you like to split out the install (+ hdrs) part of this PR into its own PR, while we keep discussing find_package + dependencies here? |
Sorry, something went wrong.
|
@g-easy, I agree it is not necessarily a good solution for users to define their own versions. However, it allows them to override the version easily from the top-level CMakeLists.txt if you follow the FetchContent convention. |
Sorry, something went wrong.
|
Sure, I'll work on headers and msvc nominmax while this is discussed, and submit them in their own PRs :) |
Sorry, something went wrong.
|
@bogdandrutu Short term: waiting for headers and MSVC changes to be split out. Longer term I'd like to see #256 (comment) implemented. |
Sorry, something went wrong.
|
Hi, I am working on separate changes, and experimented with replacing the current ExternalProject with FetchContent and this works very well and reduces the amount of code substantially. Are you interested in a PR with this? Since you have Bazel, requiring CMake >= 3.11 might be okay? :) Then (because the amount of code is reduced) it will also be easier to implement an option to switch between FetchContent and find_package... |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This is a work-in-progress - do not merge yet.
See #244
Unfortunately, I have to add support for find_package for third-party dependencies and install in one go, because the targets from third party dependencies messed up the install/export for opencensus.
I have tested this in Visual Studio 2017 with the open folder native cmake support. I did also successfully run the opencensus tests.
Are these changes acceptable to you? Is this the proper way to support find_package in the dependencies?