Convert Figma logo to code with AI

Kitware logoCMake

Mirror of CMake upstream repository

6,748
2,519
6,748
2

Top Related Projects

22,750

C++ Library Manager for Windows, Linux, and MacOS

5,498

The Meson Build System

22,963

a fast, scalable, multi-language and extensible build system

Premake

Quick Overview

CMake is a cross-platform, open-source build system generator. It is used to control the software compilation process using simple platform and compiler-independent configuration files, and generate native makefiles and workspaces that can be used in the compiler environment of your choice.

Pros

  • Cross-platform compatibility, supporting a wide range of operating systems and compilers
  • Highly flexible and extensible, allowing for complex build configurations
  • Large and active community, providing extensive documentation and support
  • Integrates well with various IDEs and development tools

Cons

  • Steep learning curve for beginners
  • Can be verbose and require more boilerplate code compared to some alternatives
  • Performance can be slower for very large projects
  • Some users find the syntax and structure less intuitive compared to other build systems

Code Examples

  1. Basic CMakeLists.txt for a simple project:
cmake_minimum_required(VERSION 3.10)
project(MyProject)

add_executable(MyExecutable main.cpp)
  1. Adding a library and linking it to an executable:
add_library(MyLibrary STATIC
    src/library1.cpp
    src/library2.cpp
)

add_executable(MyExecutable main.cpp)
target_link_libraries(MyExecutable PRIVATE MyLibrary)
  1. Setting compile options and definitions:
target_compile_features(MyTarget PRIVATE cxx_std_17)
target_compile_options(MyTarget PRIVATE -Wall -Wextra)
target_compile_definitions(MyTarget PRIVATE DEBUG_MODE)

Getting Started

  1. Install CMake from https://cmake.org/download/ or your system's package manager.
  2. Create a CMakeLists.txt file in your project root:
cmake_minimum_required(VERSION 3.10)
project(MyProject)

add_executable(MyExecutable main.cpp)
  1. Create a build directory and run CMake:
mkdir build && cd build
cmake ..
cmake --build .
  1. Run your executable:
./MyExecutable

Competitor Comparisons

22,750

C++ Library Manager for Windows, Linux, and MacOS

Pros of vcpkg

  • Simplifies dependency management for C/C++ projects
  • Supports cross-platform builds and multiple toolchains
  • Integrates well with Visual Studio and other IDEs

Cons of vcpkg

  • Limited to C and C++ libraries, while CMake supports multiple languages
  • Requires more setup and configuration compared to CMake's built-in features
  • Less mature and has a smaller community compared to CMake

Code Comparison

vcpkg

{
  "name": "example",
  "version-string": "1.0.0",
  "dependencies": [
    "boost",
    "openssl"
  ]
}

CMake

cmake_minimum_required(VERSION 3.10)
project(example)
find_package(Boost REQUIRED)
find_package(OpenSSL REQUIRED)

Summary

vcpkg focuses on package management and dependency resolution for C/C++ projects, while CMake is a more comprehensive build system generator. vcpkg excels in simplifying library management, especially for Windows developers, but CMake offers broader language support and more mature build configuration options. Both tools can be used together in projects, with vcpkg handling dependencies and CMake managing the overall build process.

5,498

The Meson Build System

Pros of Meson

  • Faster build times due to its optimized design and use of Ninja backend
  • Simpler and more concise syntax, making build scripts easier to read and maintain
  • Better cross-platform support, especially for Windows

Cons of Meson

  • Smaller ecosystem and fewer available modules compared to CMake
  • Less widespread adoption in large-scale projects
  • Steeper learning curve for developers already familiar with CMake

Code Comparison

CMake example:

cmake_minimum_required(VERSION 3.10)
project(MyProject)
add_executable(myapp main.cpp)
target_link_libraries(myapp PRIVATE somelib)

Meson example:

project('MyProject', 'cpp')
executable('myapp', 'main.cpp', dependencies: dependency('somelib'))

Both CMake and Meson are popular build systems for C and C++ projects. CMake has been around longer and has wider adoption, especially in larger projects. It offers more flexibility and a vast ecosystem of modules. Meson, on the other hand, focuses on simplicity and speed, making it attractive for smaller to medium-sized projects and developers who prefer a more straightforward build system configuration.

22,963

a fast, scalable, multi-language and extensible build system

Pros of Bazel

  • Faster build times for large projects due to advanced caching and parallelization
  • Better support for multi-language projects and cross-platform builds
  • More precise dependency management with fine-grained control

Cons of Bazel

  • Steeper learning curve and more complex configuration
  • Smaller ecosystem and community compared to CMake
  • Less widespread adoption, especially in existing projects

Code Comparison

CMake example:

cmake_minimum_required(VERSION 3.10)
project(MyProject)
add_executable(MyApp main.cpp)
target_link_libraries(MyApp MyLib)

Bazel example:

cc_binary(
    name = "MyApp",
    srcs = ["main.cpp"],
    deps = [":MyLib"],
)

Both CMake and Bazel are powerful build systems, but they have different strengths. CMake is more widely adopted and easier to learn, making it a good choice for many projects. Bazel, on the other hand, offers superior performance and scalability for large, complex projects, especially those involving multiple languages or platforms. The choice between the two depends on the specific needs of your project and team.

Premake

Pros of Premake

  • Simpler syntax and easier to learn, using Lua scripting language
  • More flexible and customizable build configurations
  • Faster execution time for generating project files

Cons of Premake

  • Smaller community and ecosystem compared to CMake
  • Less widespread adoption in large-scale projects
  • Limited built-in support for certain platforms and toolchains

Code Comparison

CMake example:

cmake_minimum_required(VERSION 3.10)
project(MyProject)
add_executable(MyApp main.cpp)
target_link_libraries(MyApp MyLibrary)

Premake example:

workspace "MyProject"
   configurations { "Debug", "Release" }

project "MyApp"
   kind "ConsoleApp"
   language "C++"
   files { "**.cpp", "**.h" }
   links { "MyLibrary" }

Both CMake and Premake are popular build configuration tools, but they cater to different preferences and project needs. CMake offers a more extensive ecosystem and wider adoption, while Premake provides a simpler syntax and greater flexibility. The choice between the two often depends on project requirements, team expertise, and personal preference.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

CMake


Introduction

CMake is a cross-platform, open-source build system generator. For full documentation visit the CMake Home Page_ and the CMake Documentation Page. The CMake Community Wiki also references useful guides and recipes.

.. _CMake Home Page: https://cmake.org .. _CMake Documentation Page: https://cmake.org/documentation .. _CMake Community Wiki: https://gitlab.kitware.com/cmake/community/-/wikis/home

CMake is maintained and supported by Kitware_ and developed in collaboration with a productive community of contributors.

.. _Kitware: https://www.kitware.com/cmake

License

CMake is distributed under the OSI-approved BSD 3-clause License. See Copyright.txt_ for details.

.. _Copyright.txt: Copyright.txt

Building CMake

Supported Platforms

  • Microsoft Windows
  • Apple macOS
  • Linux
  • FreeBSD
  • OpenBSD
  • Solaris
  • AIX

Other UNIX-like operating systems may work too out of the box, if not it should not be a major problem to port CMake to this platform. Please post to the CMake Discourse Forum_ to ask if others have had experience with the platform.

.. _CMake Discourse Forum: https://discourse.cmake.org

Building CMake with CMake

You can build CMake as any other project with a CMake-based build system: run an already-installed CMake on this source tree with your preferred generator and options. Then build it and install it.

To build the documentation, install Sphinx_ and configure CMake with -DSPHINX_HTML=ON and/or -DSPHINX_MAN=ON to enable the "html" or "man" builder. Add -DSPHINX_EXECUTABLE=/path/to/sphinx-build if the tool is not found automatically.

To run the test suite, run ctest in the CMake build directory after building. See the CMake Testing Guide_ for details.

.. _Sphinx: https://sphinx-doc.org .. _CMake Testing Guide: Help/dev/testing.rst

Building CMake from Scratch

UNIX/Mac OSX/MinGW/MSYS/Cygwin ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

You need to have a C++ compiler (supporting C++11) and a make installed. Run the bootstrap script you find in the source directory of CMake. You can use the --help option to see the supported options. You may use the --prefix=<install_prefix> option to specify a custom installation directory for CMake. Once this has finished successfully, run make and make install.

For example, if you simply want to build and install CMake from source, you can build directly in the source tree::

$ ./bootstrap && make && sudo make install

Or, if you plan to develop CMake or otherwise run the test suite, create a separate build tree::

$ mkdir build && cd build $ ../bootstrap && make

Windows ^^^^^^^

There are two ways for building CMake under Windows:

  1. Compile with MSVC from VS 2015 or later. You need to download and install a binary release of CMake. You can get these releases from the CMake Download Page. Then proceed with the instructions above for Building CMake with CMake.

  2. Bootstrap with MinGW under MSYS2. Download and install MSYS2_. Then install the required build tools::

    $ pacman -S --needed git base-devel mingw-w64-x86_64-gcc

    and bootstrap as above.

.. _CMake Download Page: https://cmake.org/download .. _MSYS2: https://www.msys2.org/

Reporting Bugs

If you have found a bug:

  1. If you have a patch, please read the CONTRIBUTING.rst_ document.

  2. Otherwise, please post to the CMake Discourse Forum_ and ask about the expected and observed behaviors to determine if it is really a bug.

  3. Finally, if the issue is not resolved by the above steps, open an entry in the CMake Issue Tracker_.

.. _CMake Issue Tracker: https://gitlab.kitware.com/cmake/cmake/-/issues

Contributing

See CONTRIBUTING.rst_ for instructions to contribute.

.. _CONTRIBUTING.rst: CONTRIBUTING.rst