Skip to content

jamesnulliu/VSC-CMake-CXX-Project-Template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VSC-CMake-CXX-Project-Template

A Template of Cross-Platform CMake-C++ Project for Visual Studio Code with Github Actions CI/CD.

1. Environment Setup

1.1. Linux with GCC and Clang

Install the following softwares:

export LLVM_VERSION=20

apt-get install -y \
    git apt-utils lsb-release software-properties-common gnupg  \
    ninja-build pkg-config build-essential gdb curl wget
  
cd /usr/local && git clone https://github.com/microsoft/vcpkg.git && \ 
cd vcpkg && ./bootstrap-vcpkg.sh  && \
wget -O /tmp/kitware-archive.sh \
    https://apt.kitware.com/kitware-archive.sh && \
bash /tmp/kitware-archive.sh && \
apt-get update && apt-get install -y cmake && \
wget -O /tmp/llvm.sh https://apt.llvm.org/llvm.sh && \
chmod +x /tmp/llvm.sh && /tmp/llvm.sh ${LLVM_VERSION} && \
apt-get install -y libomp-${LLVM_VERSION}-dev  

# Add VCPKG_ROOT to environment variables
echo "export VCPKG_ROOT=/usr/local/vcpkg" >> ~/.bashrc
source ~/.bashrc

1.2. Windows with MSVC

If you are using Windows, first install Visual Studio IN DEFAULT INSTALLATION PATH, and then choose the Desktop development with C++ workload.

vcpkg, CMake and Ninja will be installed automatically by Visual Studio Installer.

1.3. Windows with MinGW

You can skip the Visual Studio installation but install MinGW with scoop directly:

# Allow script execution
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

# Install scoop
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression

# Install softwares
scoop install cmake ninja git mingw vcpkg

2. How to Use this Template

2.1. Create Your Own Repository

  1. Click Use this template -> Create a new repository on the top right corner of this page.
  2. Clone your repository to your local machine.

2.2 Generate a Project

Parameters:

  • <project-name>: Name of your project. Can be any valid identifier.
  • <project-type>: Type of the project you want to use. Can be:
    • 0: cxx_exe, a simple C++ executable project.
    • 1: cxx_lib, a C++ lib & test project.
    • 2: cuda_exe, a CUDA executable project.
    • 3: cuda_lib, a CUDA lib & test project.
python ./.templates/gen_project.py -n <project-name> -t <project-type>

2.3. Build a Executable or Library

After generation, build the project by:

bash ./scripts/build.sh

Or if you are using windows and want to use MSVC deliberately, run the following command in Powershell or CMD:

.\scripts\msvc-bash.bat .\scripts\build.sh

Use -h or --help flag to see all available options.

2.4. Reset Project

If you chose a wrong template, don't be worry. Reset the project by:

python ./.templates/gen_project.py --reset

Or directly switch to a new template:

python ./.templates/gen_project.py -n <project-name> -t <project-type>

5. Remove Template

After generating your project, you can remove the ".template" directory by deleting it directly, or use the following command:

python ./.templates/gen_project.py --remove-templates

About

A Template of Cross-Platform CMake-C++ Project for Visual Studio Code with Github Actions CI/CD.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •