This CMake project contains the following directories and files:
my_header_lib: C++ header-only librarymy_static_lib: C++ static librarymy_shared_lib: C++ shared librarymain: Executabletest: Test with Google Testcuda/cuda_main: (option) CUDA executablecuda/my_cuda_lib: (option) CUDA static library
The preconfigured linter and formatter settings based on the Google C++ Style Guide are included.
.clang-format: ClangFormat 19.clang-tidy: Clang-Tidy 19
The vcpkg is included as a submodule:
vcpkg.json: List of dependencies
Using apt
For Ubuntu 24.04:
$ sudo apt install build-essential gdb g++-14 clang-19 clangd-19 cmake ninja-build pkg-configAdd clangd path to the .vscode/settings.json file:
{
"clangd.path": "/usr/bin/clangd-19",
}Using homebrew
For those who want to use the latest version of the compiler:
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
$ brew install gcc llvm cmake ninja gdbUsing Apple Clang
$ xcode-select –installUsing homebrew
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
$ brew install gcc llvm cmake ninja gdbInstall Visual Studio (or Build Tools for Visual Studio for command line only) with C++ development workload.
To generate compile_commands.json with header files, install compdb
$ sudo apt install pipx
$ pipx install compdbNote
Currently, compdb does not seem to support Windows.
- Clone this repository with
--recursiveto include submodules.$ git clone --recursive https://github.com/yosh-matsuda/vscode-cpp-cuda-cmake-template.git
- Open the project in VSCode.
$ code vscode-cpp-cuda-cmake-template
- Install VSCode extensions
- Select compiler and build type in CMake Tools.
- Press
F7to configure and build the project. - Press
F1and runclangd: Restart language serverto loadcompile_commands.jsonand clangd will restart. - Press
F5to debug the target executable.(gdb) Launchfor Linux(Windows) Launchfor Windows(lldb) Launchfor MacOS- You may need to enable the Developer mode
$ sudo DevToolsSecurity -enable
- You may need to enable the Developer mode
- Untrack the
.vscodedirectory and commit.$ git rm --cached -r .vscode $ git commit -m "Remove VSCode settings" - Delete unnecessary directories and
add_subdirectoryinCMakeLists.txt. - Change the project names and directories in
CMakeLists.txtandvcpkg.json. - Add your dependencies to
CMakeLists.txtandvcpkg.json.
- Update vcpkg submodule to the specified commit hash.
- Edit the
builtin-baselineinvcpkg.jsonto put the same hash as above.