Skip to content

This repository contains examples and tutorials demonstrating how to link multiplaform libraries to C++ for Windows, Linux and macOS projects using CMake.

License

Notifications You must be signed in to change notification settings

Im-Rises/CMake-Cpp-Library-Example

Repository files navigation

CMake-Cpp-Library-Example

cmakeLogo cppLogo cppLogo

Description

This is a set of simple examples of how to use CMake to build C++ projects with different libraries.

All the examples are made to be compiled with CMake for Windows, Linux and macOS, except for some like PThreads that are only available on Linux.

Each directory contains a CMakeLists.txt file that is used to build the library, the complete explanation are in the README.md file of each directory.

List of examples

Emscripten Compilation list

  • Emscripten GLFW OpenGL ES 3.0 WebGL2 compilation
  • Emscripten with React example (WIP)
  • Emscripten SDL2 OpenGL ES 3.0 WebGL2 compilation

Library list

  • OpenMP
  • OpenCL
  • OpenCL C++
  • OpenCV
  • OpenMPI
  • PThreads
  • SDL2
  • SFML

Set of libraries

  • GLFW + GLAD + OpenGL
  • GLFW + GLAD + OpenGL + ImGui
  • SDL2 + GLAD + OpenGL
  • SDL2 + GLAD + OpenGL + ImGui
  • GLFW + Vulkan
  • GLFW + Vulkan + ImGui

Library not documented

  • Boost
  • Qt
  • ...

C++ Modules with CMake

  • CMake C++20 with modules project

How to compile

According to your OS, the build setup is different. Check the appropriate indication according to the README.md file of each directory.

You will need cmake to build the project. You can download it here:
https://cmake.org/download/

Note: If you are using an IDE, the project build selection is integrated in it. You do not need the command line to build the project.

Build all projects by command line

Once you have set up your OS you can now build the project. You can either load it with your IDE (Visual Studio, Clion, etc...), or use the command line.

To use the command line build, type the following command at the project root folder.

cmake -B <build directory> -DCMAKE_BUILD_TYPE=<build optimization flag>

example:

cmake -B ./build -DCMAKE_BUILD_TYPE=Release

Then type

cmake --build <build directory> --config <build optimization flag>

example:

cmake --build ./build --config Release

Build a specific project by command line

To build a specific project, you can use the following command:

cmake -S . -B build -D PROJECT_TO_BUILD=<project name> -DCMAKE_BUILD_TYPE=<build optimization flag>

example:

cmake -S . -B ./build -D PROJECT_TO_BUILD=Lib_OpenMP -DCMAKE_BUILD_TYPE=Release

Then type

cmake --build <build directory> --config <build optimization flag>

example:

cmake --build ./build --config Release

Note You can build several projects at the same time by separating the project names with a semicolon. example:

cmake -S . -B ./build -D PROJECT_TO_BUILD="Lib_OpenMP;Lib_OpenCL" -DCMAKE_BUILD_TYPE=Release

Libraries

EmScripten:
https://emscripten.org/

OpenCL:
https://www.khronos.org/opencl/

OpenCV:
https://opencv.org/

OpenMP:
https://www.openmp.org/

OpenMPI:
https://www.open-mpi.org/

SDL2:
https://www.libsdl.org/

SFML:
https://www.sfml-dev.org/

GLFW:
https://www.glfw.org/

GLAD:
https://glad.dav1d.de/

ImGui:
https://github.com/ocornut/imgui

OpenGL:
https://www.opengl.org/

Documentation

cliutils:
https://cliutils.gitlab.io/modern-cmake/chapters/packages/OpenMP.html

GitHub Actions

CMake Emscripten-CMake cpp-linter

The project is set with a set of different scripts:

  • CMake: This script is used to build the project.
  • Cpp Linter: This script is used to check the code quality.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributors

Quentin MOREL:

GitHub contributors