<div dir="ltr">Thanks for the help I have received in the past few days. I am making incremental improvements to my CMake project and have a new challenge.  I am running CMake 3.13 on Centos 7.6, targeting make.  My CMake file successfully builds debug or release targets and puts the executable in an out-of-source build directory.  I have added debug and release make targets so I can execute 'make debug' etc.<div><br></div><div>I now want to support separate target directories: build/debug and build/release.  I've shown my CMakeLists.txt below. So far I've just added an attempt to support build/debug:</div><div><br></div><div>if (CMAKE_BUILD_TYPE EQUAL "DEBUG")<br>    message("debug mode")<br>    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/debug)<br>endif (CMAKE_BUILD_TYPE EQUAL "DEBUG")<br></div><div><br></div><div>but:</div><div><br></div><div>$ cmake3 -DCMAKE_BUILD_TYPE=DEBUG ..<br></div><div><br></div><div>puts the target into build, not build/debug.</div><div><br></div><div>I would also like this to work if I use the make targets e.g. make debug.</div><div><br></div><div>Here's my full CMakeLists.txt.  Any advice would be appreciated.</div><div><br></div><div>cmake_minimum_required(VERSION 3.5 FATAL_ERROR)<br><br>if(NOT CMAKE_BUILD_TYPE)<br>  set(CMAKE_BUILD_TYPE "Release")<br>  message(STATUS "Build type not specified: Use Release by default")<br>endif(NOT CMAKE_BUILD_TYPE)<br><br>project(hello_world LANGUAGES CXX)    # Among other things, this sets PROJECT_NAME<br><br>add_executable(${PROJECT_NAME} "")<br><br>target_include_directories(${PROJECT_NAME}<br>    PRIVATE<br>        ${CMAKE_CURRENT_SOURCE_DIR})<br><br>target_sources(${PROJECT_NAME}<br>  PRIVATE<br>    main.cpp<br>    Message.cpp)<br><br>ADD_CUSTOM_TARGET(debug<br>  COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${CMAKE_SOURCE_DIR}<br>  COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all<br>  COMMENT "Creating the executable in the debug mode.")<br><br>ADD_CUSTOM_TARGET(release<br>  COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release ${CMAKE_SOURCE_DIR}<br>  COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all<br>  COMMENT "Creating the executable in the release mode.")<br><br>if (CMAKE_BUILD_TYPE EQUAL "DEBUG")<br>    message("debug mode")<br>    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/debug)<br>endif (CMAKE_BUILD_TYPE EQUAL "DEBUG")<br><br></div></div>