cplusplus-cmake-template

This project demonstrates a robust CMake-based build system that showcases the creation and utilization of a custom library within an application. Written in year 2024.

Stars
2

CMake Template Project: MyLibrary and MyApp Integration

This project demonstrates a robust CMake-based build system that showcases the creation and utilization of a custom library within an application. The template is structured as follows:

About

Project Components

  1. MyLibrary: A custom-built library that encapsulates reusable functionality.
  2. MyApp: An application that leverages the features provided by MyLibrary.

Build Process

The CMake configuration orchestrates a two-stage build process:

  1. Library Compilation: MyLibrary is compiled as a standalone unit, generating either a static or dynamic library based on project requirements.

  2. Application Linking: MyApp is subsequently built, with CMake managing the necessary linkage to MyLibrary.

Key Features

  • Modular design promoting code reusability
  • Flexible configuration options for library type (static/dynamic)
  • Streamlined dependency management
  • Cross-platform compatibility ensured through CMake's abstraction layer
  • Integration with vcpkg for external library management

This template serves as an excellent starting point for projects requiring a clear separation between core library functionality and application-specific code, while maintaining a cohesive build system.

Prerequisite

Setup

Commands are supposed to be run from the root directory of project.

  1. Follow the instructions in external libraries
  2. Generate projectfiles

External libraries

First we need to clone VCPKG to our local drive, with the correspondig commit hash used in vcpkg.json. We use VCPKG to as our package manager for all 'potentially' used external libraries.

git clone https://github.com/microsoft/vcpkg.git vcpkg
cd vcpkg
git checkout 91d888703f251c13111c1b889be1f350c4ceb7ab # Corresponds to ID in vcpkg.json

Generate Project Files

From within your desired build directory, in most cases 'build/' in the project root. This well genereate project files for the default generator.

mkdir build
cd build/
cmake ..

you can also specify a specific generator using cmake .. -G <replace_with_other_generator> instead of the default one.