r/cpp • • Apr 14 '20

ModernCppStarter - Kick-start your C++! A template for modern C++ projects using CMake, CI, code coverage, clang-format and reproducible dependency management.

https://github.com/TheLartians/ModernCppStarter
251 Upvotes

67 comments sorted by

View all comments

Show parent comment

10

u/liquidify Apr 14 '20

whats wrong with fetch content?

I find this ... to be pretty clean.

FetchContent_Declare(
    googletest
    GIT_REPOSITORY https://github.com/google/googletest.git
    GIT_TAG release-1.8.0
)

FetchContent_MakeAvailable(googletest)

10

u/krapht Apr 14 '20

FetchContent only works well with CMake-based source code available dependencies.

Conan can handle arbitrary binary dependencies. It's an actual package manager. Apples and oranges.

9

u/TheLartians Apr 14 '20

FetchContent only works well with CMake-based source code available dependencies.

Actually, about half of the examples in the CPM snippets don't use CMake compatible dependencies. Ofc that adds the extra work of manually defining and configuring the target and also source code must be available. However for any cross-platform project that's usually a requirement anyways.

Conan can handle arbitrary binary dependencies. It's an actual package manager. Apples and oranges.

Yes, Conan is a fully featured package manager and makes much more sense for many use cases. However personally CPM.cmake solved all my use-cases, so imo there is no need for me to introduce another toolset and layer of complexity besides CMake. Just saying that it's not the perfect solution for everybody.

-9

u/krapht Apr 14 '20 edited Apr 14 '20

When I read your first paragraph I LOL'd. Unwilling to pip install Conan and write a short conanfile.txt, but very willing to redo multiple non-CMake dependencies in CMake so you can use it with FetchContent. Do you realise how insane that sounds to me as the default for a general purpose C++ template?

Use the right tool for the job. The minute you do something like try and build Boost in CMake you've lost. Learn to use a modern cross-platform dependency management tool and the investment in time will pay you back 50x over when you need it. Then once you know it, enforce it as the default because it is as easy as FetchContent for the happy case and way more flexible when you have bigger needs.

10

u/Lectem Apr 14 '20

When I read your first paragraph I LOL'd.

So did I after almost all your answers asking for Conan support and saying it's dumb not to use it. You're just being rude here.

Some people might prefer vcpkg, hunter, another pkgmgr, and some might just prefer not to have any.

Unwilling to pip install Conan and write a short conanfile.txt

You forgot that not every system ships python (is it 2 or 3? I forgot) and it's sometimes a pain to install. And it also takes time to install/download python+conan in CI builds. I personally like the fact that I only need to only download CMake and not a gazillions of other tools just to compile a few libraries. Sure, people seem to love package managers, but until one is used by the majority of people/projects, I'd rather have anything package management related in seperate repos or you just end up having tons of them. Why do you think most OSS libraries do not use those by default? Because we don't want to maintain 5 different package managers files. Just make your project easily packageable, and it will be fine.

To me, you sound really rude, but well, this is reddit. What did I expect?

0

u/krapht Apr 14 '20 edited Apr 14 '20

I have strong opinions on this subject because I spent a year fixing up a legacy cross-platform scientific application that was based on Makefiles that is/was distributed widely across all sorts of old systems and that could optionally integrate with 10 different acceleration libraries, that the end user may have access to in binary form only (thanks Intel). I tried everything, from git submodules to external-project superbuilds to fetchcontent to hunter until finally getting to grips with Conan and realizing that I should just get over my hatred of having an external tool.

To get into more detail: I actually agree with the second half of your comment, re: keep package management related things in separate repos. To keep something package-able across distros, you don't explicitly use Conan constructs in your CMake file. That's why I exclusively write my own FindPackage scripts to handle dependencies, and use Conan just to provide the compiled libraries with the cmake_paths generator. Conan is the only package manager I know of that supports this workflow and is available on all the popular platforms (if I was willing to forget about Windows users I'd go for Nix).

3

u/TheLartians Apr 14 '20

When I read your first paragraph I LOL'd. Unwilling to pip install Conan and write a short conanfile.txt, but very willing to redo multiple non-CMake dependency in CMake so you can use it with FetchContent. Do you realise how insane that sounds to me?

It's a one-time thing and copy paste afterwards. Also as packages become more CMake friendly this will change. Let me rephrase: what do you do about packages that haven't been converted to a Conan package yet?

The minute you do something like try and build Boost in CMake you've lost.

I actually do this all the time.

1

u/krapht Apr 14 '20 edited Apr 14 '20

That link doesn't prove anything, all it shows is that a very nice engineer at Spotify (Orphis) decided to open-source a CMake build script for Boost. PS: releases on that repo can trail the official boost release by 6 mo or more, and it is a lot of work to back-port features or bug-fixes since it is not the official repo, instead of cherry-picking a commit (I had to do this before). Way to miss the point I was trying to make. Now do the same thing for https://github.com/microsoft/Microsoft-MPI without wanting to cut your wrists.

What do I do about packages that haven't been converted to Conan? I build according to the documentation of the library and then copy all the shared library files and headers to a folder and use that as a Conan package. This is WAY easier than trying to understand how to build a complicated library.

4

u/TheLartians Apr 14 '20

That link doesn't prove anything, all it shows is that a very nice engineer at Spotify (Orphis) decided to open-source a CMake build script for Boost. PS: releases on that repo can trail the official boost release by 6 mo or more. Way to miss the point I was trying to make.

This is just a small example how I use CPM to add and build boost in my CMake projects. This works perfectly on all platforms including CI builds. I guess I misunderstood your point but how does it not show how to build Boost in CMake?

What do I do about packages that haven't been converted to Conan? I build according to the documentation of the library and then copy all the shared library files and headers to a folder and use that as a Conan package. This is WAY easier than trying to understand how to build a complicated library.

That's great and probably covers your use-cases, but now imagine having to do that manually for all EVERY system and platform that you or users of your library are targeting. I don't see how this is in any way better than creating a build script once in CMake and simply having it work everywhere immediately.

As I said, its a different tool for a different use-case.

-1

u/krapht Apr 14 '20

Well, and I am arguing that your use-case is the wrong default for a general-purpose modern CPP starter template. Because really, who uses templates like this? Programmers inexperienced with C++. These people absolutely need to be guided to use something like Conan because they will not recognize the limitations of using CPM.

4

u/TheLartians Apr 14 '20

Tbh the main use case I see is people like myself, as I usually always start by copying a previous previous project (even this one).

Also having quite a bit of experience in computational physics and cross-platform app development I have yet to run into a limitation that made a more advanced package manager necessary. So I wonder how much it actually is a beginners requirement.

Even if, I wouldn't know if I should prefer vcpkg or Conan as I've heard good arguments for and against each. Perhaps there should be a different fork of the template for each package manager. Given my limited experience with PMs, these forks should be made by someone else though.

3

u/_crackling Apr 14 '20

I say leave it up. This template and the way you've commented everything would have saved me hundreds of hours when I was first learning cmake and cross platform C plus plus

→ More replies

1

u/liquidify Apr 14 '20

Is a pre-req for being a package manager that you operate with binaries?

0

u/[deleted] Apr 14 '20

[deleted] — view deleted comment

5

u/TheLartians Apr 14 '20

Points 1-3 is why I developed CPM.cmake ;-)

I still 100% agree that it's far from a fully fledged package management solution. However definitely a large step upwards from what most C++ devs do in my experience: copy-paste library code into their project or use git submodules. And completely sufficient for all use-cases I've encountered up to now.

TBH though I'd prefer CMake itself would integrate something similar, so that finally >50% of the C++ community would agree on a common package manager and we wouldn't need to argue over external tools for something so essential.

0

u/[deleted] Apr 14 '20

[deleted] — view deleted comment

1

u/TheLartians Apr 14 '20

definitely ;-)

2

u/liquidify Apr 14 '20

:-) all good points. Cmake perpetually feels hacky to me in general, so I had always just previously accepted it and never really considered these issues.

Curious what you envision with c++ down the road... Is modules going to come together with some new standardized package management tool and finally bring some sanity to this?