[CMake] Trying to find a directory

Eric Noulard eric.noulard at gmail.com
Fri Nov 24 04:04:57 EST 2006


2006/11/24, Timo Rumland <cr at olympclan.de>:
> Hello,
>
> > Not sure to understand your need
> > but did you look at:
> >
> > IF(EXISTS file-name)
> > IF(EXISTS directory-name)
> > or
> > FILE(RELATIVE_PATH variable directory file)
> > or
> > GET_FILENAME_COMPONENT
>
> yes I did. Perhaps I have not explained my problem properly.
>
> My binary dir is "c:/project/test/buildfiles", the cmake variable ${PROJECT_BINARY_DIR} contains that automatically after I use the "PROJECT" command.
>
> Now I want to set the path where to build the project binaries, in my case it is "c:/project/test/bin", BUT I never know the beginning of that path ("c:/project/test"), because I can't say where the user is on his system.

Now I understand.
Setting the directory where CMake will put binary is a matter of setting

LIBRARY_OUTPUT_PATH for library target  (cf ADD_LIBRARY)
and
EXECUTABLE_OUTPUT_PATH for executable target (cf ADD_EXECUTABLE)

so you may do:

SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../bin)

>
> So I need to get the relative path "../bin" from "[whatever]/buildfiles" resulting in "[whatever]/bin".

However I wouldn't do that at all, since trying to put files OUT OF
the build tree
the user has chosen may produce REALLY UNWANTED side effects.

For example the user may have write access in ${PROJECT_BINARY_DIR}
but not in the parent ${PROJECT_BINARY_DIR}/..

If you want all the binaries to be generated in the same place
I would suggest you to override EXECUTABLE_OUTPUT_PATH
with a path within ${PROJECT_BINARY_DIR}.


-- 
Erk


More information about the CMake mailing list