Can't set CMake configuration parameters from Visual Studio - c++

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

Related

Visual studio Python extension mixed mode debugging on CMake project

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

Linking errors in Poco with Conan package manage on Windows [duplicate]

I have a project which i have generated with cmake and running in visual studio 2010.I changed the configuration to x64,in visual studio my active solution and the Target Machine in(Properties->Linker->Advanced) is set as x64.I still get the linker LNK1112 error.Is this something which i set in cmakelist.txt if so what is the command?
-swetha
It's not something you'd want to set in CMakeLists.txt. Basically, CMake has multiple generators for different compilers. (The x86 and x64 compilers are two distinct compilers on Windows.) When you generate the build files, you need to pass along the correct compiler for CMake to use, or if you use the GUI, select Win64. From the command line:
cmake -G "Visual Studio 14 Win64" path/to/your/CMakeLists.txt
or whatever version of Visual Studio you want. You can see the available generators with:
cmake --help
If this didn't solve your problem, try it again after deleting the generated build files.
If that still doesn't solve the issue, you are linking to a third party dependency built for x86.
Try to delete all *.obj files in your solution and let compiler compile all files again. This problem may cause of compiler try to reference obj files that was compiled x64

Creating Visual Studio Project from CMake, Visual studio does not find executable

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.

Visual Studio 2017 cMake diagram view

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.

Extend the Visual Studio C++ Build Process

A found an article (Extend the Visual Studio Build Process) that explained how to override build targets in a C# project file. I tested this, and it seems to work well. However, what I really want to do is override a build target in a C++ project (with Visual Studio 2005). The problem is that C++ projects use different XML. Instead of having <project> as the root, C++ projects have <VisualStudioProject> as the root. When I add the <target> tag to a C++ project file and try to open the project in Visual Studio, I get this error:
The following error has occurred during XML parsing:
File:
[Path to Project File].vcproj
Line: 304 Column: 30 Error Message:
Element 'Target' is unexpected
according to content model of parent
element 'VisualStudioProject'.
The file
'[Path to Project File].vcproj'
has failed to load.
How can I override a Visual Studio build target for a C++ project? Or is there a better way to customize what happens during a C++ build?
In Visual Studio 2005 there are no build "targets" for C++ builds as the C++ build system does not use MSBuild.
However, VC++2005 defines the Pre-Build, Pre-Link, Post-Build Events as well as the ability to add a Custom Build Step for non-standard files.
You may be able to achieve what you want using these settings.
Note:
VC++2005 projects can be built using MSBuild, it's just not what Visual Studio does out of the box.
Visual Studio 2010 uses MSBuild for all project types.