What is the benefit of building with CMake? - visual-studio

I am working on SFML and I am curious about the option that I can compile it myself. I found it in tutorials, but from the first line I became confused:
CMake is an open-source meta build system. Instead of building SFML, it builds what builds SFML: Visual Studio solutions ...
There is a build option in visual studio too, is there any difference between that build and CMake build?
What does it mean that it builds what builds SFML? It means library files?
Visual studio solutions? What does it mean? As far as i know, when i open a new project it is within a solution and i can add new projects to this solution (I am confused about why there must be more than one project in a solution too!).
What does it mean that CMake builds a solution? And what is it for?

There is sourcecode. People want to compile it. It is difficult and annoying to type the compile commands into a terminal.
People invent build systems, to make 1.) more easy. For example make files or what Visual Studio integrates and stores in its files, called solution.
There are projects, that are cross-platform. They could provide make files, solution files, files for Xcode, Eclipse and so on. This becomes difficult and annoying.
People invent systems, that creates build system to ease 3.). From a common set of files, several different build systems can be steered.
In your actual case: CMake creates the solution file, you can open the solution file and built SFML with that.

CMake is a wonderful tool for cross-platform development without the hassle of maintaining separate build utilities. On Windows, CMake can create a Visual Studio solution file based on its CMakeLists.txt file. On Linux, generally CMake outputs a makefile. CMake is compatible with many build tools, I recommend reading more of there documentation on their website to gain more information.
Edit: Just to be more clear. CMake literally builds what builds SFML since it creates the Visual Studio solution used to build SFML.
A build in VS for a solution is building the library itself. A CMake build generates the VS solution with which you would use to build the library.
See 1.
A VS solution is the full buildable setup containing 1 or more projects. Solutions can contain multiple projects since VS has a limitation on only 1 output per project. If you want multiple outputs (e.g. 4 dlls) each output needs it's own project.

Related

Visual Studio, CMake and Toolchain Files

before I explain my current problem with Visual Studio in combination with CMake, I try to explain what I want to accomplish as there might be a better solution.
At our company we have a huge code base mainly written in C for QNX. For development we are using the standard IDE QNX momentics. As this is based on a quite old eclipse version ... the whole IDE sucks.
I'm currently evaluating to use Visual Studio as a replacement. With a really simple HelloWorld-programm I was able to build and debug the project from within VS using CMake and a CMakeSettings.json.
As our code base is basically organized in a tree-like structure, I've created a typical hierarchy of CMakeLists.txt which allows me to build single/multiple projects.
As QNX delivers its own compiler I've created a toolchain file, this is running fine so far, the required toolchain is invoked once a build is triggered via cmake.
Now for the part that I'm struggling with:
How to use this CMake setup in order to develop/debug code from VS?
I had two ideas in mind which don't really work or I'm doing something wrong.
Use the CMake generator for VS 2019 and generate a complete solution. Problem: The toolchain file is not "used" as all projects will be setup with the internal VS compilers. Is there any way to get this working? I thought calling cmake -G "Visual Studio 16 2019" -DCMAKE_TOOLCHAIN_FILE=$FILE would do the job. Additionally: how would I incorporate the debugger configuration? With this solution the CMakeSettings.json seems to be ignored as VS solutions are used.
Use File->Open->CMake to open the root project. Shouldn't this show all "contained" projects which also include a CMakeLists.txt as projects? I can only see the folder tree in the Solution Explorer. Build a single project from the solution explorer is also not possible ... there is simply no option.
Anyone with experience on this topic?
Minor comment please limit questions to 1 question in the future. Multiple questions clutters questions and makes search results worse.
============================================================
I'll answer question #1 this part of question number 1.
"Use the CMake generator for VS 2019 and generate a complete solution. Problem: The toolchain file is not "used" as all projects will be setup with the internal VS compilers. Is there any way to get this working? I thought calling cmake -G "Visual Studio 16 2019" -DCMAKE_TOOLCHAIN_FILE=$FILE would do the job."
Instead of using Visual Studio as your generator try using "Ninja" instead. Ninja will work if your toolchain code is correct. Toolchains and visual studio are complicated to say the least. If you wanna go down that rabbit hole I can help but that's a separate question
Basically try switching to Ninja instead of Visual Studio as your generator for CMakeSettings.json. Ninja is very easy to write toolchains for.
======================================================================
"Additionally: how would I incorporate the debugger configuration?"
The MSDN articles are actually quite good. I figured it out this week. In my opinion the debugger configurations are more powerful with the CMake approach than vanilla visual studio.
Configure CMake debugging sessions
https://learn.microsoft.com/en-us/cpp/build/configure-cmake-debugging-sessions?view=msvc-160
"Tutorial: Debug a CMake project on a remote Windows machine"
https://learn.microsoft.com/en-us/cpp/build/cmake-remote-debugging?view=msvc-160
Trust me once it clicks you'll love it.

Compiling the opus-codec API library

First, going to be honest. I'm a c#/java-language-level dweller. So I have no idea about how to compile native-C projects such as opus.
I've tried doing it myself, and I've tried googling it. I simply need help compiling the opus-codec API (on Windows).
Once I have the library compiled, I'll build a wrapper for it's API.
While my searches have indeed found opus wrappers targeting my current project's language (c#), I can't find an up-to-date one. I don't know if it matters, but I need it for it's VoIP capabilities.
Sorry for my stupidity in the matter.
[UPDATE]
After compiling with Visual Studio 2010: Ultimate, I have a .lib library file. I need a .dll. I don't know what I'm doing. Help?
In a C project there is going to be some way to drive a build of all the object files, libraries, etc. Basically the same thing as maven build in Java, just with different tools. You will have to have the right tools if you don't.
On unix systems it's usually Makefile driven, running command line programs that compile and link the program or library that is being built. In GUI environments like XCode or Visual Studio, there are ways to run the build directly from the UI.
Looking at the source tree, there's a directory with a number of Visual Studio 2010 projects in it - https://git.xiph.org/?p=opus.git;a=tree;f=win32/VS2010
If you're using Visual Studio, loading that up and trying a build to see if it still works is where I'd start. Or perhaps have a look at Any way to do Visual Studio "project only" build from command line? or other questions that reference msbuild.

How to use Omake build system for a Visual studio 2010 project

I have a project, which works fine in VS-2010. And runs fine.
But I want to create a make-file by using Omake. How to build the same in Omake.
I have gone through all the documentation of Omake, but it does not say how to make it.
My VS-2010 project contains .c, .cpp, .h, .rc MFC and many subdirectories too.
There is no direct way to convert a project from VS to Omake: you have to write the 'OMakefile's by hand since the two build systems (MSBuild is behind VS) and concepts are somewhat different. Once the OMakefile's are working, you can always create a Visual Studio project of type "Makefile" that calls the omake utility behind the scene.
If the reason for change is that you want to make the projet multi-platform (well, I doubt so since you use MFC), you may consider CMake, a widely-used project generation tool. CMake can generate both Makefiles (GNU) and VS projects, depending on the platform, from a project description.

Visual Studio Solution to SCONS?

Is there any tool that can convert a large and complex* Visual Studio 2005 (or 2008) Solution into a SCons project?
* Lots of projects and multiple configurations on multiple platforms/compilers
Probably not, and even if there were, SCons gives you significantly more transparency and flexibility about managing your build than visual studio does. As a starting point, it's best to do each one in turn.
Create a new makefile project
Clone the source from one project to another
Invoke scons from the makefile command.
Replace the dependancies on the old project with the scons version.
Test
Repeat from 1. with each project.
Once you've done a few projects, it's pretty easy to refactor the major differences between build types (shared libs, static libs and programs) and platforms into a module of common scons helpers that can be imported. On windows, consider groups of flags for things like debug and release builds, standard library linkage and exception handling.
Also, things to look out for include:
If you're doing cross platform builds, consider the differences between the linking models with respect to the effects of missing symbols.
What you'll do to deal with manifest files and invoking the visual studio tools.
Variant build directories (debug/release) can be tricky at the start. Start simple, and enhance your build once you're sure it's necessary.
The following script looks promising. I may give it a whirl: the reason the by hand solution isn't completely practical due to the sheer scale of the solution in question: it has hundreds of projects. This is why I was thinking a script that would generate SCons modules would give me a starting point.
Unfortunately porting the solution in question to SCons by hand would be a project in itself!, although I do admit it would be the 'correct' way to do it.

Build Visual Studio Projects from Jamfiles?

Anyone know of a way to create Visual Studio Projects from a build based on Jamfiles?
I'd settle for a jamfile -> XML-or-some-other-intermediate-format exporter tool, so I could write my own.
This jam distribution has a tool that does that:
http://redmine.jamplex.org/
See here:
http://redmine.jamplex.org/git/jamplus/docs/html/jamtoworkspace.html
Haven't used any of it myself yet, so I'm afraid I can't say anything about how well it works.
You might also consider CMake. CMake files are about as easy to write as Jamfiles, and CMake can generate projects for Visual Studio, Xcode, and Unix Makefiles automatically. I used to use Jam for all my Linux projects, but once I discovered CMake, I haven't gone back.
JamPlus has a built-in workspace generator that reads a project's Jamfiles and exports an IDE workspace.
http://jamplus.org/git/jamplus/docs/html/jamtoworkspace.html

Resources