DEV Community

Cover image for CMake Architecture
Kaa Mi
Kaa Mi

Posted on

CMake Architecture

INTRODUCTION

Project CMake started in 1999 with a goal to replace autoconf/libtool as a build system for C/C++ projects. It evolved into an extensive toolkit with the following use case:

  • CMake: build tool
  • CTest: test driver tool for running regression tests
  • CPack: packaging tool to create platform-specific installers
  • CDash: web app for displaying testing results

CMake can generate Makefiles for UNIX-based systems and VSStudio Project Files for Windows etc. The only dependency for CMake is C/C++ compiler. It can generate static libraries, shared libraries, executables, and plugins.

Key Features:
  • Build tree is kept separate from the source tree.
  • Focus is shifted to program to system features and not to the system itself.
  • From a user's perspective, there are two steps:
    User View

    • configure: create internal representation of build
    • generate: actual build files are created

To avoid setting up the ENVIRONMENT VARIABLES every time, CMakeCache.txt is generated for all persistent variables. Additional CMakeLists.txt can be parsed by using include and add_subdirectory pattern and having CMakeLists.txt in them. One can have custom targets.

  • Parser for CMakeLists.txt calls yacc/lex for CMake language. yacc/lex files are kept in source under version control to build CMake.
  • From architecture perspective, CMake is a Object Oriented System with following class hierarchy.

Code Architecture

REFERENCES:

  1. CMake: Architecture of Open Source Applications, Bill Hoffman and Kenneth Martin, https://www.aosabook.org/en/cmake.html
  2. Header Image: https://www.pexels.com/photo/arch-architecture-art-building-415574/

Top comments (0)