How to specify build output directory path?

(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

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

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

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.

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.