Skip to content

yosh-matsuda/vscode-cpp-cuda-cmake-template

Repository files navigation

CMake C++/CUDA multi-platform template for Visual Studio Code

This CMake project contains the following directories and files:

  • my_header_lib: C++ header-only library
  • my_static_lib: C++ static library
  • my_shared_lib: C++ shared library
  • main: Executable
  • test: Test with Google Test
  • cuda/cuda_main: (option) CUDA executable
  • cuda/my_cuda_lib: (option) CUDA static library

The preconfigured linter and formatter settings based on the Google C++ Style Guide are included.

The vcpkg is included as a submodule:

  • vcpkg.json: List of dependencies

Setting up C++ environment

Linux

Using apt

For Ubuntu 22.04:

$ sudo apt install build-essential gdb g++-12 clang-14 cmake ninja-build pkg-config

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 gdb

MacOS

Using Apple Clang

$ xcode-select –install

Using homebrew

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
$ brew install gcc llvm cmake ninja gdb

Windows

Install Visual Studio (or Build Tools for Visual Studio for command line only) with C++ development workload.

Other dependencies

To generate compile_commands.json with header files, install compdb

$ python3 -m pip install compdb

Note

Currently, compdb does not seem to support Windows.

Getting started

Open the project template

  1. Clone this repository with --recursive to include submodules.
    $ git clone --recursive https://github.com/yosh-matsuda/vscode-cpp-cuda-cmake-template.git
  2. Open the project in VSCode.
    $ code vscode-cpp-cuda-cmake-template
  3. Install VSCode extensions

Build and run

  1. Select compiler and build type in CMake Tools.
  2. Press F7 to configure and build the project.
  3. Press F1 and run clangd: Restart language server to load compile_commands.json and clangd will restart.
  4. Press F5 to debug the target executable.
    • (gdb) Launch for Linux
    • (Windows) Launch for Windows
    • (lldb) Launch for MacOS
      • You may need to enable the Developer mode
        $ sudo DevToolsSecurity -enable

Start your project

  1. Untrack the .vscode directory and commit.
    $ git rm --cached -r .vscode
    $ git commit -m "Remove VSCode settings"
  2. Delete unnecessary directories and add_subdirectory in CMakeLists.txt.
  3. Change the project names and directories in CMakeLists.txt and vcpkg.json.
  4. Add your dependencies to CMakeLists.txt and vcpkg.json.

Update vcpkg

  1. Update vcpkg submodule to the specified commit hash.
  2. Edit the builtin-baseline in vcpkg.json to put the same hash as above.

About

CMake C++/CUDA multi-platform template for Visual Studio Code

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published