dev: add cmake-workspace sample

This commit is contained in:
Myriad-Dreamin
2026-04-03 23:48:08 +08:00
parent 72c0a74609
commit a303e13f58
5 changed files with 56 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.16)
project(clice_vscode_cmake_sample LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_library(sample_greeting greeting.cc)
target_include_directories(sample_greeting PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(sample_app main.cc)
target_link_libraries(sample_app PRIVATE sample_greeting)

View File

@@ -0,0 +1,21 @@
# VS Code CMake Sample
This workspace is a standalone CMake project for attaching the VS Code extension to a real `clice` session.
`clice` already auto-detects `build/compile_commands.json`, so this sample does not need any helper scripts or extra CMake glue.
## Prepare The Workspace
From this directory:
```sh
cmake -S . -B build -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
```
That is enough to generate `build/compile_commands.json`, which `clice` can discover automatically when this folder is opened as the workspace.
If you also want the sample binary:
```sh
cmake --build build
```

View File

@@ -0,0 +1,7 @@
#include "greeting.h"
#include <string>
std::string build_greeting(std::string_view name) {
return "Hello, " + std::string(name) + " from the CMake sample.";
}

View File

@@ -0,0 +1,6 @@
#pragma once
#include <string>
#include <string_view>
std::string build_greeting(std::string_view name);

View File

@@ -0,0 +1,8 @@
#include "greeting.h"
#include <iostream>
int main() {
std::cout << build_greeting("clice") << '\n';
return 0;
}