[CMake] Select CMAKE_LIBRARY_OUTPUT_DIRECTORY_<CONFIG> in a CMakeLists.txt script

David Cole david.cole at kitware.com
Wed Mar 2 06:40:26 EST 2011


On Wed, Mar 2, 2011 at 3:31 AM, Rolf Eike Beer <eike at sf-mail.de> wrote:
>
> > I am defining separate output paths for different configurations:
> >
> >   CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG    = bin/win32/dbg
> >   CMAKE_RUN TIME_OUTPUT_DIRECTORY_RELEASE = bin/win32/opt
> >
> >   CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG    = lib/win32/dbg
> >   CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE  = lib/win32/opt
> >
> >   CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG    = bin/win32/dbg
> >   CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE  = bin/win32/opt
> >
> > And in Visual Studio the CMake command add_library() command does a fine
> > job of choosing between CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG for the Debug
> > configuration, and CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE for the Release
> > configuration.
> >
> > I can see how I might use CMAKE_CFG_INTDIR to get the IDE configuration,
> > but its value is "Debug" or "Release".  If I were to use
> > "lib/win32/${CMAKE_CFG_INTDIR}", I would get "lib/win32/Debug" or
> > "lib/win32/Release", which is incorrect.
> >
> > I can imagine some sort of non-portable solution, but I am wondering if
> > there is a standard approach, or an example from which I might draw
> > inspiration.
> >
> > My application is compiling C# within add_custom_command().
>
> Are you searching something like
> ${CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CMAKE_CFG_INTDIR}}?
>
> Eike
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake


${CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CMAKE_CFG_INTDIR}} will not work.

CMAKE_CFG_INDIR evaluates to a string like "$(Configuration)" or
"$(IntDir)" or "." -- it evaluates to something that evaluates at
build time... Not something you can use as a double de-reference of a
CMake variable at configure time.

With CMake 2.8.4 and later, you can use "generator expressions" with
add_custom_command to get the target directory of some add_library
target, and use that as an argument in your custom command. (This
assumes that you do have at least one library/executable target that
does go to the right directories, which you can reference...)

Online docs for add_custom_command, search page for "$<TARGET_FILE_DIR:tgt>":
http://cmake.org/cmake/help/cmake-2-8-docs.html#command:add_custom_command

HTH,
David


More information about the CMake mailing list