A Template of Cross-Platform CMake-C++ Project for Visual Studio Code with Github Actions CI/CD.
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 ~/.bashrcIf 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.
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- Click
Use this template->Create a new repositoryon the top right corner of this page. - Clone your repository to your local machine.
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>After generation, build the project by:
bash ./scripts/build.shOr 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.shUse -h or --help flag to see all available options.
If you chose a wrong template, don't be worry. Reset the project by:
python ./.templates/gen_project.py --resetOr directly switch to a new template:
python ./.templates/gen_project.py -n <project-name> -t <project-type>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