dev: add cmake-workspace sample
This commit is contained in:
14
editors/vscode/samples/cmake-workspace/CMakeLists.txt
Normal file
14
editors/vscode/samples/cmake-workspace/CMakeLists.txt
Normal 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)
|
||||
21
editors/vscode/samples/cmake-workspace/README.md
Normal file
21
editors/vscode/samples/cmake-workspace/README.md
Normal 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
|
||||
```
|
||||
7
editors/vscode/samples/cmake-workspace/greeting.cc
Normal file
7
editors/vscode/samples/cmake-workspace/greeting.cc
Normal 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.";
|
||||
}
|
||||
6
editors/vscode/samples/cmake-workspace/greeting.h
Normal file
6
editors/vscode/samples/cmake-workspace/greeting.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
std::string build_greeting(std::string_view name);
|
||||
8
editors/vscode/samples/cmake-workspace/main.cc
Normal file
8
editors/vscode/samples/cmake-workspace/main.cc
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "greeting.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << build_greeting("clice") << '\n';
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user