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
Add CMake support #8
Conversation
c437574
to
8272265
Compare
👍 My CLion requires CMake. |
If you are targeting CMake 3.0, you should consider exporting imported targets from your Find modules instead of passing string variables in & out of those. |
The one constraint I know of on this: it needs to support back as far as CMake 2.8 (because I know that other Google projects like protobuf and gRPC require that, and I have to support those). |
@tituswinters Thx Titus, I was not sure about that, that's why I kept compatibility with 2.8's style. |
dd90089
to
2121590
Compare
Just being pedantic, but CMake 2.8 doesn't mean much, unless you mean 2.8.0. CMake didn't use semver before, so you should explicitly say which version of 2.8.x you intend to support. |
78c3bfc
to
b3d0631
Compare
@Orphis Fixed Most of the staff should be there now. The remaining bits are types/utility/memory/meta |
Out of curiosity, where did you get the 2.8.5? I checked protobuf and it's using 2.8.12 for example, and it's way more advanced than 2.8.5. |
@Orphis 2.8.5, if my memory is correct, was the first initial verison shipped under RHEL5 and Debian Wheezy. Meaning it should build even under prehistoric monsters and still be compatible with protobuf / gRPC. There is very little difference between 2.8.5 / 2.8.11 anyway. |
Well, 2.8.12 added It doesn't change the fact you could define IMPORTED targets in your find modules instead, those have been around for a while, though I'm not sure if all the support functionality is there for them. |
@Orphis Thx I ignored that. protobuf is 2.8.12, let's use 2.8.12 then. I have also granted you rw access to my fork like you seem motivated to contribute. |
02d7a3d
to
3dfec79
Compare
Would this mean I don't have to use Bazel? |
@agauniyal - Yes. Abseil team will still primarily support bazel, but we'll do our best to keep both working once something like this lands. |
@tituswinters just to be clear I've nothing against bazel, its just that cmake is more popular right now in c++ ecosystem and maybe if bazel starts getting used I'll be happy to be on primary build system :) |
@agauniyal - And to be clear - we've got nothing against cmake, it's just not what we're experienced with or primarily focused on. |
CMake/AbseilHelpers.cmake
Outdated
) | ||
|
||
|
||
add_library(${_NAME} SHARED ${__dummy_header_only_lib_file}) |
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.
Why is this SHARED
? STATIC
would be more appropriate here.
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.
Sorry for that, stupid late mistake.
I was thinking to provide a switch to compile everything static or everything shared for that since we are aiming to support embedded deployment by defaylt, enforcing STATIC does not really make a sense anymore
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 doesn't make sense to build dummy libraries as SHARED though.
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.
Fixed
CMakeLists.txt
Outdated
## please use these targets in your project | ||
# | ||
# | ||
add_library(absl::algorithm ALIAS absl_algorithm) |
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.
This would be better done in the macros defining the targets.
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 did that on purpose to make explicit to the user what are the public target to use. I would prefer maintain it like that excepted if you have strong objections.
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.
At some point, someone will add a new target and forget to add the line in there. It's better if it's done by the macro automatically.
This type of information needs to go in documentation actually.
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 understand your point.
However, I am convince that 70% of your user will not even take the time to check the documentation like always :)
I fixed that. The alias is automatically generated in the macro if tagged explicitely, to allow private / public namespace and a comment is added in the main CMake file for the user.
I will also add this information in the doc
list(APPEND ALGORITHM_TEST_SRC | ||
"algorithm_test.cc" | ||
${ALGORITHM_PUBLIC_HEADERS} | ||
${ALGORITHM_INTERNAL_HEADERS} |
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 test only has one file. Don't put the other headers in there.
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 is there for a reason. The header need to be associated explicitely with the sources of a target if you want them to be visible into an IDE that supports CMake. I do not like it, but it is the recommended way.
I can however associate it to the header only target, since we have them now.
TARGET | ||
algorithm_test | ||
SOURCES | ||
${ALGORITHM_TEST_SRC} |
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 test should link against its own library, even if it's header only.
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.
Fine for me
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.
Fixed. Other tests will adopt the same pattern.
CMake/AbseilHelpers.cmake
Outdated
set(_NAME ${ABSL_HO_LIB_TARGET}) | ||
|
||
set(__dummy_header_only_lib_file "${CMAKE_CURRENT_BINARY_DIR}/${_NAME}_header_only_dummy.cc") | ||
file(WRITE ${__dummy_header_only_lib_file} |
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 write all the time at generation step, you will cause rebuilds everytime. You should check the file doesn't exist before overwriting 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.
Fixed
) | ||
|
||
|
||
# test test_instance_tracker_test |
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 heard you like tests bro
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.
ahah.
On the way to the infinite test inception ✌️
I am not crazy enough to write all of that CMake code manually, I wrote an generator for the tests :)
My generator prefixed "test" before a test name "test" inside bazel and then "suffixed" test for the target naming reason. Who said we need more testing ? :)
CMake/README.md
Outdated
add_subdirectory(abseil-cpp) | ||
|
||
add_executable(my_exe source.cpp) | ||
target_link_libraries(my_exe base synchronization strings) |
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.
You'll need to fix the documentation too with the new scoped names
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.
Fixed
absl/debugging/CMakeLists.txt
Outdated
${STACKTRACE_PUBLIC_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.
Missing the absl_library for leak_check?
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.
Fixed
absl/strings/CMakeLists.txt
Outdated
|
||
|
||
list(APPEND STRINGS_PUBLIC_HEADERS | ||
"ascii_ctype.h" |
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.
This file wasn't meant to be released, and was leaked on accident. Please get rid of it here.
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 have removed it
# | ||
|
||
# test time_test | ||
list(APPEND TIME_TEST_SRC |
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.
Consistency in use $FOO_SRC and similar will be nice for us in the future when we generate cmake files from build files for consistency. Although if they're generated then re-spelling files isn't that bad either I suppose. It doesn't matter as long as it's consistent, build files are ideally for machines, not humans
absl/types/CMakeLists.txt
Outdated
${BAD_OPTIONAL_ACCESS_PUBLIC_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.
Please add any, optional, and span as their own libraries as well, as in the Bazel files
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.
Added for the missing header only ones, and all exported
absl/types/CMakeLists.txt
Outdated
|
||
|
||
|
||
absl_header_library( |
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.
Strings, time, etc have their own monolithic targets due to dependencies and bundling of similar types. The libraries here are all disparate, so let's not have a monolithic target here, again to match the Bazel file.
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.
Fixed
- initial cmake support - downgrade cmake requirement to 2.8.12 - factorize cmake test flags / libs options - refactor test / library under helpers functions, follow bazel's style - Add fix for MSVC and Windows support ( thx @patrikfors ) - Switch to default "add_subdirectory()" usage mode - add CMake/README.md for instructions - add header-only cmake target generator - map absl target to absl:: namespace
CMake/AbseilHelpers.cmake
Outdated
set(_ABSL_HELPERS_PATH "${CMAKE_CURRENT_LIST_DIR}") | ||
|
||
# | ||
# create a static library absl_based on the following variable |
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.
typo here? maybe "Create a static library absl_foo"
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.
Fixed
Friendly ping here :) I'm working on trying to put my changes in to your PR but it's a litle slow going as I'm not as familiar with CMake |
@JonathanDCohen Sorry for the slow progress, I had rather busy days recently. All the modifications coming from your comments should be implemented now. I also updated the README documentation appropriately. One last thing I see for a real convenient usage would be to finalize the cctz CMake support (google/cctz#54) . Without it, it would imply that the user create its own cctz target himself. |
CMake/README.md
Outdated
the targets `gtest`, `gtest_main`, `gmock` and `cctz` need | ||
to be declared in your project before including abseil with `add_subdirectory`. | ||
You can find instructions on how to get and build these projects at these | ||
URL : |
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.
URLs missing
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.
Fixed.
- Update documentation - Remove type target - Remove typos - simplify target - improve 1-1 matchign with Bazel targets
abseil directly and use the abseil targets in your project. | ||
|
||
Note: Abseil requires CCTZ and the googletest framework. Consequently, | ||
the targets `gtest`, `gtest_main`, `gmock` and `cctz` need |
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.
In its current proposal, cctz would be better referred as cctz::cctz
.
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.
Since the cctz PR will likely undergo some change, I consider this non-blocking
#add_subdirectory(googletest) | ||
|
||
## check targets | ||
check_target(cctz) |
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.
In its current proposal, cctz would be better referred as cctz::cctz
.
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.
Since the cctz PR will likely undergo some change, I consider this non-blocking
${TIME_PUBLIC_HEADERS} | ||
${TIME_INTERNAL_HEADERS} | ||
) | ||
set(TIME_PUBLIC_LIBRARIES absl::base absl::stacktrace absl::int128 cctz) |
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.
In its current proposal, cctz would be better referred as cctz::cctz
.
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.
Since the cctz PR will likely undergo some change, I consider this non-blocking
PUBLIC_LIBRARIES | ||
${TIME_PUBLIC_LIBRARIES} | ||
PUBLIC_INCLUDE_DIRS | ||
${CCTZ_INCLUDE_DIRS} |
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.
In the current proposal of the cctz
CMake support, this should not be needed.
The usage requirements for cctz::cctz
should bring this automatically.
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.
Since the cctz PR will likely undergo some change, I consider this non-blocking
Here is a short CMakeLists.txt example of a possible project file | ||
using abseil | ||
|
||
cmake_minimum_required(VERSION 2.8.12) |
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.
Updated this after following the README myself, PTAL.
I'd like @Orphis to take one last look through the code since he is more knowledgeable about the ins and outs of CMake than me, but if everything goes well I suspect we'll merge this either tonight or tomorrow morning.
Looks like this is ready to merge. It's definitely not perfect but it's undergone a lot of review and work, is reasonable as a start, and it works. Thank you so much to EVERYBODY who has taken so much time on this. We were looking at this task with dread because none of us knew that much about CMake, and having this PR come so quickly was a wonderful surprise. There were and are a lot of strong opinions here, and the polite, professional, courteous, and intelligent level of discourse on this PR made it a delight to work on. Thank you everybody, Abseil is lucky to have contributors like all of you :) |
Thank you very much everyone! |
- c3a608de577e0c278b50916ad4803549929f8f72 Merging #8 inte... by Gennadiy Civil <misterg@google.com> - d0b528cdf5843db871784c629cb4e7c5165af716 explicitly cast -1 for Span::npos by Jon Cohen <cohenjon@google.com> - 32066311a4379f1144f029aaa3740af59b1e364e Remove GUARDED_VAR and PT_GUARDED_VAR entirely. by Abseil Team <absl-team@google.com> - 3d3c69d97d15b5c6457906631054109094c083a6 Remove unneeded inline on constexpr definitions. by Alex Strelnikov <strel@google.com> - a9a8fe71f90d0b80de8e77375228a7185032636b Remove unneeded lint suppression. by Alex Strelnikov <strel@google.com> GitOrigin-RevId: c3a608de577e0c278b50916ad4803549929f8f72 Change-Id: I0897ce0b11e41f83fed8d88f18e079a15d086527
Initial partial CMake support for abseil, created after the discussion of this afternoon.
Do not merge yet, this is still incomplete.
I created the pull request for tracking and avoid duplicated effort.
Adev