title: How best to set output directory for a CMake C++ project built by Visual Studio 2017?
body: <p>I have used Visual Studio 2017 to build C++ desktop projects using .vcxproj files.  I like the default behavior where the output directory is a subdirectory below the project. For example:</p>
  
  <pre><code>|-myproj.sln
  |-myproj.vcxproj
  |-----------------|--x64 --|-- myproj_release --|-- myproj.exe
  </code></pre>
  
  <p>I now want to define the build using CMake instead of .vcxproj, so that I can build with Visual Studio Code as an alternative to Visual Studio 2017.</p>
  
  <p>I converted my .vcxproj to a CMake project using cmake-converter. The resulting CMakeLists.txt contains:</p>
  
  <pre><code>if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_DEBUG}")
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_DEBUG}")
    set(CMAKE_EXECUTABLE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_DEBUG}")
  else()
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_REL}")
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_REL}")
    set(CMAKE_EXECUTABLE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_REL}")
  endif()
  </code></pre>
  
  <p>When I open this CMakeLists.txt with Visual Studio 2017 and build it, it puts the executable in subdirectory CMakeBuilds of my user directory.  I guess this is because Visual Studio 2017 is determining CMAKE_BINARY_DIR.</p>
  
  <p>What is the best way of getting the output directory to be in the source directory as happens with my .vcxproj file?</p>