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

added initial cmakelists.txt file. #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

madmongo1
Copy link

Adds support for the CMake build manager.

Also adds [optional] support for the hunter dependency manager which is fast becoming the de-facto standard for seamless cross-platform management of dependant libraries.

after pulling, you can build the tests with

mkdir build
cd build
cmake <path_to_impl_ptr_source>
make

Copy link
Collaborator

@muggenhor muggenhor left a comment

Choose a reason for hiding this comment

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

I like the idea of adding a decent build system. What I don't like however, is the complexity of yours. Build systems are difficult enough to get right and to understand. Your reliance on Hunter seems to add a lot of extra required knowledge without any clear benefit over plain CMake.

I had already written my own CMakeLists.txt for this last week. It contains warning detection and color-enabling for Ninja and still is only 98 lines. I've pushed it to my private branch as 4c6f6e1. Please tell me what you think your PR offers that the simple approach doesn't.

#

project(ImplPtr)
set(CMAKE_CXX_STANDARD 14)
Copy link
Collaborator

@muggenhor muggenhor Sep 10, 2017

Choose a reason for hiding this comment

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

  1. This is wrong: right now C++11 can be used for building
  2. This fixes it to a specific version instead of requiring a minimal version. Try target_compile_features(impl_ptr INTERFACE cxx_std_11) instead (or better: the list of C++11 features we use).

cmake_policy(VERSION 3.8)

###############################################
# NOTE FOR THOSE UNFORTUNATES WHO DON'T KNOW OF HUNTER
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems like a lot of overkill for just getting Boost. Not to mention that "those unfortunates" is a rather condescending tone to take. I get the impression from this text that you just like hunter a lot and as a result it's become your hammer for which every problem needs to be a nail.

Could you explain why find_package(Boost REQUIRED ${MIN_VERSION}) isn't enough? That approach will work with a system-installed boost, which I doubt this Hunter thing does as from the little info I've gleaned about it it's basically it's own package manager.


add_library(impl_ptr INTERFACE)
target_include_directories(impl_ptr SYSTEM INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are no generated sources, so adding the binary dir is not necessary.

add_library(impl_ptr INTERFACE)
target_include_directories(impl_ptr SYSTEM INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You're adding a BUILD_INTERFACE, why not an INSTALL_INTERFACE?

Copy link
Author

Choose a reason for hiding this comment

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

I Haven't got round to the that bit yet. The first commit was simply to get this building and running tests on any platform without having to install any dependencies.

if (HUNTER_ENABLED)
sugar_include(test)
else ()
find_package(Boost REQUIRED)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you repeat the package detection that you've already done above?

Copy link
Author

Choose a reason for hiding this comment

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

That's a harmless oversight. Repeating a dependency in cmake has no ill effects.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, but it is a reason to not merge this PR in. "It works" isn't good enough, it needs to be understandable too.

add_subdirectory(test)
endif ()

add_executable(impl_ptr_tests ${TEST_SOURCES})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Erm? Why aren't you creating this target directly in the test dir?

Copy link
Author

Choose a reason for hiding this comment

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

That's one way. Easy to do if that's where you want it.

@@ -0,0 +1,22 @@
#
# this file is used if the developer has opted not to use Hunter cmake extensions
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's wrong with plain CMake? This adds a lot of indirection, and I'm not seeing any advantage right now.

Copy link
Author

Choose a reason for hiding this comment

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

Try building a project for OSX, linux, windows, ISO and android. You'll soon start to appreciate not having to pre-build all your dependencies for every platform, keep those dependencies up to date, and remember where you built them.

This is what hunter does for you. It's the 80% of cmake that's missing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove ISO from that list, add QNX and WinCE and you're describing the list of platforms that I've had to target with CMake for a single (large) project. Pre-building is effectively a caching strategy: it can be useful (during development it certainly is), but it's very hard to get right and the benefits are non-existent for small projects.

I do thank you for pointing it out to me, because it may be useful at work.

This however, is a header-only library, so there's no external dependency to be built. I.e. the tests are the only build artifact and those only use Boost's header-only part too.

Copy link
Author

Choose a reason for hiding this comment

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

WinCE and QNX are covered with hunter by using the toolchain files that have been conveniently supplied by ruslo. the project on github is ruslo/polly.

ISO == iOS, my apologies.

Let's re-discuss when you have come to get to know hunter.

The author is not english so the documentation can take some decoding. Feel free to ping me if you have questions.

@@ -0,0 +1,12 @@
sugar_files(TEST_SOURCES
Copy link
Collaborator

Choose a reason for hiding this comment

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

This just looks like a duplicate of test/CMakeLists.txt, violating DRY (Don't Repeat Yourself). If you actually need to duplicate things with hunter/sugar to be able to build without it then I think you should just build without it. This just seems to double required maintenance effort.

Copy link
Author

Choose a reason for hiding this comment

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

In my projects (globally deployed services for very large companies with massive user bases) I always use hunter because I value the reliability, good integration with CI and automatic cross-compilation.

However, I am aware that not everyone will be persuaded of the benefits on first sight (usually the moment someone has actually used Hunter, they never stop using it).

So I thought I'd put equivalent code so that people could use it both ways.

I am a busy person so for me to contribute to a project which has dependencies (even just one), it is helpful to have automatic dependency management.

I don't keep a copy of the boost libraries in my usr/lib because I am often cross-compiling against a number of different systems and versions of c++ and I can't risk cmake etc picking up the wrong version.

Hunter solves that too.

However, this is your project. If the commit is not welcome, no problem. I'll just play on my fork and just contribute code changes.

Another solution might be to have a separate subdirectory for (vanilla) cmake and one for hunterised cmake.

If you ever want this package to be adopted as a hunter package (you do). Then a hunterised version of the cmakelists.txt file will be made in the hunter packaging fork in any case, because the dependency on boost needs to be managed.

Thanks for reading the commit.

R

Copy link
Collaborator

Choose a reason for hiding this comment

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

From your description I get the impression that Hunter, while it uses CMake, is in practice a completely different build system that isn't interchangeable with plain CMake. I had hoped it would be able to just, at CMake-generation-time, walk all targets, extract its properties, and use those to produce an exportable "package". If it requires interfacing with CMake through it's own abstraction layer that seems rather unfortunate because that's a very invasive approach.

Copy link
Author

Choose a reason for hiding this comment

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

It's not completely different.

You can use Sugar without deploying it from hunter, it's just that hunter supports it out of the box.

Sugar is about source file management (something that cmake is bad at - since source file properties don't migrate out of sub_directories).

Hunter is about dependency management.

You can simply ignore all hunter code in a cmake project by setting the cache variable HUNTER_ENABLED=NO

As long as your packages can be found, it will all still work.

)

foreach (file ${TEST_FILES})
list(APPEND TEST_SOURCES "test/${file}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you can just add ${CMAKE_CURRENT_SOURCE_DIR}/ in the set() statement above.

Copy link
Author

Choose a reason for hiding this comment

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

They would then be absolute paths. Sure that can work.

@@ -0,0 +1,68 @@
cmake_minimum_required(VERSION 3.8)
cmake_policy(VERSION 3.8)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not necessary, the cmake_minimum_required already defaults to the same policy version.

@muggenhor
Copy link
Collaborator

I'll look at Hunter during the next week, because the problem that you mention, easy pulling of external dependencies, is one that I would very much like to see be less of a problem.

@madmongo1
Copy link
Author

madmongo1 commented Sep 10, 2017 via email

@yet-another-user
Copy link
Owner

Guys, have you come to an agreement regarding this pull request? I do not use/know cmake so I'll go with what you think is best. There seems to be a branch conflict also to resolve...

@madmongo1
Copy link
Author

madmongo1 commented Sep 15, 2017 via email

@yet-another-user
Copy link
Owner

yet-another-user commented Sep 15, 2017 via email

@madmongo1
Copy link
Author

madmongo1 commented Sep 15, 2017 via email

@muggenhor
Copy link
Collaborator

muggenhor commented Sep 25, 2017

@madmongo1 I rebased this branch on my plain CMakeLists.txt in this branch: madmongo1/pull-cmake.

After looking for a bit I do see some value in the Hunter portion, especially the virtualenv-like behaviour may be relevant here. The Sugar part of it doesn't seem to add any value over plain CMake however.

So if you agree, could you rebase your Hunter support (without the Sugar part) on top of latest master then we can get that in?

PS excuse the delayed reply, I've been doing (or trying to) way too much things at the same time lately.

@muggenhor
Copy link
Collaborator

Looking a bit more at Sugar I'm not clear what problem it's trying to solve, but it looks like it has some overlap with https://github.com/tomtom-international/cpp-dependencies. The latter has the advantage of not being necessary while building, only while running this tool after having added/removed a source file. It's even possible to automate this such that it's only necessary to execute this in CI (if you give these CI systems commit/push access).

@muggenhor
Copy link
Collaborator

I've just been at Meeting C++ where this, build systems and dependency management, are pretty hot topics. I've discussed this with a few people here (mostly Mathieu Ropert and Diego Rodriguez-Losada) and I believe the main problem with this approach is that it confuses the build system and package management. Dependency fetching is part of package management, not of building. That being said: dependency and package management are necessary, confusing the two just makes solving this more harder though.

I've been pointed at Conan, I haven't yet had the time to look at it, but from what I've been told it may solve this problem in a better way because it keeps package management split out from the build system and instead better integrates the two. Requirements can be specified in a similar format to Python's requirements.txt in a conanfile.txt. I'm not sure how usable this really is at this time, I have to look into that. It seems promising at least.

@madmongo1
Copy link
Author

madmongo1 commented Nov 11, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants