Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jimli570/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.
https://github.com/jimli570/cplusplus-cmake-template

cmake cplusplus

Last synced: about 1 month ago
JSON representation

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.

Awesome Lists containing this project

README

        

# 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

- CMake version >= 3.15
- Download from:
- A C++ compiler and build system (e.g., Visual Studio, GCC, Clang)
- For Visual Studio:

## 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.

```bash
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.

```bash
mkdir build
cd build/
cmake ..
```

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