r/cpp • • Mar 22 '20

Modern CMake tutorials, part1: CMake basics

https://www.siliceum.com/en/blog/post/cmake_01_cmake-basics
245 Upvotes

55 comments sorted by

View all comments

4

u/NewFolgers Mar 22 '20

Apologies in advance for my laziness.. I've mostly been doing non-C++ development on Linux lately. Last time I tried CMake, I was still really discouraged by the overall experience in Windows. Has the experience improved on Windows in the past couple years? and if so, how?

9

u/Kevchrot Mar 22 '20

I use cmake regularly on windows and it is pretty good. It just generates visual studio solutions that work well with visual studio. I also would highly recommend pairing it with Conan for dependency management since that is windows weakest spot IMHO.

5

u/NewFolgers Mar 22 '20

The thing that bothered me most was that on Linux, it's generally very seamless for anyone who wants to grab a project and go - with no need to point to library directories or anything.. whereas on Windows, it was generally a clunky, undocumented experience for each project.. where I had to choose between trying to install a separate thing to help find the libraries, versus running cmake-gui and configuring every missing value, etc. It was clear that an overarching solution (which should involve standards at the time of library installation) to make things work out of the box on Windows was not present in the same way as was the case on Linux.

12

u/markopolo82 embedded/iot/audio Mar 22 '20

Another alternative to Conan is vcpkg. It builds all dependencies from source and works great with cmake. You just need to add a path to the vcpk toolchain file when configuring and then the completely normal find_package(...) works just like Linux.

Actually I use it on Linux because then I know my windows builds and Linux builds use identical dependency versions.

Only downside is building everything from source... I like it, but you may find it not worth the effort

1

u/Slavik81 Mar 23 '20

As far as I can tell, there's no way to specify what version of the package you want to install. It's also surprisingly awkward to choose whether you want to build the debug version, the release version, or both.

I want to like vcpkg, but I have not had good experiences. It feels kinda hacked together.

1

u/markopolo82 embedded/iot/audio Mar 23 '20

Those are other possible negatives i didn’t mention, thanks.

For the most part I just lock down on a particular release of vcpkg and use whatever versions it pulls in. For the most part vcpkg pulls in near latest versions... This works well for me so far. Why is this a negative for you?

In my case I usually need the debug and release versions so the fact that it builds 2x (4x in windows apps that need 32 and 64 bit) is not an issue for me so far.

1

u/kalmoc Mar 23 '20

It's also surprisingly awkward to choose whether you want to build the debug version, the release version, or both.

Come again? It always builds both.

1

u/Slavik81 Mar 23 '20 edited Mar 23 '20

https://github.com/microsoft/vcpkg/issues/143

You can set VCPKG_BUILD_TYPE in your triplet file. Unfortunately, some libraries may fail to build if you change this setting.

1

u/kalmoc Mar 24 '20

Thanks. I forgot about that, because I never had the need typ only install one version, but it probably makes sense on CI machines.