[CMake] Change the default output path in Visual Studio

Nils Gladitz nilsgladitz at gmail.com
Mon Mar 30 09:46:30 EDT 2015


On 03/30/2015 03:36 PM, Petr Bena wrote:
> Hi Nils,
>
> Great! Could you please give me some mininal example and perhaps add
> it to documentation page which is now kind of vague? From what is
> written there, I suppose that this variable changes the runtime output
> directory, but for all targets since it's set and until it's changed?
>
> eg. if I have huge CMakeLists.txt file that includes other CMake files
> using add_subdirectory I would wrap all add_subdirectory directives
> with change to this variable? like:
>
> RUNTIME_OUTPUT_DIRECTORY("extensions/")
> add_subdirectory("extension/ext1")
> # Now I should reset it back to what it was?
> RUNTIME_OUTPUT_DIRECTORY("WHAT DO I PUT HERE??")

CMAKE_RUNTIME_OUTPUT_DIRECTORY is a variable.

You can set it with e.g.:
   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

You could unset it again with e.g.
   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY)

Regular cmake variables are inherited into sub-directories.

CMAKE_RUNTIME_OUTPUT_DIRECTORY is read at every add_executable() and 
add_library() call to initialize the RUNTIME_OUTPUT_DIRECTORY_PROPERTY 
[1] of the newly created target.

So to revise your example the following should work (assuming the 
sub-directory itself does not override the defaults):

   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY 
${CMAKE_CURRENT_BINARY_DIR}/extensions)

   add_subdirectory(extension/ext1)

   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY)

Nils

[1] www.cmake.org/cmake/help/v3.2/prop_tgt/RUNTIME_OUTPUT_DIRECTORY.html




More information about the CMake mailing list