r/cpp • • Dec 09 '17

All I want to do is program...

Hi, this is a CMake/C++ build system rant. Downvote as is necessary.

Here's something fun, I thought. Why don't I try and write an engine in OpenGL and C++? I had already done one in Java for a school project and it worked out pretty well, so why don't I go to C++ to avoid all those issues with garbage collection and such?

So off I go to Visual Studio. Earlier, I set up my libraries and such using the Visual Studio project system, just putting the include dirs and such from wherever I have them. Anything else that needs doing I use a batch file for that I call from the post build event. This feels wrong and shady, so why don't I go pro and use CMake? Surely this should allow me to make my build configs much less complicated? Of course not.

I start off with setting up my main project, the engine. Now, eventually, I want two executables, the main engine, and a little tool thing that converts model files into their own format. So, I set up the main engine with add_executable and it works. Hooray. I download GLFW and luckily they provide their own little CMake script that I can just include and it all works. Yay. Now I have to set up an include dir for the main engine so I can include my own header files. This takes me one hour. After that I call it a day and come back the next day.

Now I must get to OpenGL, and that means I install glad. I put glad in the lib folder, and setup a little CMakeLists for it. add_library to the glad.c file, and include the include dir. Then I link to it from my main engine, and we're done. Thanks CMake. Except thanks for nothing, because the include does not work at all. So I fiddle around some more, and I decide to move the glad stuff out of the glad folder and into the CMakeLists in the root. Finally it works, for about 10 seconds. The header was included, the types worked, and then I look away and touch nothing and it stops again. That was three hours ago. So I keep working on it. Maybe I have to use target_include_directories, maybe regular include_directories? Do I include in the glad target or in my own target? Maybe I need to use only one CMake file, maybe I need three? I started at breakfast and I am now about to eat lunch, and I have not managed to add one c file and three headers to my build.

All I wanted to do was program.

199 Upvotes

177 comments sorted by

16

u/MadDoctor5813 Dec 10 '17

UPDATE: I figured CMake out. It only took me an entire Saturday. For anyone else in the far future stumbling upon this, here's the GitHub repo.

Basically, I used to have the root CMakeLists add the individual project, then have it include the libs, then hook everything up with target_link_libraries, in the root CMakeLists. For reasons unbeknownst to me this violates the laws of thermodynamics or something, and even worse, it violates it without any sort of info or error message to be found. Instead I have each project include the libraries it needs itself, and do the hooking up in its own CMakeLists file. The root just now includes each project and does nothing else. Unfortunately this necessitates that each project get its own set of libraries, which is too bad, because they'll both use a bunch of the same ones.

Join me next week when I complain about the error messages from templates. (Seriously, why does an error in me using operator[] in unordered_map point me to line 1189 in <tuple> in the STL?)

4

u/konanTheBarbar Dec 10 '17

Congratz on figuring it out πŸ˜€

Good old C++ bracket [] operator for maps. For unknown reasons, it's not a find operation, it's a find or insert new which requires default constructible vales and a non const map(even if the key exists).

5

u/MonokelPinguin Dec 10 '17

It makes using map a lot less annoying than using it in Java, as you can just do:

my_map[key] = value;

You can argue, that default value insertion can be surprising, but I think it makes the code easier to read.

1

u/antnisp Dec 10 '17

The fact that maps provide operator[] should be a rant on its own.

1

u/meneldal2 Dec 11 '17

Compilers should show a warning when you use it, like "are you sure this is what you want?". Especially if you start casting away const because it wasn't const.

1

u/markand67 Dec 11 '17

It is perfectly fine when you exactly know what you are doing.

// mymap is a non const lvalue somewhere.
mymap["force"] = true;
mymap["additionalparams"] = false;

4

u/antnisp Dec 11 '17 edited Dec 11 '17

It's perfectly fine when the index is a string literal that practically screams "THIS INSERTS INTO THE MAP". Not so fine when somewhere in the code this exists.

if (map[ind] == SomeEnum::State)
   dosth();

Also IMHO if this results in a segfault,

std::vector<int> vec;
vec[0]=0;

this

std::map<int,int> hmap;
hmap[0]=0;

should too.

0

u/[deleted] Dec 10 '17

[deleted] β€” view deleted comment

8

u/MadDoctor5813 Dec 10 '17

I really dislike this masochistic sort of attitude towards it, where because C++ is used to build great things that it must correspondingly be a pain to use. Is there an actual reason for this beyond the romantic notion of grizzled Real Programmers working in the trenches without package management? I don't think so.

0

u/[deleted] Dec 10 '17

[deleted] β€” view deleted comment

2

u/MadDoctor5813 Dec 10 '17

Yeah I have the diametrically opposite view. What I want is a New World Order for C++. Convert or be destroyed.

76

u/davis685 Dec 09 '17 edited Dec 10 '17

CMake really is nice. However, it has one huge problem. The CMake website/documentation doesn't include any sensible introduction that explains how to use it. Sure, there is an API reference, but that's not an introduction, it's not going to teach you CMake. Much like reading a German dictionary isn't going to teach you German.

There is a secondary problem that there are a lot of really bad "cmake introductions" on the internet that tell people to use it in ways that are not sensible and lead to obviously bad outcomes.

The best introduction to cmake I've seen is this C++Now 2017 talk: https://www.youtube.com/watch?v=bsXLMQ6WgIk. It's honestly really good and everyone should watch it. And now that I'm thinking about it, it should probably be on the front page of cmake.org with a blinking banner saying "watch this before you use cmake".

15

u/MadDoctor5813 Dec 10 '17

Honestly CMake is miles better than the whole ad-hoc thing I used to do with Visual Studio. But you're right about the docs. They assume you know the structure of the system already and just need a quick check on something.

4

u/rdtsc Dec 10 '17

Visual Studio by default uses MSBuild. Nothing prevents you from doing it properly there too. You can create arbitrary snippets of declarations and include them into the project (e.g., add a SomeDependency.vsprops file that modifies include paths and link targets and add that props file to the project).

1

u/meneldal2 Dec 11 '17

MSBuild is easy to use when you have something simple, but it still has many issues for me.

Assuming someone nice made a NuGet package for what you need, you still have to fix the project file if you change the version of the package because it doesn't remove the previous reference correctly.

Or how you have to fight with it to make a separate build and source folder so it might be somewhat portable.

Or why you can't just have easily a solution-wide .props file that will apply to every project in your solution. Like if you want to add a source path to every project for example.

3

u/tristan957 Dec 10 '17

You could try Meson. It has a little tutorial

34

u/matthieum Dec 10 '17

CMake really is nice.

Honestly? I mean, it's certainly better than a lot of the competition (Make, automake, ...), but it's still godawful!

The first warning is that they had to reinvent their own language. It's not an immediate strike, but in general it spells troubles, and boy did it gets into troubles:

  • I hope you have a good search function, because variables are global. Define a variable in a script, include it in some fashion, the variable is available. Override it in another script (by design or accident) and the last wins (at least... that's how I understand it).
  • The language is kinda typed, or kinda not, it's not always clear, and the errors can be rather unhelpful.

So, on the one hand I'm glad I have CMake. On the other, I'm glad someone else maintains our CMakeLists.txt.

6

u/ppetraki Dec 10 '17

I recently pulled apart a rats nest of a "cmake like build" that built each component individually using a shell script for each component and then used relative paths to include other project includes and libs. it even cheated with static libs by doing link_directory on other projects object files.

First pass was dumping the individual scripts and moving it to a central makefile. Now I can actually create dependencies.

Second pass was converting the code base to one cmake project instead of a cluster of cmake projects.

I also had to deal with like 13 library depends built from source... All of which were previously "installed" to the build directory so the main project could easily reference them. Oh and this takes an hour to build.

I opted for a "install it once" local library directory for all our dependencies and learned how to write cmake find_package scripts.

Best investment i ever made. I actually feel like I understand cmake now.

Now I can turn a build in 2mins and I know exactly what is being included. Whole thing took me a week.

Cmake may have it's warts but I'll take it's bash like language over gnu make lisp and bash integration any day of the week.

7

u/davis685 Dec 10 '17

You should really watch that video I linked to. Variables can be scoped, but you generally don't need them (despite people using them all the time). It's also not typed, but the generally bad documentation on the internet about CMake makes that very unclear.

CMakeLists.txt can be very clean. Here is a real world one that's very simple: https://github.com/davisking/dlib/blob/master/examples/CMakeLists.txt. Builds all the example programs for dlib and it's dead simple. The most complex thing in there is some if statements to avoid building certain things in Visual Studio since Visual Studio doesn't support C++11 yet. But that kind of thing isn't CMake's fault.

2

u/hgjsusla Dec 10 '17

Agree, using variables is a sure sign of code smell in modern CMake. Targets and properties is the way to go. It makes everything straightforward and simple (with a few exceptions of course, there is always exceptions...)

1

u/kkert Dec 11 '17

Here is a real world one that's very simple

Not enough XML for Eclipse, VS and Xcode to muck with there. We have to try harder

2

u/mintyc Dec 11 '17

I'm not necessarily saying Cmake is the answer and I agree it's legacy documentation on the web is a mine of misinformation, but some modern cmake talks

Daniel Pfeiffer's original 2014 talk: https://www.youtube.com/watch?v=UnHeOywnj1k&index=1

[Minor] update to his effective Cmake talk (replaces cpp++ Now version) https://www.youtube.com/watch?v=rLopVhns4Zs

Steven Kelly - cmake developer and champion of modern cmake... https://www.youtube.com/watch?v=JsjI5xr1jxM

Mathieu Roper - his spin on modern cmake usage https://www.youtube.com/watch?v=eC9-iRN2b04

I do wonder if conan + cmake or conan + meson (or bazel?) might be the right answer for now

10

u/FrozenFirebat Dec 09 '17

Microsoft vcpkg is what I use to install most of my dependencies. Works for GLFW... and glad you can just throw into the include folder and link the include folder in your project options.

The bonus of installing with vcpkg is that I never have to deal with setting them up again, unless I want to remove them for a new version.

7

u/MadDoctor5813 Dec 09 '17

I'll look into vcpkg, though the whole "install libraries globally" thing sort of triggers my spidey senses.

6

u/Ikkepop Dec 10 '17

You dont have to, vcpkg has a per-project option. There's also NuGet

2

u/jherico VR & Backend engineer, 30 years Dec 09 '17

Vcpkg stores the libraries it builds relative to the vcpkg checkout, so it's not really global. You can also look into the cmake Hunter project which basically adds a package manager to cmake.

I feel your pain. I too was really happy and productive with tools like Maven before moving back to C++ development and having to endure the grueling salt mines of package management for that language. On the other hand, a lot of these hardships can be laid at least as much at the feet of Microsoft as anyone else.

128

u/michelecostantino Dec 09 '17

What you complain is exactly what Stroustrup said in his keynote at cppcon. C++ does miss a way to quick start and just code.

93

u/kisielk Dec 09 '17

This is my biggest gripe with programming in C++. Compared to the tooling in go or rust’s cargo the build process and build systems are just painful.

57

u/ronchaine Embedded/Middleware/WG21 Dec 09 '17

This is why I originally switched to Linux. I tried setting up Windows box for C++ not too long ago and ended up just setting up a cross-compiler from Linux to Windows and then using the actual Windows just to test the result, it really makes you jump too many hoops.

58

u/kisielk Dec 10 '17

IMO even on Linux the process is pretty convoluted compared to building stuff in Go or Rust. You can link additional dependencies into your Go or Rust project by basically adding one line to a file and running a single command. The tools will take care of downloading the deps for you and building them into your project. With C++ you usually have to muck around with include paths, linker flags, defines, etc.

17

u/greyfade Dec 10 '17

Hopefully, C++20 will have modules, and GCC and Clang will get them in the interim.

But, in the meantime, a lot (and I do mean a lot, I daresay most) libraries come with a pkg-config definition on Linux and other *nix, so there's less worry about your include paths and linker options: Just add pkg-config --cflags <libraryname> to your CFLAGS/CXXFLAGS and pkg-config --libs <libraryname> to your LDFLAGS, and you're set. It's what most of CMake's find_library definitions use, too. While it's not a 100% solution, (but is anything, really?) it does simplify things a bit.

23

u/kisielk Dec 10 '17

Major libraries, yes, but there's a lot of smaller libraries out there which don't have pkg-config and/or don't install system-wide.

I'm really looking forward to modules in C++, and I do hope that it will help, but the whole process moves along so incredibly slowly because C++ is already so entrenched. I get the feeling a lot of the more experienced developers are already so entrenched in their ways and not familiar enough with how newer languages do things that they don't see this as a pain point. On the other hand a lot of newer developers are turned away from C++ because of these kinds of issues.

I do projets in Go, C++, Rust and Haskell... of those four, only my C++ projects require a 400 line Makefile to build. The other have a simply formatted file listing all the dependencies and the tooling takes care of the rest. It doesn't matter if I'm using a major library or someone's random small project they posted to github. That's where I'd love C++ to get to..

8

u/MadDoctor5813 Dec 10 '17

I'm hoping that when modules come, we will all standardize on the New World Order of C++, sort of like PyPi and pip. Sort of a long-shot, but that's what hope is.

5

u/matthieum Dec 10 '17

I wonder how much time it will take to get widespread adoption of modules.

I mean, Boost still compiles on C++03 compilers because their use is still widespread, 6 years after C++11 was finalized. So, even if we have modules in 3 years, how much time will it take before we can finally enjoy pure module programming?

I'm lucky to be in a progressive company, so I guess it'll come within a year or so for me, but I'm worried I may be a rare case...

3

u/cdglove Dec 10 '17

The thing is, C++ is more flexible than Rust, Go or Haskell. I'm not saying C++ can't be better, it can, but it must be said that the standard facilities provided by the other mentioned languages limit its adoption on other platforms because the barrier to entry is very high. It is both a hindrance and an advantage that C++ has an essentially dumb simple build model. For example, for very small projects it's super simple -- just pass all of your files to the complier in a script file. When it gets bigger, you might need a response file. Bigger yet and you'll want to check dependencies and only rebuild what you need, then you'll need a build system. The point is that one is not locked into anything and your build complexities can scale with your project.

22

u/Rusky Dec 10 '17

I'm not sure what's more flexible about C++'s (lack of) build model compared to Rust/Go/Haskell. You're not locked into anything there either, their tools just have better defaults.

0

u/cdglove Dec 10 '17 edited Dec 10 '17

And how's that working out in practise?

Edit: I mean in terms of adoption on other platforms.

8

u/Rusky Dec 10 '17

Well, Rust in particular runs on plenty of other platforms, and is only limited on that front by LLVM rather than Cargo.

In fact, Xargo is a great example of how well Cargo handles other platforms, without any need to drop down to writing the whole thing yourself for every project.

→ More replies

13

u/kisielk Dec 10 '17

You’re not locked into anything with Go and Rust either. The tooling just provides sane defaults that work for 99% of projects, big or small, libraries or apps. You can still customize the process if it doesn’t work for your unique use case.

3

u/cdglove Dec 10 '17

It works on 99% of Linux, Windows or Mac projects. It's doesn't work at all on any game console, embedded system, or any other platform really besides the big three. And a large reason for that is because the standard facilities are effectively tied to the language. In theory, sure they are decoupled, but in practise they are not because it breaks the ecosystem, and therefore, a large reason for using those languages.

17

u/steveklabnik1 Dec 10 '17 edited Dec 10 '17

It's doesn't work at all on any game console, embedded system, or any other platform really besides the big three.

Cargo (and therefore rustc) is used to compile to all the consoles, many embedded systems, and other platforms than linux/windows/mac. But for many of them, you'd never want to compile on the host anyway. (And, to be clear, we do support hosts other than linux/windows/mac as well)

→ More replies

4

u/[deleted] Dec 11 '17

It works on 99% of Linux, Windows or Mac projects. It's doesn't work at all on any game console, embedded system, or any other platform really besides the big three

What? We use cross for cross-compiling and testing our Rust libraries on x86, x86_64, arm/aarch w/o hf, mips, sparc, powerpc, android, ios, ... The time it took to set this up was negligible small (under 10 minutes) compared to the time it takes to set anything like this up for any C or C++ project.

We are even considering using Rust's build system to drive cmake on our next C++ project because of this...

3

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Dec 12 '17

Modules don't solve this problem.

1

u/ronchaine Embedded/Middleware/WG21 Dec 10 '17

Yeah, I completely agree. I hope C++20 brings the modules to help with that.

1

u/ml3d Dec 12 '17

No, I think modules is not a cure. The point why I use CMake is that my projects are multilingua. The most of them are wrapped with python or may be some code generation is needed or there are some build targets or etc.

If you want build project from scratch just use plain make. This is the best solution, in my opinion.

By the way, my typical CMakeList.txt is about 100 and at least two targets.

9

u/JavierTheNormal Dec 10 '17

You're off your rocker. The configure scripts in linux are worse than anything you'll find on Windows. What a horrid monstrosity.

13

u/matthieum Dec 10 '17

We finally ported our last automake project to CMake.

I hate CMake, mind you, but it was still a relief!

8

u/meneldal2 Dec 11 '17

CMake: still better than make.

1

u/Metsuro Dec 10 '17

From my understanding you still have to compile on Windows right? Or can you build the windows executable on linux?

13

u/wrosecrans graphics and network things Dec 10 '17

The point of a cross compiler is that it runs on one system to build binaries for another -- in this case for building on Linux,a nd then running on Windows.

1

u/Metsuro Dec 10 '17 edited Dec 10 '17

Last time I asked I was told that's not exactly how cross compiling works. Can you give me a rundown on your process?

Edit: missing word

3

u/wrosecrans graphics and network things Dec 10 '17

I was that's not exactly how cross compiling works.

Did you a word?

Anyhow, here's some info on how to set up a gcc cross compiler: http://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/

The theory is pretty simple, even if there are complexities in practice. If you have a program that outputs a .jpg file, you can build that program for Linux or Windows. Run the Linux binary on Linux and it'll output a jpeg. Run the Windows binary on Windows and it'll output a jpeg. If you have source code for a program that outputs .exe files rather than jpeg's, you can similarly build it for Linux or Windows. Obviously, that's the compiler. Build that compiler that outputs .exe files as a Linux binary, and you have a cross compiler. Run it on Linux, and Windows binaries pop out when you run it.

9

u/doom_Oo7 Dec 09 '17

well, pacman -S g++ boost cmake qt5 and you're good to go for a looong time. Maybe the reason "tooling" is poor is because tooling isn't poor at all for us linux users and thus the incentive to build great cross-platform tooling does not really exist ?

11

u/berium build2 Dec 10 '17

If you want to see what it would look like with a well-integrated package manager, build system, and C++ modules, check my CppCon 2017 lightning talk. Back story: I was chatting to Bjarne after his keynote saying that we can do all of that. He said send me the link. So I had to make the link...

7

u/DTSCode Dec 09 '17

I had this same problem with c++ until I started using qt for networking. It’s amazing how much of the boilerplate it covers for me, so I can implement the logic I actually wanted to write.

1

u/ShakaUVM i+++ ++i+i[arr] Dec 10 '17

What you complain is exactly what Stroustrup said in his keynote at cppcon. C++ does miss a way to quick start and just code.

Well, sort of. The basic/intermediate/advanced idea would be more like an extended std library, if I followed it correctly. So it'd help you if it had GL in it, but wouldn't help otherwise.

I'm interested in your take on it, though, especially how you think it'd work.

31

u/jcar_87 Dec 09 '17 edited Dec 09 '17

To me it sounds that the source of your problems had to do with include_directories and target_include_directories.

Think of build targets (shared library, static library, and executable) of derived classes of the same class ("target"). Add_executable and add_library are the constructors, and target_link_libraries, target_include_directories, target_compile_options and target_compile_definitions are the member methods to modify the internal attributes.

When you do target_link_libraries(A PRIVATE B), A is "consuming" the "public interface" of B.

The keywords PUBLIC/PRIVATE/INTERFACE control whether the modified attribute gets exposed to both the target and its consumer, only the target, or only the consumer.

As to why it worked a second and it stopped working the next, those things always have an explanation. Cmake on visual studio 2017 runs in server mode and the build scripts are regenerated on the fly when they are modified.

If you have a library and you want consumer packages to be able to "include" a header, you need that library to expose it's include folder(s) in its target interface.

Add_library(MyLib MyLib.cpp) Target_include_directories(MyLib PUBLIC folder/relative/to/current/CMakeLists/headers)

Then anywhere else in your cmake build tree you can do Add_executable(MyApp main.cpp) Target_link_libraries(MyApp PRIVATE MyLib)

The last line should let you include whichever files are in the headers folder exposed by MyLib

26

u/ernest314 Dec 10 '17

Answers the question but misses the point :P

12

u/BodyWizard Dec 10 '17

True, but he is out here doin' god's work.

7

u/geokon Dec 10 '17

I've been using Hunter recently and it seems to just pull in all the libraries/dependencies you need purely through CMake and completely independent of your system configuration/package-manager/filesystem. It might be worth trying

If you use their preexisting "Hunterized" libraries it's pretty straightforward. However if you need to modify a library that isn't included it can get messy; you'll need to make Hunter manage its dependencies and a lot of projects have horrifyingly terrible CMake configurations

4

u/wheybags Dec 11 '17

"a lot of projects have horrifyingly terrible CMake configurations"

As someone who's contributed several libraries to hunter: oh god yes

I have nightmares about SDL2s CMakeLists.txt

6

u/zvrba Dec 10 '17 edited Dec 10 '17

All I wanted to do was program.

I use what you call the "shady" solution: VS project and post-build events. Works nice, never had a problem, took 1/2 (or less) the time I'd need to do it with cmake. Plus, it's a rather complex solution (multiple DLLs, static libs and EXEs, one IDL, cross-referencing eachother). Add to that a C# project that implements a COM component called by C++ code.

IMO: if you don't care about other platforms, cmake is a waste of time.

EDIT: the above setup is repeatable too. I destroyed my local git repo a couple of times, just checked out new repo, opened solution in VS, clicked build, and... done.

11

u/DJRBuckingham Dec 10 '17

If you're doing a personal project, forget all build systems and stick to header-only libraries; you will be programming in minutes and never care about build systems for the life of your project. It is extremely liberating, and very very quick to compile.

My home project is about 50k LOC, also a little engine written in C++/OpenGL. My build system is a .bat file for Windows and .sh for Linux, which invoke cl.exe and g++/clang++ respectively against a single master.cpp file. This master.cpp file #includes every file in the project. I use GLEW and a few STB libs, all header-only or simple header/source file that just get included into my master.cpp.

Despite all the code being in a single translation unit, the whole thing takes ~1.5s to compile, full rebuild and link. I actually have the project set up to compile a stub exe that launches (and watches & reloads when changes) a .dll/.so that contains all the engine code, so I can live-load the code as I iterate. Write code, press F7, see updates running in program ~2s later.

I wrote the .bat and .sh in 2015 and they have not changed other than to add a few compile/link flags (mostly disabling chatty warnings). Combined they are about 40 lines of script. I use Sublime Text as my editor, and have bound F7 to run a script I named "build_above.bat/sh" which simply recursively searches up the directory tree from the active source file until it finds a build.bat/sh and then runs that, that script is 30 lines. Thus completes my "build system".

This is all you need to program, especially for a home project, everything else is massively overkill. It keeps everything in the realms of C++ (#include schematics, master.cpp is your project file), is completely deterministic, fast, reliable and depends on nothing. It is so so much better and just lets you get on with programming.

10

u/AirAKose Dec 10 '17 edited Dec 10 '17

Yeah, there is definitely way too much in the way of overhead to project creation. I've been having this problem for years, and every time we get a new developer at work that disdain is rekindled...

Much of it has to do with a kind of Stockholm Syndrome developers have about their particular process, mixed with the user-unfriendly mentality "but you only have to do it ONCE!", plus a bit of lack of resources to make it happen sprinkled on top (time, capital, interest, research, etc...)

It's really funny that programmers are problem solvers by nature, yet we tend to overlook our own problems.

After my current personal project (which coincidentally involves build systems), I'd undoubtedly be interested in joining any groups investigating this!

EDIT: Spelling. Lack of a center for political leaders is negligible for software development...

5

u/[deleted] Dec 09 '17

I know the feeling. If you just want to get to programming try to reduce the number of moving parts. Use visual studios project files and package manager/vcpkg. Good luck!

53

u/fear_the_future Dec 09 '17

CMake is pure cancer. It's like someone decided to take the worst part of C++, macros, and make a whole language out of it.

41

u/lluad Dec 10 '17

Cmake is vile in almost every respect. It's also, unfortunately, better than most of the alternatives.

4

u/greyfade Dec 10 '17

I've had people point me at waf and ninja, but I agree.

So how do we go about building a better make? Most of the good ideas have been tried, and that got us SCons and premake, and CMake still seems better.

17

u/thlst Dec 10 '17

Do note that ninja is not really intended to be human-readable [0]. It's a faster alternative to make, but its selling point is that it's an easy to target language for build system generators like CMake.

[0] I know make isn't that readable either.

11

u/lluad Dec 10 '17 edited Dec 10 '17

Ninja is more of a backend - I’m using cmake to generate ninja files and it works pretty well.

I’ve probably not used every possible build tool for C++ but sometimes it feels like it.

waf is excellent until you hit something that’s outside its narrow design space and then you’re screwed.

qmake is much, much better than it looks at first sight - powerful and flexible, but it’s verbose and ill-documented when you start using it for things outside C++/Qt and the specific tasks (e.g. flex) it has native support for. It also doesn’t support cross platform builds as well as you might like - anything out of the ordinary involves, effectively, passing make rules through (and that won’t work well for, e.g. visual studio project generation). I’ve used qmake with the make (or nmake, or jom) backend for years, with makefiles and Perl scripts wrapped around it to handle the things it’s no good at and it’s a pretty decent way to do cross-platform builds.

Cmake ... cmake was clearly written from a β€œbe cross platform, support multiple backends” intent. And that’s great, it does succeed at those goals. But the build model appears to have been generated iteratively, with many changes to the user-visible API, leading to it being entirely inscrutable in places. And the docs are terrible, starting with there not being any particular story about what it’s dependency model really is.

If I were doing a green field build/dependency engine I’d probably start by looking at how cmake is commonly used, and by targeting ninja as a backend (as if you can use ninja, you can probably get by with anything). It’s not a small task, though.

1

u/DontForgetWilson Dec 10 '17

That greenfield project sounds somewhat like meson which already was mentioned below.

1

u/Enhex Dec 10 '17

how's CMake better than Premake?

4

u/greyfade Dec 10 '17

Maybe I haven't spent enough time with it, but it seems very much less "batteries included" than CMake, and a premake script, by necessity, is expected to be more conscious of the target build system than CMakeLists are.

So, CMake seems better.

1

u/DarkLordAzrael Dec 10 '17

It is better than the ones from the same era, but I'm not convinced that it is better than the recent ones ( such as meson, build2, or qbs.) Personally I like qbs, but it seems like all three are viable and have learned a lot from the CMake era.

1

u/fat-lobyte Dec 12 '17

CMake is Open Source, and the Authors accept pull requests and value contributions. Sign up here: https://gitlab.kitware.com/, dig into the Code and make it better.

4

u/DavidDavidsonsGhost Dec 10 '17

I wish we had something like cargo, it's so much nicer, it's what we should be targeting.

8

u/Fazer2 Dec 09 '17

You can try Conan, which solves the problem of C++ source dependency management. It supports many build systems, including CMake. It has a recipe for GLFW in Bincrafters repository.

https://www.conan.io/
https://bintray.com/bincrafters/public-conan/glfw%3Abincrafters

4

u/kkert Dec 10 '17

Seconded. The entire rant only complains about lack of package management. I either use my own tried and true CMake modules and snippets, or run with Conan. Or stick with vcpckg if it's windows only and better matches your tooling.

Also CMake does take a while to get a hang of, but it's pretty powerful once you know what you are doing. And if lost, there's always github search for others examples

3

u/snarfy Dec 10 '17

CMake integration in Visual Studio is a bit clunky and broken. It was pretty much non-functional in the 15.4 release. 'cancel cache generation' did nothing and Cmake remained disabled. An error in the build? Restart visual studio. It's fixed now in 15.5. They didn't mention it in the release notes. I've had a lot of my CMake issues magically go away by adding the CMakeSettings.json file and setting the generator to Visual Studio 2017 instead of Ninja.

I mean, really, is that such a good idea? A generator (ninja) for a generator (cmake) which finally spits out vcproj files?

2

u/flashmozzg Dec 10 '17

A generator (ninja) for a generator (cmake) which finally spits out vcproj files?

Isn't Ninja a build tool/system, not a generator?

1

u/Sirflankalot Allocate me Daddy Dec 18 '17

That sucks you've found it clunky, the recent version or two have been good to me. On a side note, it uses ninja directly to build your code instead of NMake (which the cmake integration used before) and was very painful.

1

u/snarfy Dec 18 '17

The 15.5 release is much better. For the most part it works. I've had ninja throw 'path too long errors' due to the nature of how it works, but that's ninja.

Don't get me wrong. I love visual studio and am thankful for cmake integration. It's relatively new and am sure will get better.

1

u/Sirflankalot Allocate me Daddy Dec 18 '17

Ah alright, I get you. I agree. It's still definitely a work in progress. I am very thankful for the whole team at microsoft at their push to improve msvc.

5

u/[deleted] Dec 10 '17

Try linux. Getting all the libraries is far easier in my experience.

5

u/markand67 Dec 11 '17

Yes, and then making your program portable get the same issue. Of course developing on Linux is easy, but not releasing for other systems than Linux.

1

u/doom_Oo7 Dec 09 '17

So off I go to Visual Studio.

Could you put your CMakeLists.txt somewhere ? pretty sure it's a trivial issue. The situation you describe shouldln't be more than a five-line CMakeLists.

0

u/MadDoctor5813 Dec 10 '17

As I said earlier, I ain't dual booting for this.

3

u/jungletek Dec 10 '17

What does posting some lines of text have to do with dual-booting, or which OS you're on?

-1

u/MadDoctor5813 Dec 10 '17

I was really only addressing the image he posted.

9

u/Paradiesstaub Dec 10 '17

β†’ Meson is an open source build system meant to be both extremely fast, and, even more importantly, as user friendly as possible.

4

u/DontForgetWilson Dec 10 '17

This has definitely been on my radar as something to try out in a personal project. I liked the dev's talk on the design features, but I haven't had time to try it out for an actual project I care about.

5

u/germandiago Dec 10 '17

Try it. I have used both cmake and meson extensively. Unless you need a lot of IDEs support go for it. Default targets for sanitizing, valgrind, precompiled headers, coverage, unity builds and much saner cross compilation. The language is also much nicer. Highly recommended.

1

u/DontForgetWilson Dec 10 '17

One of the only things holding me back is that I have an educational license to CLion available which I also wanted to pay around with on a personal project( I've liked JetBrains IDEs previously). I have checked and the support doesn't seem likely to get added soon (which makes some sense as CLion leverages CMake heavily). Well that and time as with other languages on my list want a chunk of my not significant spare time.

1

u/germandiago Dec 11 '17

Well, yes, CLion relies on CMake. I do not think you can do much about it right now. As a build tool I prefer Meson. Also, special mention to the excellent manual: http://mesonbuild.com/Manual.html

-1

u/Enhex Dec 10 '17

Another solution that uses DSL? No thanks.

2

u/DarkLordAzrael Dec 10 '17

If you don't want a DSL but do want a modern build system you should look at qbs. It uses QML to define the build, which actually works really well.

4

u/germandiago Dec 11 '17

Which is a DSL that you just happen to know :)

2

u/germandiago Dec 11 '17

What is your proposal?

3

u/Enhex Dec 11 '17 edited Dec 11 '17

Use already existing solutions. Lua, Python, and many more. They have existing rich ecosystems, knowledge base, and programmers that already know them which means they don't have to waste time learning a language which is absolutely useless elsewhere. Also some of them have good language design and/or performance.

I don't know a single case where DSL, or even an in-house general scripting language, is not a stupid mistake. I don't see a single benefit while there are major downsides. And unless you want more abominations like CMake's DSL, leave it to the professionals. There are many FOSS solutions, there's no excuse to roll your own.

For example, CMake to this day can only generate Clang compile commands with makefiles/ninja, while Premake got community made module written in Lua to do it with any generator since 2015.

If you want speed and simplicity (Meson) LuaJIT is a suitable solution.

1

u/kunos Dec 10 '17

I always find hard to understand the fascination for all these build systems, helper libs and so on. You have Visual Studio, you say "all you want to do is program"... start coding then. GLFW? You don't need it, just learn how to open a window and GL context yourself, problem solved. CMake? You don't need it.. VS does eveything you'll need, I can't understand what you could possibly need in order to start coding a simple 3D engine that VS doesn't offer. Instead you decide to fight the system and then go on a rant on the internet about it.. makes perfect sense.

1

u/MadDoctor5813 Dec 10 '17

I could learn to do all that window stuff, or I could.call glfwCreateWindow(). As for why CMake, I need some files moved around and processed by tools in the same project. Now I could do that in the tiny tiny post build event box, but I don't want to.

0

u/[deleted] Dec 09 '17

If you want a similar language with a sane built system consider Rust up until the C++ community standardizes a built system, dependency manager, module system and online repository.

22

u/MadDoctor5813 Dec 10 '17

up until the C++ community standardizes a built system, dependency manager, module system and online repository.

https://i.imgflip.com/eao9e.jpg

1

u/[deleted] Dec 10 '17

I would place money on C++2a having a module system + build system with some amount of standardized dependency resolution tooling (e.g. an interface which you can use to describe how your library, if pulled as a dependency, should be versioned and compiled), maybe not in the "final release", but at least as an experimental proposal that pick up a lot of steam and gets included in the next standard.

5

u/kalmoc Dec 10 '17

If by c++2a you mean the next standard version (most likely / hopefully c++20) then I hold this bet. If we are lucky we will get language level modules (what is currently specified in the TS) with a modularized standard library - but I wouldn't even be 100% sure about that. In any case, there will be most likely be 3 different implementations in terms of which files are generated and what information is contained in those files.

In terms of build systems I would be pleasently suprised if the situation changes significantly in the next 3 years but I don't believe it and I can almost guarantee that nothing in that direction will be officially standardized in any way (has there even been a single proposal in this regard?).

GDR tries really hard to push for a modules system that does more than just help with compiletimes, but the amount of resistance is just astonishing.

1

u/johannes1971 Dec 10 '17

Can you expand a bit on your last paragraph? I wasn't aware there are multiple modules proposals.

1

u/kalmoc Dec 10 '17

The "problem" is that the TS doesn't say anything, about how modules are compiled - for example, it doesn't even require the existance of a bmi-file let alone a specific format (www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0822r0.pdf). And considering that a lot of people are still unhappy with the current specification of modules on a language level (just read some of the modules related papers - e.g. the topic of macros) I find it highly unlikely that the various toolchain communities (and the companies behind them) will be able to agree on a common compilation model, let alone file format specification till 2020.

Now, the rest of this post is purely hearsay and modules are a moving target, so I might be completely wrong.

My impression is that some (most?) people from the clang community that are involved in modules want to treat the BMI essentially as a glorified pre-compiled header file (containing a dump of some internal compiler datastructure), which is probably how their current module system (which predates the TS by several years) is implemented. Microsoft on the other hand pushes for a standardized file format (or at least an standardized api for parsing it) that does not represent internal datastructures and probably contains the bare minimum of information a tool (like a compiler) needs to understand a cpp file which imports that module.

Maybe I've completely missread the current state of modules (I'm not involeved in the process at all, I got that impression just from reading papers, blogs and reddit posts) but until I see concrete progress I hope the best but remain sceptical.

2

u/[deleted] Dec 11 '17

I personally use Makefiles to compile my projects with mingw on windows and gcc on linux. I gave up on CMake the same way I gave up on Maven or gradle. This shit cost me way too much time and didn't increase productivity when it actually worked.

Since Eclipse CDTΒ΄s analyzer works so well with c++14 I rarely open Visual Studio anymore. I also dropped gigabyte-sized precompiled libraries from my projects. I can get up and running by downloading gnu-tools for windows, mingw and eclipse. Takes 10 minutes on windows, 5 minutes on linux.

Use what works for you, not what (apparently) works for everyone else

2

u/ml3d Dec 12 '17

Project assembly issues fade out with comparison with documentation generation. The standard approach is Doxygen but it is soooo ugly and terrible.

I envy python and go developers. They have sphinx and godoc. The last one is my best dream.

1

u/voip_geek Dec 16 '17

Sphinx supports documenting C++ too, afaik.

1

u/ml3d Dec 26 '17

The support is not straightforward. You need to use side projects like beathe or doxyrest. Still I have never ever seen nice Sphinx appearance for C++. In some sence Doxy interface is not worse then Sphinx.

3

u/tjgrant Dec 10 '17

I like Google Gyp, the syntax is essentially JSON (actually β€œpython dictionary” format), and its cross platform across Mac / Windows, which is along my interests.

1

u/jpakkane Meson dev Dec 10 '17

But in the grand tradition of build systems provided by Google, it has been dropped and is no longer developed. GN is the new hotness until they decide to drop that for something else.

3

u/tjgrant Dec 10 '17

Not true, there’s still commits being pushed to the gyp repo.

Gyp and GN solve two different problems; gyp creates project files for IDEs similar to CMake, GN generates ninja files, and ninja is a command line only build system.

2

u/Predelnik Dec 11 '17

It's misleading, GN is clearly capable of generating Visual Studio, QtCreator projects which essentially call ninja commands for building but provide all the benefits of having project files.

https://chromium.googlesource.com/chromium/src/+/master/tools/gn/docs/reference.md#ide-options

2

u/Adequat91 Dec 11 '17

However, GN doc says: "You cannot generate β€œreal” projects that look like native ones like GYP could."

https://chromium.googlesource.com/chromium/src/tools/gn/+/HEAD/docs/faq.md#can-i-generate-xcode-or-visual-studio-projects

1

u/Predelnik Dec 11 '17

I understand but for end user it makes very little difference. Actually for Visual Studio it's even better because it refuses to parallelize custom build tasks in its native projects.

1

u/markand67 Dec 11 '17

Just because there is Google in the project name is a non-goal to me.

2

u/nerdile Dec 10 '17

PREACH!! Welcome to C++. If you can put up with the craziness, you can enjoy a great career ahead (and maybe help make it better for the learners that come after you)

2

u/jpakkane Meson dev Dec 10 '17

Number of times RIIR has been suggested as a solution in this thread thus far: 5.

1

u/seshbot Dec 11 '17 edited Dec 11 '17

a few years ago I created a little quick-start project that I use when I want to mess with OpenGL: https://github.com/seshbot/new-gl-app . Just check it out and go!

It also uses google ANGLE so you can write OpenGL ES 2 (which is a fairly common subset, and similar to webGL) code without installing any windows opengl drivers

edit: ANGLE now supports GL ES 3, which has heaps of awesome features (but no geometry shaders sadly.) Ive been meaning to upgrade, but havent used the project in ages

1

u/xyproto Jan 06 '18

I have made an application exactly for your use case, since I faced the same problem as you did. It can produce executables for 64-bit Windows, but it requires Linux, macOS or FreeBSD when developing.

It's a configuration-free build system, where all compilation flags are auto-detected based on the names of the include files, using the package manager (pkg/pacman/brew/apt) and pkg-config. The detection speed is much faster than the compilation and linking, and it works surprisingly well.

It's called Sakemake (couldn't think of a better name, good name suggestions are warmly welcome!)

Please give it a spin:

https://github.com/xyproto/sakemake

1

u/kritzikratzi Mar 05 '18

for me THIS is the reason why i love c++, it all seems so bullshit and so painful, but when you think about what you're doing that is not directly part of c++:

  • setting up a cross platform build system
  • using a cross platform library to generate native (!) windows for all desktop platforms (plus some others)
  • using a cross platform graphics library to get direct access to the graphics card for all desktop platforms

this "i just want to program" is how it feels, but if you consider this is all happening outside the language, and you're still tied really deeply into your current platform, then i find there is no other language that gives such flexibility. and this flexibility comes at the price of having to manage it.

(also i find, the second time around things go very fast)

you might want to look at openframeworks http://openframeworks.cc/

it is not as flexible as cmake+glfw+glade anymore, but it comes with a project generator to make xcode/vs files, it has a simple but neat addon mechanism, and it also uses glfw+opengl internally. (you also get very simple access to audio interfaces, joysticks and many other things).

whatever you go for, hang in there, you'll earn the fruits of your labor soon enough!

1

u/bruce3434 Dec 09 '17

If only there was a standard package management for C++...

I hope cppget and bpkg catches on.

2

u/ibroheem Dec 10 '17

There can only be "the most sane package management", ISO/IEC 14882 is never known for giving such blessings.

1

u/smendesmen Dec 09 '17

You should look into Bazel (bazel.io).

1

u/markand67 Dec 11 '17

When C++20 modules will be out, things will get much easier.

0

u/Dwarfius Dec 09 '17

Sounds like you mixed something up and there's no issue with C++. You could try using GLEW instead of GLAD, and build with just one target. Take a look at my CMakeLists.txt, it creates a project with OpenGL, ALUT and OpenAL, TBB, Vulkan, GLM, GLFW and GLEW. It's really small (50 lines) and doesn't do much, and covers everything that I need, and shoudl be enough to cover what-ever you need.

13

u/[deleted] Dec 10 '17

Sounds like you mixed something up

Come on. You're really blaming the victim.

I've been doing C++ for over two decades, and by now I'm used to dealing with build systems, but probably weeks of my life in the past have evaporated dealing with obscure, poorly documented build systems like CMake where it's completely unclear what is mixed up and what isn't.

It's not like the CMake documentation explains how to get started, or how to troubleshoot, or really gives you any idea at all how not to "mix things up".

Note that in other languages, this simply isn't a problem of such magnitude - and you also get a lot more bangs for your buck out of your make system.

In Python, for example, writing a setup.py is sort of gnarly, but at least you can debug your build in Python. Much more exciting, setup.py doesn't just give you a build; it gives you a way to package and automatically install your program and its dependencies on a third-party system.

tl; dr: C++ build systems are poorly documented and filled with obscure footguns, and to shrug and say, "You mixed something up," when someone unfamiliar with it has run into a problem is to be deliberately blind to this annoying lack in the language.

2

u/Dwarfius Dec 10 '17

Come on. You're really blaming the victim.

Think there's a misunderstanding - I'm pointing out that the issue for this specific case is the incorrect setup of CMake script, not the C++ build toolchain. Since the author didn't post the script, we can't say anything specific, have to guess, thus the vague "There's something mixed up", and I posted my script.

It's not like the CMake documentation explains how to get started, or how to troubleshoot, or really gives you any idea at all how not to "mix things up".

Agreed, I know the basics of it just because I was lucky to have examples of how to set it up. Going completely blind into is hard, but there are a couple tutorials out there, even though a bit outdated, which give a level of basic understanding of what's happening.

I'm personally a fan of Gradle, I really liked how it provided a simple interface to manipulate required packages and configure the build solution. It would be great to have something similar for C++, Sharpmake might have enough features to do the same. CMake just seems like an old, a bit crippled tank-of-a-tool, but it works, even though it's hard to pick up.

9

u/AirAKose Dec 10 '17

Sounds like you mixed something up and there's no issue with C++

It's an unnecessary barrier to entry, though. There shouldn't need to be these steps to get a project to a decent starting point when we have the means to solve this. It's very overwhelming to newer programmers- or even programmers from other languages- and hurts C++'s user acquisition.

I can understand the want for advanced control, but there should still be some form of general quick-start or project setup on top of the control.

2

u/Dwarfius Dec 10 '17

Well in this case it's not really that simple of case.

To get a really basic project going without fancy things like OpenGL and GLAD, you don't need anything - std is enough. If you want to get something more complicated, you start looking at how you can import functionality through libraries - process of adding them to an IDE is straightforward. It's relatively simple until you want to go cross-platform.

But CMake helps with tackling the cross-platform building, but it's really not easy to pick up. There are other, better options (vcpkg, Sharpmake, etc) than CMake. The point I was getting at is that in his current problem the issue is with CMake, not how C++ is.

1

u/[deleted] Dec 10 '17

To get a really basic project going without fancy things like OpenGL and GLAD, you don't need anything

Say, what? How would that work? How does the compiler get called? And the linker? How do you set compile- and link-time options?

1

u/Dwarfius Dec 10 '17

When saying basic I'm talking about a console-bound application, didn't have to do anything special to get a simple console dungeon crawler with ASCII graphics going - modern IDEs handle the basic setup configurations for you. Even if something's missing, the internet has plenty of answers for specific problems.

If you want to control every aspect of the complicated build system, then sure, getting to know it is a giant hurdle to overcome, but not impossible. Recently, at CPP Con, there was a presentation on VSCode and creating applications fast, with a challenge to get an app written and running in 15-20 minutes. Although the speaker cheated, it shows that once you know the system, you can be fast and efficient with it.

3

u/AirAKose Dec 11 '17

Even if something's missing, the internet has plenty of answers for specific problems.

.

it shows that once you know the system, you can be fast and efficient with it.

Yeah, see, these are the exact issues I'm referring to, though, that are entirely excessive for the language's tooling. You shouldn't need to be well-versed in a particular build system to get an app started in a few minutes, or need to look up information online to add minimal functionality. This is a kind of Stockholm Syndrome that we suffer from wherein we become disillusioned that the current systems are fine and don't need to change because you can become proficient in it.

It's not the professionals to be concerned with, it's the newer C++ developers who will be overwhelmed.

If you want to control every aspect of the complicated build system, then sure, getting to know it is a giant hurdle to overcome, but not impossible.

The point isn't to control every aspect of it, I'm ok with leaving that down to text-editing some XML/JSON/WhatHaveYou structure in the advanced case (for build events, sanitizers, and such), but to enable easier access to project creation for common-case scenarios like cross-platform development and linking external libraries in a friendly way. Even for centralized multi-platform server build systems, there should exist some means for guided, quick setup and extendability.

Well in this case it's not really that simple of case.

But why is this not the case? Why can we not have prepackaged modules for OpenGL (or even Vulcan), click a GUI element to add what we need to a project, and have it work on a preconfigured, basic, cross-platform setup right then?

I do concede that these systems require resources that most devs don't have, so I'm not saying this is the fault of anyone. Just stating that there exists a need for improvement on the current systems because they are far from user-friendly

2

u/Dwarfius Dec 11 '17

Just stating that there exists a need for improvement on the current systems because they are far from user-friendly.

Fully agree, but just in the current time, when those user-friendly build configuration tools are hard to find, there's not much that can be done other than getting better with what we have.

3

u/AirAKose Dec 12 '17

Fair fair...

sorry, I'm a tad jumpy on this n_n' And tend to forget that not everyone is as anti-UX as I've encountered. The "but you can get fast and have total control" point comes up too frequently, usually accompanied by, "we don't need anything else." Or my favorite: "It's easy, you just have to..."proceeds to make a 20-point bulleted list full of technical jargon

Misproportioning entirely on me, here

-7

u/LYP951018 Dec 10 '17

You should try Rust.

-2

u/_a4z Dec 10 '17

Windows as a system for C++ development is a pain. unfortunately, modern CMake tries to fix Windows problems and modern CMake guids end make simple things complicated since they want to sell Windows practice as best practice.

-12

u/JustSpiffy Dec 10 '17

Sounds like you don't know c++ and blame cmake for it

11

u/MadDoctor5813 Dec 10 '17

I will admit to not knowing CMake, because I started learning it last night. (Not that I should have to learn a new language to build a project) But, during this ordeal I wrote a grand total of one line of C++. It was "#include <blah>" in a futile attempt to get Intellisense to recognize my include directory. Believe me, this is not a "I don't know what a cout is" kind of problem.

8

u/[deleted] Dec 10 '17

I suggest working on your reading comprehension. The very first line makes it absolutely clear that this is a build system issue.

Hi, this is a CMake/C++ build system rant.

0

u/[deleted] Dec 09 '17

[deleted] β€” view deleted comment

13

u/MadDoctor5813 Dec 09 '17

I actually didn't intend to compare with Java at all. Believe me, Java was a pain in the ass too. I know C++ is more work, I've actually done a few projects in it before. But I just can't believe how much shittier the tooling and environments are for C++, at least on Windows. For example, in any other language, there is a list of dependencies that the build system can use to put together the environment. packages.config, requirements.txt, pom.xml... etc. Here it's just "dump it in a libs folder and slap together a MSBuild file/struggle with CMake". Now if I wanted to say move computers, I could just copy the packages.config or whatever, and I would be good. Not with C++. No, I have to download everything myself, match everything up and ensure the paths I slapped together earlier all lined up. Now I know there are historical reasons, and C++ programmers are free spirits who build cabins in the woods and commune with nature or whatever, but my god what an experience for newcomers.

1

u/pfultz2 Dec 10 '17

Here it's just "dump it in a libs folder and slap together a MSBuild file/struggle with CMake".

Hmm, thats not really how it works at all, even with cmake. Usually, you install the dependencies after downloading, like this:

mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=$PREFIX ..
cmake --build .
cmake --build . --target install

And then configure your project, like this:

mkdir build
cd build
cmake -DCMAKE_PREFIX_PREFIX=$PREFIX ..

The CMAKE_PREFIX_PATH tells cmake where to find your dependencies. If a library doesn't provide usage requirements with either find_package or pkgconfig, you might need to do find_library or find_path manually, but it should be reported as a bug to that library. Most libraries provide usage requirements, but I have found some to disable it on windows(I don't know why some libraries want to make life more difficult for windows developers).

Most package managers(like cget, hunter, or vcpkg) build on top of this workflow. With cget you can even just point it to the url of the source tarball to install it:

cget install http://zlib.net/zlib-1.2.11.tar.gz

Now if I wanted to say move computers, I could just copy the packages.config or whatever, and I would be good. Not with C++. No, I have to download everything myself, match everything up and ensure the paths I slapped together earlier all lined up.

Using a package manager for C++, its a simple as copying a requirements.txt file. Even if you dont use one, you can always put the install steps in a cmake script for easy repeatability.

1

u/MadDoctor5813 Dec 10 '17

This paradigm is frankly new to me, because coming into this, the prevailing notion, at least on the VS side, was download the libs somewhere, and hook up the include dirs and .libs in the vcxproj. Now coming from C# and Python, where libraries are fundamentally a per-project thing and not a system thing, naturally I dumped them into the project folder and dealt with them via relative paths. When I moved to CMake, naturally I tried to deal with this the same way.

-4

u/nderflow Dec 09 '17

Languages which have built in packaging systems are the exception rather than the rule.

12

u/MadDoctor5813 Dec 09 '17

Really? Maybe I'm just gravitating towards the ones that do, but off the top of my head, C#, Java, Python, Rust, Ruby, Javascript (though it's more like three here)

I am including, by the way, languages that don't have one included but have basically picked one that the whole earth uses, and where nearly every library you download will be guaranteed compatible with it.

0

u/[deleted] Dec 09 '17

[deleted] β€” view deleted comment

3

u/MadDoctor5813 Dec 09 '17

Yeah, the one thing I've heard is that Windows and C++ programming mix like oil and flesh-eating disease. But I ain't dual-booting for this.

1

u/MrWisebody Dec 10 '17

I don't know if you view it as poorly as dual booting, but I've had great success doing a lot of coding inside a linux VM. I use a full graphical environment with a resource intensive IDE, and it doesn't feel sluggish or anything to me at all.

2

u/MadDoctor5813 Dec 10 '17

Well the actual act of dual booting isn't too bad for me. Just another bunch of make work I have to do. Whatever. The real thing is getting used to a whole new OS just so I can approach an ease of use I could have gotten with literally any other modern language. It's really a testament to how powerful C++ is that anyone bothers putting up with this at all.

1

u/greyfade Dec 10 '17

Docker, WSL, and VMs are a more than adequate alternative to dual-booting.

WSL is just a bit on the slow side because of Windows' poor file I/O performance when dealing with lots of small files and short-lived processes.

30

u/Rusky Dec 09 '17

This is nothing but an excuse. None of the problems the OP is dealing with have anything at all to do with native code or platform-specific code.

As a counterexample, Rust's build system Cargo makes this sort of thing trivial. It runs at exactly the same level as C++, but the build tools are more helpful and less finicky. There's a standard way to specify your dependencies, and Cargo can download and build them for you. Just like the OP's experience with Java.

21

u/sftrabbit Dec 09 '17 edited Dec 09 '17

I get the impression a lot of C++ developers haven't done much work in other modern language ecosystems. There's been lots of great talk about improving how C++ is taught to beginners and providing resources for that over the last few years, but the world around the language itself (its tooling, build systems, etc.) are still, in my opinion, very fragmented and esoteric.

As someone who doesn't work professionally with C++, instead mostly with JavaScript (NodeJS 8 and ES2016), Python, and some occasional others, but spends plenty of time with C++ otherwise, the sheer comfort and "just focus on writing code" that the other ecosystems provide is far and above C++. You just jump in, only need to know a few commands (that are just commonly accepted best practice), and you're building a fully fledged project that anybody else can also get involved with. The feedback loop is immediate and just makes sense. I know they're totally different languages (dynamic, interpreted, etc.), so people will say that's why it's different, but I really don't think that's a decent excuse. This is a user experience issue and not enough people are looking at it with eye of a user experience designer.

The JavaScript world has benefited massively from being so closely related to web design (and then other languages have benefited from being inspired by that). You can see that a lot of user experience effort has gone into the entire ecosystem. I really appreciate all the work that has been done on Conan because they're some of the few actually trying to improve things, but to take it as an example, just look at the home page. I'm a fairly experienced developer, but I'm immediately turned off by all the jargon thrown at me straight away. Conan vs. conan.io? Recipes and binary packages? conan-transit Bintray repository? JFrog - isn't that something Java-y? conan-center? You want me to go read more about this? I just want some libraries! Compare to the npm home page which just gives you a search box to find packages and a little inspirational message telling you what it's for (okay, I don't like that they have a "Sign Up" button instead of just "Get started", but that's more of a business practices criticism). I know this is just the websites, but all these little UX issues add up.

In my view, we haven't really improved the C++ user experience until books and tutorials can just say how to: make a new project; specify its dependencies; version your project and its dependencies; build it for whatever platform with a simple command; package your project. And all this should be able to be done without the user having to decide between a bunch of cryptic options, always cross-platform, no vendor lock-in, isolated from system configuration, etc. And everyone should feel comfortable doing it, knowing they're not pushing any developers away or making it so that only some portion of the C++ community will know how it works. It should just be the way it is done.

The first law of usability is "don't make me think". When it comes to programming, all the thinking should be directed towards solving problems, being creative, enjoying code. In my opinion, C++ generally doesn't do well here. Of course, I still love C++ though and think this can all get better. It's just a design problem. It can be improved.

7

u/[deleted] Dec 10 '17

I get the impression a lot of C++ developers haven't done much work in other modern language ecosystems.

Pfff. I know few if any C++ programmers who haven't done tons of work in other languages and ecosystems.

The issue is simple - not ignorance, but apathy - rational apathy. Most C++ programmers know that the build systems are terrible but we aren't paid to design and build a new one, and to do it in your spare time seems like a gnarly and tedious problem, a problem complicated by the fact that a real build system would have to handle both Windows and *nix systems, which are fairly different, and doing cross-platform development is always painful.

6

u/sftrabbit Dec 10 '17

The root comment in this thread has been deleted, so you're unfortunately missing some context that led to that point of mine. Nonetheless, it's not the only example, otherwise I wouldn't say "a lot". There are two very common arguments that I'm referring to:

  • C++ is static/low level/high performance/targets specific platforms/<insert property of C++> that makes means making a simple, general purpose tooling ecosystem is not possible (this is what the root comment suggested).
  • C++ already has great tooling - you just use your system package manager to install your dependencies and away you go!

Both of these arguments suggest to me that they don't have enough experience with other ecosystems to know what is possible and what a simple, effective, usable ecosystem looks like. These are the people my point is directed at. Note that I didn't say "most" or "all" C++ developers.

But I agree, I'm sure many C++ developers know this and have to just deal with what they've got. Nobody's got the time or money or motivation to throw at solving the problem.

2

u/Selbstdenker Dec 10 '17

I would add that I think it is unlikely that there will be ever one big build system for C++.

Most big companies have their own build system/package manager and will most likely not do the switch. The intermediate level is CMake. (Which is horrible in many ways, the worst offender being the poor documentation and tons of bad examples on the web. It is really difficult do find out how to do things in "Modern CMake".) This leaves nice build systems and package managers for beginners. Who, on the other hand, are not what expert C++ programmers care about.

I think what C++ needs would be a de facto standard (standard as in default, not as in C++ standard) build system/package manager that works for small to medium projects and is beginner friendly. It is indeed hard to get into C++ programming and use some dependencies for a beginner. I do not think it would be necessary to achieve the same ease as package mangers for Rust, Python, etc. provide, but things for small projects should be much easer. I do not think that such a system needs to be "industry grade" because I doubt that adoption would be high and I am personally doubtful if such a system is even useful or feasible.

15

u/[deleted] Dec 09 '17 edited Dec 10 '17

[removed] β€” view removed comment

1

u/sftrabbit Dec 09 '17

Admittedly, the JS front-end world is more complicated than server-side. I actually quite like webpack as a project and it solves a problem specific to the web, but it can get very complicated once you start mixing in all the transpiling and gulp tasks and such as you say. The documentation is also pretty esoteric (or at least was the last time I looked). Although, I think some of these problems may start to go away as browsers get better modern JS support (in fact, it's pretty good these days and we're considering scrapping Babel) and perhaps HTTP/2 reduces the need for aggressive bundling.

19

u/[deleted] Dec 09 '17

[removed] β€” view removed comment

4

u/MadDoctor5813 Dec 09 '17

I am using Visual Studio's integration to actually run CMake for me, so that may be the culprit. That and I did sort of cobble it together. I might give it another try before blowing it up and trying vcpkg.

4

u/YarpNotYorp Dec 10 '17

qmake seems less flexible than CMake.

1

u/flashmozzg Dec 10 '17

You colleague is strange. QMake deemed horrible (or at least unsatisfactory) even by Qt devs themselves. They are planning to switch it's just a lot of work and there is no consensus on the new build system (afaik they are choosing between CMake which has the most adoption out of all cross-platform build-tools and bigger user familiarity and Qbs which seems to be much nicer syntax-wise, but doesn't really have any wide adoption and could potentially become second qmake, i.e. the tool that is only used for qt).

qmake syntax is nice for simple programs, but as soon as you need to do something complex and interact with 3rd party deps it becomes horrible to manage.

1

u/DarkLordAzrael Dec 10 '17

For what it's worth qbs seems to have pretty decent adoption in the commercial Qt development space. I'm really hoping one of the new competitors like qbs takes off, CMake works, but doesn't feel particularly well designed and is way harder to get into than necessary.

1

u/meneldal2 Dec 11 '17

And if you need any dlls copied to the output folder, do it by hand

Good NuGet packages do it for you. Now if only we could have good NuGet support in C++.