-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 Update #292
CMake Update #292
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! (since I'm a Google Temp (red card)) |
CMakeLists.txt
Outdated
if (TARGET gflags::gflags) | ||
set(GFLAGS_TARGET gflags::gflags) | ||
elseif(TARGET gflags) | ||
set(GFLAGS_TARGET gflags) |
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.
Just curious, what is this logic doing? Why is the target sometimes gflags::gflags
and other times just gflags
, is this a side effect of version differences for the glags
package maybe? I'm not too familiar with it.
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.
I guess, this is a workaround for gflags not providing an alias target when used as a subproject.
@Mizux Wouldn't it make sense to let the gflags folks add this alias instead of making this work using ugly hacks?
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.
Hi,
- Curently gflags-[target|config].cmake provide
gflags
imported target (and gflags alias if using as subproject). - There is no official findgflags.cmake module AFAIK
- I'm currently sending a PR247 in gflags.git to use gflags::gflags instead (and providing alias as well when using as subproject)
- gRPC seems to already to look for gflags::gflags
- We have glog::glog protobuf::libprotobuf gRPC::grpc ...
- CMake preconise the use of namespace
When providing imported targets, these should be namespaced (hence the Foo:: prefix);
CMake will recognize that values passed to target_link_libraries() that contain :: in their name are supposed to be imported targets (rather than just library names), and will produce appropriate diagnostic messages if that target does not exist (see policy CMP0028).
src: https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html#a-sample-find-module (at ~bottom, search for namespaced)
So all in all we have gflags
currently but hope to have gflags::gflags
soon -> here it is a workaround to be able to work during the transition since find_package
don't provide a way to deal with this otherwise...
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.
I would prefer not adding the alias hack and wait until the gflags::gflags
alias is added. No need for temporary workarounds.
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.
LGTM remove the commit for this PR
@@ -8,23 +31,14 @@ if (POLICY CMP0063) | |||
cmake_policy (SET CMP0063 NEW) | |||
endif (POLICY CMP0063) | |||
|
|||
project (glog) |
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.
I am 👍 on this, and checked that our minimum CMake version supports this syntax in project
(I think it must have been older 2.x versions that didn't).
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.
I'm not. The policies must be set before the Nevermind. project
call, not after it. Please revert.project
is in the correct place.
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.
project(VERSION)
came in CMake 3.0 (i.e. not available in 2.8.12)
Also Trusty cmake package is 2.8.12 BUT ubuntu provides 3.5.1 as cmake3
package for trusty (and travis has trusty with 3.8 or 3.9 BTW).
So it should be reasonable to think everyone have at least CMake 3.0 with VERSION support...
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.
And we're using cmake_minimum_required (VERSION 3.0)
, so it'll be a very explicit error if 2.x is used. It is not worth attempting to support CMake 2, it's possibly worse than than the Python 2 and 3 split IMHO.
set_target_properties (glog PROPERTIES VERSION ${GLOG_MAJOR_VERSION}) | ||
set_target_properties (glog PROPERTIES SOVERSION ${GLOG_VERSION}) | ||
set_target_properties (glog PROPERTIES VERSION ${PROJECT_VERSION}) | ||
set_target_properties (glog PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR}) |
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.
I'm not sure this is correct. Does this mean there will be only a libglog.so.0
but not a libglog.so.0.3.5
?
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.
No there will be 3 files: (-> means symbolic link aka ln -s ...)
libglog.so -> libglog.so.0 (since SO_VERSION which is the API compatibility is only major)
libglog.so.0 -> libglog.so.0.3.5 (so the "API" point on your build version)
libglog.so.0.3.5 (which is the "real" library)
And it seems that target_link_library will point on the soname aka lbglog.so.0
(so you should be able to install different major version on linux system etc..)
As I said in the commit message, there is also an inversion between VERSION and SOVERSION usage
(easy to spot with make install DESTDIR=install && ls -l install/use/local/lib)
doc: https://cmake.org/cmake/help/latest/prop_tgt/VERSION.html#prop_tgt:VERSION
Hope it's clear know 😅
side note: if you wrap your code in a python "setup.py" bdist will resolve the symlink so you just have to depend on $<TARGET_SONAME_FILE:glog>
cf https://github.com/google/or-tools/blob/mizux/dev/cmake/python.cmake#L110
@@ -8,23 +31,14 @@ if (POLICY CMP0063) | |||
cmake_policy (SET CMP0063 NEW) | |||
endif (POLICY CMP0063) | |||
|
|||
project (glog) |
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.
I'm not. The policies must be set before the Nevermind. project
call, not after it. Please revert.project
is in the correct place.
I just remove the gflags::gflags / gflags management. |
@googlebot rescan |
CLAs look good, thanks! |
CMakeLists.txt
Outdated
## add_subdirectory(glog) | ||
## | ||
## add_executable(foo src/foo.cc) | ||
## target_link_libraries(foo glog::glog) |
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.
I don't believe this is a good place to document such specific stuff. I would suggest moving this part either into the wiki or cmake/INSTALL.md
.
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'll move it...
ps: I just put it here as gflags CMakelists.txt did
Useful when using glog as subproject. Add an explanation at top like in gflags.git CMakeLists.txt
CTest module already provides it
- Use of Project version properties instead of custom variables - fix missmatch between VERSION (build version) and SOVERSION (API version) src: https://cmake.org/cmake/help/latest/prop_tgt/VERSION.html#prop_tgt:VERSION
Ok I moved the doc to INSTALL.md and incorparate this patch with the glog::glog alias commit. Don't hesitate to comment / modify / whatever... |
LGTM. |
Few patch to:
cf https://cmake.org/cmake/help/v3.0/command/project.html