CMake Visual Studio Workflow - cmake

What does the Workflow look like if you're developing in Visual Studio but using CMake? I need to maintain CMakeLists.txt manually, but I'm building the project using the default VS solution file. How do I know I haven't made mistakes in my CMake file?

Related

How to make CMake set dependencies for a static library project?

I'm using Windows 10 Pro, Visual Studio 2022 and cmake version 3.26.0-rc3. In my Visual Studio solution I have a static library project, let's call it MyLib, which uses features from libxml2 i.e. it needs to link against libxml2.lib. Also in my solution there is an executable project, let's call it MyExe, which links against MyLib and also has libxml2.lib listed as a dependency in its project settings.
The problem is that in the CMakeLists.txt file of MyLib, target_link_directories and target_link_libraries do not seem to have any impact on the MyLib project settings, particularly Additional Library Directories and Additional Dependencies, respectively. For MyExe, those commands work as expected. If I fix the linker options for MyLib project settings manually in Visual Studio IDE, everything builds fine, but I don't think I should need to manually alter project settings initially created by CMake. So is there something I'm missing here - like that dependencies for a static library project need to be set in a different way in CMake - or is this a bug in CMake or Visual Studio? Are there any alternative ways to achieve the desired behavior and get the build to work?
In trying to find solutions for this I came across this very old post, but if I understood correctly it suggested adding an extra library project which sounds like a huge overkill for a simple thing like this which could be worked around by setting the project settings manually in Visual Studio IDE, so it's not an acceptable solution for me.

Open CMake proejct in Visual Studio 2019 using command line

I use Visual Studio IDE to develop, VS C++ to compile, CMake to generate the project in VS and Ninja to build.
I have a script that clone a project from git server and automate several steps I need to perform before start working on it.
At the end of this script I would like to open the project in Visual Studio. Before I used to generate the VS solution instead and then use devenv with the sln file as a parameter to open it. But now that I use VS support for CMake if I use CMakeList.txt file as a parameter it only opens this file not the complete project.
Is there a way to do what I am trying to do??
Thanks in advance.
Assuming your project's root CMakeLists.txt is located in C:\project\CMakeLists.txt you can call
devenv "C:\project"
without the CMakeLists.txt.
Note that currently there seems to be a bug in Visual Studio 16.7 that when opening a directory, all the views (e.g. solution explorer) are hidden by default. (https://developercommunity.visualstudio.com/content/problem/1140297/visual-studio-is-forgetting-docked-viewwindow-layo.html)

How reimport .targets file in Visual Studio?

I work in Visual Studio. It seems for me, that, if I change anything in imported .targets file, the new version of .targets is not reimported to main project while building it. If I reopen my project (I.e. close and open again Visual Studio) and then launch build - the new version of .targets works.
Is it possible to tell Visual Studio to import .targets at any rebuild?
I tried use "rebuild" and "clean" solution and project, without any result regarding the problem.
Re-evaluating imported files is done by the new CPS-based project systems that are used for .NET Core / .NET Standard projects.
For VS versions before VS 2019, you may also need to indicate to MSBuild that the imported targets file should also re-trigger incremental build by adding its path to $(MSBuildAllProjects) (this is no longer needed in MSBuild 16 / VS 2019):
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
But for "classic" .NET Framework / ASP.NET projects, you still need to close and re-open the solution for changes to take effect inside the IDE.
Also see this GitHub tracking issue for the legacy project system.

Using MSBUILD with C++ Builder 2010

Enlighten me please... I have a buildserver that runs MSBUILD to build projects done in C++ Builder 2010. I wanted to setup that entire setup on my local machine to be able to work on the build scripts without messing up the live build server. But I was wondering how MSBUILD knew how to work with C++ Builder projects.
Then I read that a file called Borland.Group.Targets was the magic piece. But I can't find it anywhere. I looked at Embarcaderos site, Microsoft's site, the C++ builder and MSBUILD installations etc. What is it, where do I get it and how does it work?
(My guess is that it's a file with "rules" telling MSBUILD how to handle C++ Builder projects, but that doesn't help if I can't find the file... hehe)
Are you asking how to build a project via the command line? Make a .cmd file like so:
#ECHO OFF
call rsvars.bat
msbuild.exe MyProject.cbproj /t:clean /p:Config=Release
msbuild.exe MyProject.cbproj /t:build /p:Config=Release

Build merge module without Devenv from .vdproj

I read quit a few Stackoverflow Questions about building mergemodules via commandline but all of them were accepted when either somebody suggested to use devenv for compilation or use Dark to create wix-files from existing msi files.
Considering the following:
VisualStudio isn't installed on the buildserver I have to use.
I am using nant + msbuild to compile the solutions
I would like to compile mergemodules from .vdproj (because Visual Studio detects dependencies automatically)
and create a msi setup from multiple mergemodules
... how can I build the merge modules from commandline without devenv and without loosing the comfort of automated dependencie resolving for mergemodules in visualstudio?
Maybe there is a nanttask for it I haven't found?
MSBuild doesn't support Visual Studio deployment projects, my advice would be to bite the bullet and go with Wix.
Perhaps VS2010 will use MSBuild schema for vdproj files? I'm guessing no, but couldn't find any links.
currently, it is not possible to do this with msbuild. but i am pretty sure you might be interested in this MSDN blog article because of your question related to merge module/setup projects in vs. It seems they won't continue to support .vdproj files in upcomming versions of visual studio (2010 will be the last supporting them).
So you may run into problems in the future even if you're using devenv instead of msbuild.
... but this article could be some kind of whispering, too. Anyway, there are a lot of alternatives on the road if you want to build setups.
Even I was facing the same issue. Use below format
call "C:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\vcvarsall.bat"
cd /d Path_to_sln
"C:\Program Files (x86)\Microsoft Visual Studio
10.0\Common7\IDE\devenv.com" "Required_path\solution.sln" /Project "Required_path\Setup\Setup.vdproj" /Build Release /Out
"Required_Path\vs_errors.txt"
I would be pretty surprised if you are able to build .vdproj files without installing Visual Studio.