Basically, I've got the same question as in
How to configure CMake so that the generated Visual Studio project finds the executable?. None of the answers there worked for me.
I have a CMake project, and I just want to create a Visual Studio 2019 Project from it:
So I just run cmake . from the root directory.
Then I have a *.sln file in my root directory.
After opening it with Visual Studio 2019, I press the "Local Widows Debugger" button, it compiles successfully but then the IDE complains with:
Unable to start program 'C:\Users...\x64\Debug\ALL_BUILD'. The system is unable to find the specified file.
Using travis everything compiles fine, too: https://travis-ci.com/Necktschnagge/markov_chain_analyzer/builds/144941090
You can see the code here: https://github.com/Necktschnagge/markov_chain_analyzer/tree/old
What do I need to do so that CMake creates a VS solution, that is well-configured so that I can run the debugger?
When you create a Visual Studio solution with CMake, it automatically sets the Startup Project to ALL_BUILD. This is a CMake pre-defined target, which builds all of the projects in the solution. It is not a project containing an executable that can be debugged.
You must change the Startup Project in your Solution Explorer to one of your executable projects before debugging. You can do this by right-clicking on the project you want to debug, and selecting Set as Startup Project. There are some more instructions here if you're using VS with CMake integration.
You can also tell CMake to set a different Startup Project by default when building CMake from scratch, using VS_STARTUP_PROJECT. Put something like this in your top-level CMake file:
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT MyExeTarget)
Now, CMake will set MyExeTarget as the Startup Project in Visual Studio, instead of ALL_BUILD.
Related
I'm trying to create a C++ Python extension using pybind11 and CMake, and would like to take advantage of visual studio's mixed mode debugging (see) for developing the extension.
I tried following the MSDN guide, and was able to create an extension and debug it using visual studio solution configurations. However, trying to recreate the project with CMake and debug it, breakpoints inside the C++ code are not triggered. I tried recreating the project twice:
a full CMake project (i.e. first create a folder with a CMake file then open it in VS).
a Python solution with a CMake subproject (adding the build folder to python search paths to access the extension).
In both methods C++ breakpoints are not triggered. Is there any way to make this work? Something I'm missing? I know there is a VSCode plugin which enables something similar. I'm currently using it, however I'd like to know if it is possible in Visual Studio proper.
Versions:
Visual Studio 2022
CMake 3.18
Python 3.8 (with debug symbols installed), however this is not the Python distributed with Visual Studio
I am trying to use the entire CMake workflow from Visual Studio. I created a folder with a CMakeLists.txt file along with the code, and Visual Studio magically builds and configures it with the parameters I specified in the CMakeLists.txt file.
However, I can't seem to configure the parameters that I am able to configure from the CMake GUI. I thought that the CMakeSettings.json file that VS creates when I "Configure" the build would help me override the default settings, but VS still builds with the default parameters, even if I change their values there and save it.
What is the correct way to set the build parameters from Visual Studio?
I suggest you could refer to the following docs:
Configure and build with CMake Presets in Visual Studio
Customize CMake build settings
It seems like this should be easy and I've spent hours trying to find this answer online but haven't had any luck.
I can open the CLion folder path in Visual Studio, but that option doesn't give me the usual options to build and start the project. To do that, I need to open CLion as a Project/Solution, but I can't seem to do this.
My professor requires that my C++ code be executable in Visual Studio, but I prefer CLion. So I've done all my work in CLion and want to test that it runs in Visual Studio. How can I import my CLion project?
Thanks!
The link provided describes Visual Studio's CMake integration, which (similar to CLion) will install a version of CMake that Visual Studio will use. These instructions are pretty thorough and should provide everything needed to get your CMake project working in Visual Studio.
Now, you probably have two versions of CMake installed on your machine, one that came with CLion and one that came with Visual Studio. I would recommend installing the latest version of CMake on your machine separately, and configuring both Visual Studio and CLion to use that version instead. However, this is probably getting outside the scope of your immediate problem.
As you follow the Microsoft's instructions for "CMake projects in Visual Studio", you mentioned receiving the error:
1> [CMake] CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.17/Modules/CMakeDetermineSystem.cmake:173 (file):
1> [CMake] file failed to open for writing (No such file or directory):
This looks like a permissions issue, specifically while running CMake within Visual Studio, so be sure you have read/write access to all the files in your project, and the CMake packages in your Visual Studio installation. Hopefully, this doesn't require you re-install Visual Studio in another location on your machine, or run Visual Studio with elevated privileges, but perhaps that is necessary.
If you decide to install CMake separately, the instructions would be the following:
Install the latest CMake on your machine (somewhere you have adequate permissions), and ensure it is available in your Path environment variable. You can verify this by running cmake -version from the command line to see it is the version you just installed.
Using Windows command prompt, navigate to your CMake project directory (containing the top-level CMakeLists.txt file), and run the following:
mkdir build
cd build
cmake -G "Visual Studio 16 2019" -A x64 ..
You may run -A Win32 with the cmake command instead if your project is a 32-bit build.
Open the .sln Visual Studio Solution file that was generated in the build directory. Once, the Solution is loaded in Visual Studio, you can build the project (CTRL + SHIFT + B).
I am trying to compile GDCM 2.8.4 for Windows. Can anybody describe how to compile it with Visual Studio 2013 Professional? The GDCM wiki is out of date. Thanks a lot.
First of all, you will have to install CMake. Then
Start CMake GUI.
I guess you already have the gdcm-2.8.4 directory (in a directory X:\XXXXX\ ) containing
Applications
Source
Testing
Utilities
and other subdirs. So set the in the CMake GUI "source dir" to X:\XXXXX\gdcm-2.8.4 . (NOT to its Source subdir!).
Then you create a new directory, where CMake will create the VS projects, let's call it X:\XXXXXX\GDCM-VSProjects. In the CMake GUI set "Where to build the binaries" to X:\XXXXXX\GDCM-VSProjects.
Then, in the CMake GUI press "Configure".
After configuring CMake offers you some options; choose at least GDCM_BUILD_APPLICATIONS, GDCM_BUILD_EXAMPLES, GDCM_BUILD_SHARED_LIBS. For documentation you will need doxygen, latex and possibly more.
Then, in the CMake GUI press "Generate". Now a lengthy calculation is performed and finally VS solution and VS subprojects are generated into your new X:\XXXXXX\GDCM-VSProjects subdirectory.
Now you can open GDCM.sln in VisualStudio and BuildAll in 64 bit Release mode.
After the build, you will find libs, dlls and exes in the bin/Release subdirectory of your X:\XXXXXX\GDCM-VSProjects.
Thats it.
Recently I have opened a .sln project in VS 2017 and I noticed that I can view diagram of all classes - its 1st time I ever noticed it and I'm quite "wow this is epic".
I now have a cMake based project that I open via > open Folder > cmake root folder. Even tho it opens/ compiles I don't see any view diagram option. Does any1 know how to enable it?
CMake should generate a Visual Studio solution (sln). You need to run CMake and then open the generated solution which will be put in your build folder. You will have to view/edit your CMakeSettings.json to see where your build folder is when opening a CMake project in Visual Studio. Alternatively just run CMake from the command line to get the solution file.