pthom/hello_imgui_template

VS solution location

Closed this issue · 4 comments

Hello, this may sound silly but is there any way to not have the visual studio solution project location be in the same path as build directory when using the hello_imgui_template to build ? I could not find an easy way to move this outside of the build directory as I do not like using filters in visual studio to see my source files. It makes managing my project very cumbersome. Appreciate any help

When you run CMake on Windows, here is how the Solution Explorer looks.
image

You can see Hello ImGui sources at the top, and your project source at the bottom (hello_world).

I do not understand your remark: "I do not like using filters in visual studio to see my source files".


If you want more customization, you should consider doing it with CMake. Below are some advice given by ChatGPT:

To address this, you can modify the CMake setup to place the solution/project files in a different directory than the build files. Here’s a general approach to achieve this:

Modify CMakeLists.txt: Specify a different output directory for project files.
Use CMake Options: Utilize CMake's CMAKE_RUNTIME_OUTPUT_DIRECTORY, CMAKE_LIBRARY_OUTPUT_DIRECTORY, and CMAKE_ARCHIVE_OUTPUT_DIRECTORY to control where different types of build artifacts are placed.
Out-of-source Build: Configure CMake to use a separate build directory.

Example CMake Configuration

In your CMakeLists.txt, you can add:

# Set the output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

# Optionally, specify where to put Visual Studio project files
set(PROJECT_BINARY_DIR ${CMAKE_SOURCE_DIR}/vs_project)

Running CMake

When you run CMake, specify the build directory:

sh

mkdir build
cd build
cmake -G "Visual Studio 16 2019" -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=../vs_project ..

This approach will separate the build artifacts from the project files, addressing the user's concern.

Thank you for your reply. I have tried that and the visual studio solution is still in the build folder. I guess I am not used to this way of working on a project. So the solution is used to just build the project and I put my source control at the project root path (one root above the build folder) ?
image

So the solution is used to just build the project and I put my source control at the project root path (one root above the build folder

Absolutely, and add "build/" to your .gitignore.

When using CMake, you should not commit the visual studio solution, it is generated by cmake.

Thank you for your time !