Skip to content

Commit 26b0074

Browse files
committed
Make: Build just 1 target for VS Code debug
1 parent e7b4b9e commit 26b0074

File tree

3 files changed

+94
-3
lines changed

3 files changed

+94
-3
lines changed

.vscode/build_current.cmake

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# build_current.cmake
2+
# Cross-platform script to build the current file's target
3+
#
4+
# Usage: cmake -DFILE=<file> -DBUILD_TYPE=<Debug|Release> -P build_current.cmake
5+
6+
cmake_minimum_required(VERSION 3.14)
7+
8+
if (NOT DEFINED FILE)
9+
message(FATAL_ERROR "FILE not specified. Usage: cmake -DFILE=path/to/file.cpp -P build_current.cmake")
10+
endif ()
11+
12+
if (NOT DEFINED BUILD_TYPE)
13+
set(BUILD_TYPE "Debug")
14+
message(STATUS "BUILD_TYPE not specified, defaulting to Debug")
15+
endif ()
16+
17+
# Extract basename without extension
18+
get_filename_component(BASENAME "${FILE}" NAME_WE)
19+
20+
# Map filename patterns to CMake targets
21+
if (BASENAME MATCHES "^bench_(.+)$")
22+
# Benchmark files: bench_find.cpp -> stringzilla_bench_find_cpp20
23+
set(TARGET "stringzilla_${BASENAME}_cpp20")
24+
else ()
25+
message(FATAL_ERROR "Unknown file pattern: ${BASENAME}\nSupported patterns:\n - bench_*.cpp\n - test_stringzilla.cpp\n - test_stringzillas.cpp")
26+
endif ()
27+
28+
# Determine build directory
29+
string(TOLOWER "${BUILD_TYPE}" build_type_lower)
30+
set(BUILD_DIR "${CMAKE_CURRENT_LIST_DIR}/../build_${build_type_lower}")
31+
32+
# Verify build directory exists
33+
if (NOT EXISTS "${BUILD_DIR}")
34+
message(FATAL_ERROR "Build directory not found: ${BUILD_DIR}\nRun: cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -B ${BUILD_DIR}")
35+
endif ()
36+
37+
message(STATUS "Building target: ${TARGET}")
38+
message(STATUS "Build directory: ${BUILD_DIR}")
39+
message(STATUS "Build type: ${BUILD_TYPE}")
40+
41+
# Execute the build
42+
execute_process(
43+
COMMAND cmake --build ${BUILD_DIR} --config ${BUILD_TYPE} --target ${TARGET}
44+
RESULT_VARIABLE result
45+
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/..
46+
)
47+
48+
if (result EQUAL 0)
49+
message(STATUS "Build succeeded: ${TARGET}")
50+
else ()
51+
message(FATAL_ERROR "Build failed with exit code: ${result}")
52+
endif ()

.vscode/launch.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,17 @@
106106
"name": "ASAN_OPTIONS",
107107
"value": "detect_leaks=0:atexit=1:strict_init_order=1:strict_string_checks=1"
108108
},
109+
{
110+
"name": "STRINGWARS_TOKENS",
111+
"value": "file"
112+
},
109113
{
110114
"name": "STRINGWARS_DATASET",
111115
"value": "utf8.txt"
112116
}
113117
],
114118
"stopAtEntry": false,
115-
"preLaunchTask": "Build Benchmarks: Debug",
119+
"preLaunchTask": "Build Current File: Debug",
116120
"linux": {
117121
"MIMode": "gdb",
118122
"setupCommands": [
@@ -149,7 +153,7 @@
149153
}
150154
],
151155
"stopAtEntry": false,
152-
"preLaunchTask": "Build Benchmarks: Debug",
156+
"preLaunchTask": "Build Current File: Debug",
153157
"linux": {
154158
"MIMode": "gdb",
155159
"setupCommands": [
@@ -182,7 +186,7 @@
182186
}
183187
],
184188
"stopAtEntry": false,
185-
"preLaunchTask": "Build Benchmarks: Debug"
189+
"preLaunchTask": "Build Current File: Debug"
186190
},
187191
{
188192
"name": "Current Python File",

.vscode/tasks.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,41 @@
7878
}
7979
]
8080
}
81+
},
82+
{
83+
"label": "Build Current File: Debug",
84+
"command": "cmake",
85+
"args": [
86+
"-DFILE=${file}",
87+
"-DBUILD_TYPE=Debug",
88+
"-P",
89+
"${workspaceFolder}/.vscode/build_current.cmake"
90+
],
91+
"type": "shell",
92+
"group": {
93+
"kind": "build",
94+
"isDefault": true
95+
},
96+
"presentation": {
97+
"reveal": "always",
98+
"panel": "shared"
99+
}
100+
},
101+
{
102+
"label": "Build Current File: Release",
103+
"command": "cmake",
104+
"args": [
105+
"-DFILE=${file}",
106+
"-DBUILD_TYPE=Release",
107+
"-P",
108+
"${workspaceFolder}/.vscode/build_current.cmake"
109+
],
110+
"type": "shell",
111+
"group": "build",
112+
"presentation": {
113+
"reveal": "always",
114+
"panel": "shared"
115+
}
81116
}
82117
]
83118
}

0 commit comments

Comments
 (0)