Debug custom targets, and a Docker image to build and develop in
Build / build (pull_request) Successful in 9m40s
Build / build (pull_request) Successful in 9m40s
- 🐞 on a custom target without an executable set debugs the program its command runs, as the build system has it (Ninja's edge, a Makefile's recipe): its arguments, directory and cmake -E env variables; what the target depends on is built first, not the target itself - Debug for custom targets in the status bar, the Targets view and the code lenses above add_custom_target - Dockerfile (Node, CMake, Ninja, g++, GDB), scripts/docker.sh to run a command in it, a dev container, and example/ to try the extension on Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fe6fd8be69
commit
27d924ed06
18 files changed
+300
-9
No files matched your search
@@ -0,0 +1,25 @@
|
||||
# A small project to try the extension on: F5 "Run Extension (example)".
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
project(example CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
add_library(greet src/greet.cpp)
|
||||
target_include_directories(greet PUBLIC src)
|
||||
|
||||
add_executable(hello src/main.cpp)
|
||||
target_link_libraries(hello PRIVATE greet)
|
||||
|
||||
enable_testing()
|
||||
add_executable(greet_test tests/greet_test.cpp)
|
||||
target_link_libraries(greet_test PRIVATE greet)
|
||||
add_test(NAME greet COMMAND greet_test)
|
||||
|
||||
# Custom targets: ▶ builds them (runs their command), 🐞 debugs the program their command runs.
|
||||
add_custom_target(run_hello
|
||||
COMMAND hello CMake
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
COMMENT "Running hello")
|
||||
add_custom_target(run_hello_env
|
||||
COMMAND ${CMAKE_COMMAND} -E env GREETING=hi $<TARGET_FILE:hello> "with spaces"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo done)
|
||||
@@ -0,0 +1,5 @@
|
||||
#include "greet.h"
|
||||
|
||||
std::string greet(const std::string& name) {
|
||||
return "Hello, " + name + "!";
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
std::string greet(const std::string& name);
|
||||
@@ -0,0 +1,7 @@
|
||||
#include <iostream>
|
||||
#include "greet.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::cout << greet(argc > 1 ? argv[1] : "world") << std::endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#include <iostream>
|
||||
#include "greet.h"
|
||||
|
||||
int main() {
|
||||
if (greet("CMake") != "Hello, CMake!") {
|
||||
std::cerr << "unexpected greeting: " << greet("CMake") << std::endl;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user