[Cmake] out of source builds

Brad King brad.king at kitware.com
Mon Aug 2 16:53:39 EDT 2004


David Somers wrote:
> I'm trying to get Cmake to do out of source builds with MSVC6.
[snip]
> I'm probably doing something fundamentally wrong, so any help appreciated.

Doing an out-of-source build requires no special support in your 
CMakeLists.txt code.  They are a fundamental feature of CMake.  When you 
run CMakeSetup.exe, the dialog has two entries:

"Where is the source:" and "Where to build the binaries:"

Just put the source tree in the first entry and whatever other directory 
you want in the second entry.  The source tree will be left completely 
untouched and the build tree will have all the intermediate files.

EXECUTABLE_OUTPUT_PATH just puts all the executable targets into a 
single directory instead of each executable being put in the build tree 
path corresponding to the source tree path of the CMakeLists.txt file 
that contained the ADD_EXECUTABLE command.

CMAKE_CURRENT_BINARY_DIR is a read-only variable for the path to the 
directory containing the CMakeLists.txt file that evaluates the variable.

> (also, I tried using
> SET_TARGET_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/preproc.c PROPERTIES
> DEFINE_SYMBOL "_POSIX_" ) to set a preprocessor definition on a specific
> file, but that seems not to work).

preproc.c is a source file, not a target.  Use 
SET_SOURCE_FILES_PROPERTIES with the "COMPILE_FLAGS" property to add a 
"-D_POSIX_" flag.

-Brad


More information about the Cmake mailing list