[CMake] Restrictions on where a binary can be put?

Andreas Pakulat apaku at gmx.de
Sun Jan 9 14:35:13 EST 2011


On 09.01.11 14:24:16, Michael Hertling wrote:
> On 01/09/2011 12:58 PM, Andreas Pakulat wrote:
> > Hi,
> > 
> > I'm having a bit of a problem here changing the runtime output directory
> > for a binary. Its an executable target named 'setup' and I'd like to put it
> > into the top-level directory. Unfortunately it always ends up in the bin/
> > directory, which is what CMAKE_RUNTIME_OUTPUT_DIRECTORY is being set to.
> > 
> > I'm using
> >     set_target_properties( setup PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} )
> > after creating the target currently, which should work as far as I can see
> > from the documentation. Are there maybe any restrictions on what the
> > directory may be or what targets can be put there?
> > 
> > If not, any suggestions how to debug this? I can see that the build.make
> > does already have the rule setup for putting the binary into bin/, so it
> > must be going wrong somewhere in the generation stage, but a simple cmake
> > --trace doesn't show up anything suspicious. Is there a switch to follow
> > the steps that cmake does during makefile-generation?
> 
> Could you provide a minimal but complete example?

Might take a bit, my first try actually works as expected, so I'll need
to take the real code and reduce it.

> Currently, I can't
> confirm this issue, i.e. the RUNTIME_OUTPUT_DIRECTORY property seems
> to take precedence over the CMAKE_RUNTIME_OUTPUT_DIRECTORY variable.
> Nevertheless, if RUNTIME_OUTPUT_DIRECTORY is set to CMAKE_BINARY_DIR
> from within a subdirectory, i.e. CMAKE_CURRENT_BINARY_DIR isn't equal
> to CMAKE_BINARY_DIR, I can see quite strange things happening:
> 
> # CMakeLists.txt:
> CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
> PROJECT(ROD C)
> ADD_SUBDIRECTORY(main)
> 
> # main/CMakeLists.txt:
> FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/main.c
>     "int main(void){return 0;}\n"
> )
> ADD_EXECUTABLE(main ${CMAKE_CURRENT_BINARY_DIR}/main.c)
> SET_TARGET_PROPERTIES(main PROPERTIES
>     RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
> )
> 
> After CMaking from within an empty directory, building fails with:
> 
> .../gcc CMakeFiles/main.dir/main.c.o -o . -rdynamic
> .../ld: cannot open output file .: Is a directory
> 
> If the RUNTIME_OUTPUT_DIRECTORY property is set to CMAKE_BINARY_DIR/bin,
> e.g., everything works as expected, i.e. the executable gets written to
> CMAKE_BINARY_DIR/bin. Also, no such problem occurs from within the top-
> level directory, i.e. CMAKE_CURRENT_BINARY_DIR == CMAKE_BINARY_DIR.
> Perhaps, these two phenomena are related?

Hmm, for me everything works fine (see attached project) here when
setting the output-dir to cmake-binary-dir.

Andreas

-- 
Green light in A.M. for new projects.  Red light in P.M. for traffic tickets.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cmake_tst1.tar.gz
Type: application/octet-stream
Size: 439 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110109/1d8d5598/attachment.obj>


More information about the CMake mailing list