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

build artifacts in source directory #133

Open
mwoehlke-kitware opened this issue Sep 7, 2016 · 6 comments
Open

build artifacts in source directory #133

mwoehlke-kitware opened this issue Sep 7, 2016 · 6 comments
Labels

Comments

@mwoehlke-kitware
Copy link

It appears that the built libraries get written to the source directory. Please don't do that; build artifacts belong in the build directory.

@ahornung
Copy link
Member

Arguably, the compilation results are placed in bin and lib alongside the source directories in the main project root, whereas the build directory contains temporary artifacts only. This is common in quite a few projects and provides a re-usable project layout similar to an install space.

Do you have a specific case in mind where this is problematic?

@mwoehlke-kitware
Copy link
Author

Do you have a specific case in mind where this is problematic?

It prevents thoroughly nuking a build by simply removing the build directory; CMake users tend to expect this to work. Multiple build trees from a single source will be horribly broken. Also, it grossly violates Standard Practice. (In general, it should be possible to build a CMake project with the source in a read-only mount point. Note also that it is "source directory", singular, i.e. the root of the git clone, which usually matches CMAKE_SOURCE_DIR.)

This is common in quite a few projects and provides a re-usable project layout similar to an install space.

Can you show me another project that does this? I've seen quite a few projects using CMake, and I can't think of a single one besides octomap that forces its build artifacts to be in the source tree in this manner. (I'm ignoring ones using ExternalProject in bad ways, but even those are few.)

To be clear: the problem isn't putting all the libraries in lib; that is moderately common and perfectly acceptable. The problem is putting lib in the source tree. It belongs in the build tree.

@ahornung
Copy link
Member

The projects that I had in mind were not necessarily CMake projects, and the layout originates from a time when building completely in-source was common so maybe that's an explanation.

All basic instructions I've come across actually tell you to create build in the main source tree (aka mkdir build; cd build; cmake ..; make) and then call this an out-of-source build. But is the build directory then not also contained in the source?

Your scenarios all make sense to support, so the change is best planned for the next major release. Could you provide a PR with a suggestion?

@mwoehlke-kitware
Copy link
Author

The projects that I had in mind were not necessarily CMake projects, and the layout originates from a time when building completely in-source was common so maybe that's an explanation.

Sounds plausible. Most of the problems I think can be fixed by using CMAKE_[CURRENT_]BINARY_DIR instead of CMAKE_[CURRENT_]SOURCE_DIR when specifying locations of build artifacts.

All basic instructions I've come across actually tell you to create build in the main source tree (aka mkdir build; cd build; cmake ..; make) and then call this an out-of-source build. But is the build directory then not also contained in the source?

In some technical sense, yes... but all build artifacts should still be contained within the build directory. (This matters when you instead create e.g. build-debug, build-release, etc.) Note that the use cases I mentioned previously all work with this pattern.

Also, those are typical "lazy" instructions; not that there is anything wrong with them, but there is no requirement that the build directory be a subdirectory of the source directory. Personally, I keep sources and builds about six levels deep in the FS, with only the first two in common. (When possible, they're on different physical drives, for performance reasons.)

IOW, this pattern is just as valid:

$ git clone some/project src
$ mkdir build && cd build
$ cmake ../src

@ahornung
Copy link
Member

Do you have a concrete proposal for a change as PR? I'm preparing a new release and now would be a good time to change things.

xaedes added a commit to xaedes/octomap that referenced this issue Jan 11, 2019
Use CMAKE_BINARY_DIR instead of CMAKE_SOURCE_DIR to specify output directories.
See OctoMap#133
@ahornung ahornung added the CMake label Dec 4, 2019
@ahornung
Copy link
Member

ahornung commented Dec 4, 2019

PR is here: #270

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

No branches or pull requests

2 participants