Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging/Running executables in cmake/Visual Studio project

We are moving from hand-managed Visual Studio projects to cross platform cmake.

We used to open a solutions file, select a project as "Startup Target" and push Ctrl+F5 or F5 debug or run.

Now cmake has this install concept. It requires me to run the install target. But the install project doesn't have any executables set so it can not be used to start with debugging.

If I set my executable project as a startup target, then install will not run, so I can not debug.

I am sure there is a better way of doing this.

Any ideas ?

like image 966
Paul Avatar asked Dec 08 '25 15:12

Paul


1 Answers

You should only need to run the INSTALL target if you want to distribute your application. If you select a project that builds an executable (so it has a ADD_EXECUTABLE statement in the CMakeLists.txt file) it should run with F5 or Ctrl+F5.

It could be that you executable requires shared libraries which are build in a seperate directory. You can force all executables and libraries to be build in the same directory with the following CMake commands in your main CMakeLists.txt file.

   SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/Bin/${CMAKE_BUILD_TYPE} CACHE PATH "Library output path")
   SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/Bin/${CMAKE_BUILD_TYPE} CACHE PATH "Executable output path")

If you want more control over the command that should be run when debugging have a look at this question: How to Set Path Environment Variable using CMake and Visual Studio to Run Test

like image 110
pkit Avatar answered Dec 10 '25 04:12

pkit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!