Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a CMake generator?

I read the documentation.

It says:

A CMake Generator is responsible for writing the input files for a native build system.  

What exactly does that mean?

If I have a set of C++ files in my project, are these the input files?

If I'm using Linux, what is my native build system by default? Make?

Why do the input files have to be written by the generator if they already exist?

like image 789
batman Avatar asked Sep 19 '14 19:09

batman


People also ask

What is CMake is used for?

CMake is an open-source, cross-platform tool that uses compiler and platform independent configuration files to generate native build tool files specific to your compiler and platform. The CMake Tools extension integrates Visual Studio Code and CMake to make it easy to configure, build, and debug your C++ project.

How does CMake generate Makefile?

CMake generates a Unix makefile by default when run from the command line in a Unix-like environment. Of course, you can generate makefiles explicitly using the -G option. When generating a makefile, you should also define the CMAKE_BUILD_TYPE variable.

Does ninja use CMake?

Working with Ninja using CMakeA build generator system like CMake can be used to create the input files for Ninja. To showcase working with Ninja using CMake, let us build Ninja using CMake with Ninja as the backend. Make sure that ninja.exe created by the bootstrap version is in the path.

How do I change the generator in my CMake gui?

For those seeking the CMake GUI answer. Go to File->Delete Cache and then click Configure again. A scenario where changing the generator is needed is that you are keeping the CMake GUI open and reusing the same directory (source and CMakeList.


1 Answers

What's a generator?

To understand what a generator is, we need to first look at what is a build system. CMake doesn't compile or link any source files. It used a generator to create configuration files for a build system. The build system uses those files to compile and link source code files.

So what's a build system?

A build system is a broad term that groups together a set of tools used to generally compile and link source code, but it can also include auxiliary tools used during a build process.

For example, in a multi-stage build system, one executable might be built to be used in the build process of another build.

Depending on the tool chain used on a system, CMake will generate multiple files and folders to allow the building of the source files referenced in the CMakeLists.txt and supporting .cmake files.

Sometimes multiple build systems may be installed on a computer, like for Windows you could have a Visual Studio and MinGW build system. CMake allows you to specify which if these build systems to generate configuration files for.

CMake includes a number of Command-Line, IDE, and Extra generators.

Command-Line Build Tool Generators

These generators are for command-line build tools, like Make and Ninja. The chosen tool chain must be configured prior to generating the build system with CMake.

The following are supported(**):

  • Borland Makefiles
  • MSYS Makefiles
  • MinGW Makefiles
  • NMake Makefiles
  • NMake Makefiles JOM
  • Ninja
  • Unix Makefiles
  • Watcom WMake

IDE Build Tool Generators

These generators are for Integrated Development Environments that include their own compiler. Examples are Visual Studio and Xcode which include a compiler natively.

The following are supported(**):

  • Visual Studio 6
  • Visual Studio 7
  • Visual Studio 7 .NET 2003
  • Visual Studio 8 2005
  • Visual Studio 9 2008
  • Visual Studio 10 2010
  • Visual Studio 11 2012
  • Visual Studio 12 2013
  • Visual Studio 14 2015
  • Visual Studio 15 2017
  • Visual Studio 16 2019
  • Green Hills MULTI
  • Xcode

Extra Generators

These are generators that create a configuration to work with an alternative IDE tool and must be included with either an IDE or Command-Line generator.

The following are supported(**):

  • CodeBlocks
  • CodeLite
  • Eclipse CDT4
  • KDevelop3 (Unsupported after v3.10.3)
  • Kate
  • Sublime Text 2

If I have a set of C++ files in my project, are these the input files?

Yes, they are some of the input files. For a make build system you also have a MakeFile. For Visual Studio you have a solution file (.sln). With both systems there are additional files needed that CMake knows how to create given a proper CMakeLists.txt file.

If I'm using Linux, what is my native build system by default? Make?

Generally, yes, but other build systems could be setup like Ninja.

Why do the input files have to be written by the generator if they already exist?

Some source files may already exist, but CMake has the ability to generate header and source files. Also as mentioned above, there are configuration files that must be generated that depend on the source files supplied in the CMakeLists.txt file.

** According to the documentation for CMake Version 3.9 & 3.15

like image 51
jmstoker Avatar answered Oct 07 '22 00:10

jmstoker