tags:

views:

246

answers:

2

I want to disallow people from cluttering our source tree with generated CMake files... and, more importantly, disallow them from stepping on existing Makefiles that are not part of the same build process we're using CMake for. (best not to ask)

The way I have come up with to do this is to have a few lines at the top of my CMakeLists.txt, as follows:

if("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
   message(SEND_ERROR "In-source builds are not allowed.")
endif("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")

However, doing it this way seems too verbose. Additionally, if I try an in-source build it still creates the the CMakeFiles/ directory, and the CMakeCache.txt file in the source tree before the error is thrown.

Am I missing a better way to do this?

+2  A: 

I think I like your way. The cmake mailing list does a good job at answering these types of questions.

As a side note: you could create a "cmake" executable file in the directory which fails. Depending on whether or not "." is in their path (on linux). You could even symlink /bin/false.

In windows, I am not sure if a file in your current directory is found first or not.

Juan
Good idea; I'll interpret that as putting something on the $PATH that will intercept the call to cmake - or simply a separate script that will wrap it. Or maybe a standard alias. Unless there is a 'native' way to do this in cmake I think that's the way to go. And yes, I believe on Windows '.' is implicitly on the $PATH; on UNIX it is not, but we could always put a cmake wrapper somewhere else in the $PATH.
Mike
What sort of nutter has . on their path?
Draemon
A: 

Just make the directory read-only by the people/processes doing the builds. Have a separate process that checks out to the directory from source control (you are using source control, right?), then makes it read-only.

Harper Shelby
Thanks for the answer. Unfortunately, because of the way our source control and system works, it would be impractical to do it this way. I was looking for a more general solution.
Mike