# How to specify build output directory path?

**URL:** https://discourse.cmake.org/t/how-to-specify-build-output-directory-path/202
**Category:** Code
**Created:** [November 14, 2019, 8:59am UTC](https://discourse.cmake.org/t/how-to-specify-build-output-directory-path/202 "2019-11-14T08:59:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [November 14, 2019, 8:59am UTC](https://discourse.cmake.org/t/how-to-specify-build-output-directory-path/202/1 "2019-11-14T08:59:56Z")

</div>

(Copied from mail list where it is currently unanswered)

Hi

I am rather confused about how to specify the output directory. I am working on Windows with the Ninja generator and Microsoft toolset. My default build type is Debug. I am building a library and an executable:

```
add_subdirectory(../Kernel Kernel)
add_executable(MyExe ../Kernel/main.cpp)

```

The resulting directory structure, after a build, is:

```
Kernel <== source files
    |--CMakeLists.txt
CMake
    |--CMakeLists.txt
    |-- build_msvc
            |--Kernel <== library goes here
            |--debug <== exe goes here

```

I want the Kernel library to go into the ‘debug’ folder (where the exe is correctly being put).

$CMAKE\_RUNTIME\_OUTPUT\_DIRECTORY and $RUNTIME\_OUTPUT\_DIRECTORY are undefined.

How would I achieve this?

Which variable holds the exe output path: build\_msvc/debug?

Best regards  
David

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [November 14, 2019, 10:00am UTC](https://discourse.cmake.org/t/how-to-specify-build-output-directory-path/202/2 "2019-11-14T10:00:52Z")

</div>

I tried to reproduce your setup by creating the following files and folders:

 ![image](https://discourse.cmake.org/uploads/default/original/1X/c9337307497f5fb86960545c01e9c5ba283cf5e3.png)

Then I opened “x64 Native Tools Command Prompt for VS 2017”, changed my working directory to `topic-202/CMake/build_msvc/`, and ran:

```cmake
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=debug
cmake --build .

```

I now have `MyExe.exe` inside `build_msvc/`, and `Kernel.lib` inside `build_msvc/Kernel/`.  
I don’t have any `debug` folder, so I can’t help you with “Which variable holds the exe output path: build\_msvc/debug?”

Please let me know what I should change in my setup to be able to reproduce properly.

---

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [November 14, 2019, 11:28am UTC](https://discourse.cmake.org/t/how-to-specify-build-output-directory-path/202/3 "2019-11-14T11:28:34Z")

</div>

Thanks for testing my code. This morning I reran mine and no debug folder was generated - just as you said.

My code previously had:

```
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/debug) 

```

but I have commented that out. I wonder if it was cached in some way. Anyway you have answered my question. Thanks.
