


CMAKE DEBUG BUILD HOW TO
Finally we will show how to use the advanced CMake breakpoints to quickly locate the relevant parts of the CMake scripts.you could also edit the version.txt file and then force CMake to re-run the file() statement to read the updated version from the file. missing tools) without restarting the entire configuration process each time. Now the project got configured with PROJECT_VERSION=2 as we have manually changed it during CMake configuration: Changing variable values manually and setting next statement could be useful to quickly get past errors (e.g.Step through the rest of the set_version_from_file() function to see that the error doesn’t trigger anymore:.Once the breakpoint triggers, hover the mouse over VERSION_FROM_FILE and change its value to 2: Ensure the breakpoint on the VERSION_FROM_FILE check is still set and start another debug session. Now we will show how to modify the version after it was read from the file.Once it is complete, the project will be configured with PROJECT_VERSION=1 as the error statement was successfully skipped: Press F5 to continue the CMake configuration process.Now instead of stepping into the check, simply right-click on the “target_compile_definitions” line and select “Set Next Statement”:.Restart the CMake debugging an put a breakpoint on the line comparing VERSION_FROM_FILE.
CMAKE DEBUG BUILD WINDOWS
Once CMake hits a fatal error, VisualGDB will automatically stop at that statement: You can use the Call Stack and Watch windows to examine the program state, however as the message was already triggered, it is too late to change anything or skip the error line. The easiest way to get to the error message would be to simply press F5 to continue debugging.VisualGDB will stop at the first statement of the file:.Right-click on your project in Solution Explorer and select “Launch CMake Debugger”: Now we will use the CMake Script Debugger to step through the CMakeLists.txt file and see what exactly CMake is doing and also to skip the error statement.Save the CMakeLists.txt and see how CMake reports a configuration error (as the version stored in the file is less than the version checked in CMakeLists.txt):.
CMAKE DEBUG BUILD CODE
Then add the following code to your CMakeLists.txt file:.First of all, create a file called version.txt in your project directory and ensure it contains a single character: “1” Now we will replace the hardcoded version with a CMake function that will read the version from a text file.VisualGDB will automatically insert the corresponding statement into the CMakeLists.txt file:.Open the Visual Studio project properties for the target and add “PROJECT_VERSION=1” to the preprocessor definitions:.VisualGDB will generate a simple CMake project with one target: In this tutorial we will build the code locally using the Raspberry Pi cross-toolchain: You can either build the code on the Windows machine using a cross-toolchain, or build it directly on the Linux machine, depending on your configuration. On the next page select the machine you want to target.Select “Create a new project” -> “Application” -> “CMake” and ensure that the “Use the advanced CMake Project Subsystem” checkbox is set:.Start Visual Studio and open the VisualGDB Linux Project Wizard:.
CMAKE DEBUG BUILD INSTALL
We will create a basic CMake project using a Linux cross-toolchain, add macros to read the version number from a text file, and will then step through the CMake statements in the debugger and show how to modify the version read from the file on-the-fly.īefore you begin, install VisualGDB 5.4 Preview 7 or later. Set(CMAKE_LIBRARY_OUTPUT_DIRECTORY $/bin)įirst time you open a CMakeLists.This tutorial shows how to use VisualGDB to step through the CMake scripts while analyzing CMake configuration problems. Now I use cmake and qtcreator on a regular basis, to obtain the same behavior I have found the following approach : I have used qmake for a while and the debug_and_release facilities to have both debug and release version of my code (with different executable, different build tress …)
