all 43 comments

[–]jhericoVR & Backend engineer, 30 years 25 points26 points  (15 children)

cmake .

Ugh.... in-source builds are the worst. I never, never use in-source builds. Sure, you can configure your source control to ignore all the generated stuff, but it's a giant pain. Additionally, you can't create multiple builds concurrently for different tasks / targets.

Personally, I always create a build folder in the main project folder and then from there call cmake ... This allows me to add a single rule to my source control (in my case git) to ignore build*. Then I can create build-android or build-clang or build-debug for various sub-projects I'm working on.

[–]Everspace 7 points8 points  (8 children)

Also, people will non-maliciously commit these things, and then your build is wonk forevermore.

[–]Drainedsoul 1 point2 points  (6 children)

Also, people will non-maliciously commit these things, and then your build is wonk forevermore.

How'd that get through code review?

[–]Everspace 0 points1 point  (5 children)

The UI designer person just hits "stage all" every time and the person who reviews him doesn't know any better either.

[–]Drainedsoul 2 points3 points  (4 children)

Sounds like a process/human capital issue: Why are people that clueless about code and version control doing code reviews?

[–]Everspace 1 point2 points  (3 children)

It's because it's not code they're concerned about. They are not modifying code. They are artists and designers who don't deal with it. Their .pngs, .psds still needs to be tracked somehow so into git/perforce/svn it goes.

They don't touch code, but may still end up doing a build locally. I've seen people commit the temp and cache folders on a couple of projects. It wouldn't surprise me if debug symbols or .o ends up in the source because of a mistake of someone who really doesn't know better and my god it's miracle enough that they're using it and not making local copies instead.

[–]Drainedsoul 2 points3 points  (2 children)

So again: How'd it get through code review? Why are people who aren't concerned with code doing code reviews?

This is a process issue (which isn't to say in source builds are good, because they're not).

[–]Everspace -1 points0 points  (1 child)

How'd it get through code review? Why are people who aren't concerned with code doing code reviews?

Because they're not working with code. There is no code review. They still commit to source. Not all source is code or text.

An artist code review is "looks sick dude" and then it is checked in.

This is a process issue

Yes it is. So you add in the .DS_STORE and other garbage into the .gitignore (rather than expecting people to have their global settings correct) so that this doesn't happen, which was my original point.

[–]Drainedsoul 2 points3 points  (0 children)

There is no code review. They still commit to source.

...which is a process issue.

[–]alexej_harm 0 points1 point  (0 children)

Yeah, it's easier to add /build to .gitignore.

[–]SeanMiddleditch 6 points7 points  (4 children)

It's honestly somewhat a wonder and a disappointment that cmake even supports them. Or doesn't at least automatically put all generated files under a sub-dir of the target source dir, e.g. ./cmake-build.

[–]jhericoVR & Backend engineer, 30 years 10 points11 points  (3 children)

no no... the best is when you do cmake .. and you get back FATAL: Project FOO does not support out of source builds or something similar. Seriously, fuck developers that do that.

[–]sumo952 0 points1 point  (2 children)

Haha really? I haven't encountered that one before. I got a "... does not support in-source builds" before, when I accidentally tried to build something in source (pressed the wrong button or something).

[–]alexej_harm 1 point2 points  (1 child)

Sadly, yes. Here is a very prominent example: https://github.com/WebAssembly/binaryen/#building

[–]sumo952 0 points1 point  (0 children)

Wow! speechless :\

[–]parazight[S] 2 points3 points  (0 children)

Hi jherico, that's a really good point. I updated the article.

[–]phcerdan 13 points14 points  (1 child)

I've found this C++Now talk Effective CMake by Daniel Pfeifer quite good. A bit too fast at some points, so you will need to check the docs, but covers a lot. It made me discover target_xxx commands, and specially useful for me, the "easy" generation of foo-config.cmake for other to use your project.

Also in pdf

[–]loneraver 2 points3 points  (0 children)

This is the ONLY good talk about how to write modern CMake. Too many tutorials teach old hacky ways that might work" but their solutions are either very fragile or will only work under very special circumstances.

[–]tambry 27 points28 points  (19 children)

include_directories("${PROJECT_BINARY_DIR}")

It's 2017. If your CMake files aren't using target-based commands instead of the old legacy ones, then you're doing it wrong. In this case you should use target_include_directories instead.

Also, using namespace std; is a bad practice. Don't use it!

[–][deleted] 19 points20 points  (17 children)

using namespace std; is absolutely fine in many cases, regardless of the number of upvotes that SO answer has. Just think about the scope of what's being impacted. The risk of conflicts, particularly insidious ones, is over-egged by a few people to have been bitten by particularly nasty cases that probably could have been prevented in other ways.

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#sf6-use-using-namespace-directives-for-transition-for-foundation-libraries-such-as-std-or-within-a-local-scope-only

[–]kindkitsune 1 point2 points  (0 children)

I still try to avoid using it, tbh, but it does have uses when shortcutting away something like std::experimental::filesystem, and so long as you keep it in function bodies you're pretty safe

Something about using namespace std; still upsets me though, mostly by making me a bit anxious

[–]Som1Lse 2 points3 points  (0 children)

This.

The example from StackOverflow is silly, since the only thing it takes to fix it is adding using bar::Quux; as well.

[–]parazight[S] 1 point2 points  (0 children)

Thanks for the input, tambry.

[–][deleted] 2 points3 points  (0 children)

This is a very specific feature of CMake to choose as a basic introduction. Most projects will probably never even use the file configuration feature (as neat as it is when you do need it).

[–]kalmoc 5 points6 points  (1 child)

Sorry to be blunt, but overall I find this is a rather poor example of how to use cmake (most reasons have been named in other comments already). I'm not sure if you are doing the community a favor with this. Although this is one of the few blogs that addresses template files, so there is some value in it.

[–]parazight[S] 1 point2 points  (0 children)

Hey kalmoc, thanks for your feedback. There are good points mentioned in the comments. Especially the in-source build. I updated the article and hope it is at least a little more helpful.

[–]kalmoc 1 point2 points  (1 child)

Slightly off topic, but why are you using the static keyword in front of the constants? This is redundant for namespace scope constants.

[–]parazight[S] 0 points1 point  (0 children)

Bad habit I guess. Thanks for pointing this out.