Skip to content
/ cpp-cmake-template Public template

Template project for C++ and C projects built with CMake using GCC or LLVM

License

Notifications You must be signed in to change notification settings

robamu/cpp-cmake-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ and C project template

Project template for building C++ and C projects with CMake and various different compilers and IDEs. Install CMake first.

All builds displayed here are for Debug configurations. To build for release, replace Debug with Release in the folder names and and add -DCMAKE_BUILD_TYPE=Release to the CMake build command.

Windows - GCC

Using MinGW Makefiles

Install MSYS2 first. All command line steps here were done in MinGW64. Set up MinGW64:

pacman -Syuu
pacman -S git mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake
git config --global core.autocrlf true

Then build the application with

mkdir build-MinGW64 && cd build-MinGW64
cmake -G "MinGW Makefiles" ..
cmake --build . -j

Using Visual Studio Code

Make sure you can build the application with MinGW64 like specified above. After that there are good instructions on how to set up Visual Studio Code here. A workspace file is provided as well to get started quickly.

Using Eclipse

Copy the .project and .cproject file found in misc/eclipse into the project root and open the folder in Eclipse with Open Project from Filesystem. Build configurations and launch files for MinGW were provided. You have to generate the build system with CMake via command line first before you can Build, Run and Debug with Eclipse.

Windows - MSVC

Using Visual Studio

Install Visual Studio. You can generate Visual Studio project files with the following command (here, for Visual Studio 2019)

mkdir Debug-VS2019
cd Debug-VS2019
cmake .. -G "Visual Studio 16 2019"

After that, a .sln project file is generated which you can open with Visual Studio 2019.

Using Visual Studio Code

Instructions can be found here. Not tested yet.

Windows - LLVM

Using MinGW Makefiles

Install LLVM first. Perform the same set-up as specified above for MinGW64.

Ensure you can call clang --version from the command line by adding the LLVM binary path to the MinGW64 path as well, for example by adding the following line in the ~/.bashrc file

export PATH=$PATH:"/c/Program Files/LLVM/bin"

If everything was set up correctly, you can build the application with clang

mkdir build-MinGW64 && cd build-MinGW64
cmake -G "MinGW Makefiles" -DUSE_LLVM=ON ..
cmake --build . -j

Linux - GCC

Using GCC and Unix Makefiles

Instructions for Ubuntu, adapt accordingly Install required packages and tools first

sudo apt-get update
sudo apt-get install build-essential gdb

Build the project like this:

mkdir Debug-Unix
cd Debug-Unix
cmake .. 
cmake --build . -j

Using Eclipse

There are two Eclipse files .project and .cproject located inside the misc/eclipse folder. IN the .project file, change the name to your project folder name. After that, copy both files into the project root and open the folder in Eclipse with Open Project from Filesystem. Build configurations and launch files for Unix systems were provided. You have to generate the build system with CMake via command line first before you can Build, Run and Debug with Eclipse.

Using Visual Studio Code

Make sure you can build the application like specified above. After that there are good instructions on how to set up Visual Studio Code here

Linux - LLVM

Install LLVM first.

If everything was set up correctly, you can build the application with clang

mkdir build && cd build
cmake -DUSE_LLVM=ON ..
cmake --build . -j

About

Template project for C++ and C projects built with CMake using GCC or LLVM

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published