Skip to content
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

Merged
merged 5 commits into from Nov 6, 2017
Merged

Add CMake support #8

merged 5 commits into from Nov 6, 2017

Conversation

adevress
Copy link
Contributor

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

@kumagi
Copy link

kumagi commented Sep 27, 2017

👍 My CLion requires CMake.

@Orphis
Copy link

Orphis commented Sep 27, 2017

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.

@tituswinters
Copy link

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).

@adevress
Copy link
Contributor Author

@tituswinters Thx Titus, I was not sure about that, that's why I kept compatibility with 2.8's style.

@Orphis
Copy link

Orphis commented Sep 27, 2017

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.

@adevress
Copy link
Contributor Author

@Orphis Fixed

Most of the staff should be there now. The remaining bits are types/utility/memory/meta
Abseil compiles with cmake and unittests passed without issues on OSX and RHEL6 on my side.

@Orphis
Copy link

Orphis commented Sep 28, 2017

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.

@adevress
Copy link
Contributor Author

adevress commented Sep 28, 2017

Out of curiosity, where did you get the 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.

@Orphis
Copy link

Orphis commented Sep 28, 2017

Well, 2.8.12 added target_compile_options() which is currently used in the code above, so the minimum version should be that one. Other commands in the target_ family have been added and make it way more robust to work with since you deal less with strings and just target objects instead.

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.

@adevress
Copy link
Contributor Author

@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.

@agauniyal
Copy link

Would this mean I don't have to use Bazel?

@tituswinters
Copy link

@agauniyal - Yes. Abseil team will still primarily support bazel, but we'll do our best to keep both working once something like this lands.

@agauniyal
Copy link

@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 :)

@tituswinters
Copy link

@agauniyal - And to be clear - we've got nothing against cmake, it's just not what we're experienced with or primarily focused on.

)


add_library(${_NAME} SHARED ${__dummy_header_only_lib_file})
Copy link

@Orphis Orphis Oct 26, 2017

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.

Copy link
Contributor Author

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

Copy link

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.

Copy link
Contributor Author

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)
Copy link

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.

Copy link
Contributor Author

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.

Copy link

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.

Copy link
Contributor Author

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}
Copy link

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.

Copy link
Contributor Author

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}
Copy link

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine for me

Copy link
Contributor Author

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.

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}
Copy link

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.

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

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)
Copy link

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

${STACKTRACE_PUBLIC_LIBRARIES}
)


Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed



list(APPEND STRINGS_PUBLIC_HEADERS
"ascii_ctype.h"
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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

${BAD_OPTIONAL_ACCESS_PUBLIC_LIBRARIES}
)


Copy link
Contributor

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

Copy link
Contributor Author

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_header_library(
Copy link
Contributor

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.

Copy link
Contributor Author

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
set(_ABSL_HELPERS_PATH "${CMAKE_CURRENT_LIST_DIR}")

#
# create a static library absl_based on the following variable
Copy link
Contributor

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"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@JonathanDCohen
Copy link
Contributor

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

@adevress
Copy link
Contributor Author

adevress commented Oct 31, 2017

@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 :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URLs missing

Copy link
Contributor Author

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
Copy link

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.

Copy link
Contributor

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)
Copy link

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.

Copy link
Contributor

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)
Copy link

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.

Copy link
Contributor

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}
Copy link

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.

Copy link
Contributor

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)
Copy link
Contributor

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.

@JonathanDCohen
Copy link
Contributor

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 :)

@gennadiycivil
Copy link
Contributor

Thank you very much everyone!

@gennadiycivil gennadiycivil merged commit 78e1abc into abseil:master Nov 6, 2017
gennadiycivil pushed a commit that referenced this pull request Nov 6, 2017
  - 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet