This CMake project serves as a template for C++ and CUDA development. It includes the following directories and files:
my_header_lib: C++ header-only librarymy_static_lib: C++ static librarymy_shared_lib: C++ shared librarymain: Executabletest: Tests using Google Testcuda/cuda_main: (Optional) CUDA executablecuda/my_cuda_lib: (Optional) CUDA static library
Preconfigured linter and formatter settings based on the Google C++ Style Guide are included.
.clang-format: ClangFormat 20.clang-tidy: Clang-Tidy 20.clang-tidy-lower: Lower-case version of the above. Please rename it if needed.
vcpkg is included as a submodule:
vcpkg.json: List of dependencies
Using apt
For Ubuntu 24.04, please install the following:
$ sudo apt install build-essential gdb g++-14 clang-20 clangd-20 cmake ninja-build pkg-configThen, add the clangd path to the .vscode/settings.json file:
{
"clangd.path": "/usr/bin/clangd-20"
}Using Homebrew
If you prefer the latest compiler versions:
$ /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 gdbPlease install Visual Studio (or Build Tools for Visual Studio for command-line use) with the C++ development workload.
To generate compile_commands.json with header files, install compdb:
$ sudo apt install pipx
$ pipx install compdbNote
Note that compdb currently does not 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
-
Please install the following VSCode extensions:
-
Select the compiler and build type in CMake Tools.
-
Press
F7to configure and build the project. -
Press
F1and runclangd: Restart language serverto loadcompile_commands.jsonand restart clangd. -
Press
F5to debug the target executable.- For Linux:
(gdb) Launch - For Windows:
(Windows) Launch - For macOS:
(lldb) Launch- You may need to enable Developer mode:
$ sudo DevToolsSecurity -enable
- For Linux:
-
Untrack the
.vscodedirectory and commit the change.$ git rm --cached -r .vscode $ git commit -m "Remove VSCode settings" -
Remove unnecessary directories and
add_subdirectoryentries inCMakeLists.txt. -
Update project names and directories in
CMakeLists.txtandvcpkg.json. -
Add your dependencies to
CMakeLists.txtandvcpkg.json.
- Update the vcpkg submodule to the specified commit hash.
- Edit the
builtin-baselineinvcpkg.jsonto match the hash above.