Can't build a project in Visual Studio Code when there are two build steps, cmake and make
23:00 18 Sep 2025

Visual Studio Code 1.104.1, running on Fedora 42 (Workstation Edition). I can't seem to be able to build a project that requires two build steps, cmake and make. Part of the problem is that I want to be able to build with Ctrl-Shift-B or build/launch with F5, without intervening/extra steps or the use of a shell script to do the heavy lifting. I also want the intermediate files and the executable to be fully segregated by debug vs release.

Here is my CMakeLists.txt file:

cmake_minimum_required(VERSION 3.10)
project(dirsize)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_BUILD_TYPE Debug)

add_compile_options(-Wall -Wextra -Werror)

include_directories(src)

set(SOURCES
    src/dirsize.cpp
)

add_executable(dirsize ${SOURCES})

Here is my tasks.json file:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "build dirsize Debug",
      "type": "shell",
      "command": "${workspaceFolder}/build-debug.sh",
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "problemMatcher": ["$gcc"]
    },
    {
      "label": "build dirsize Release",
      "type": "shell",
      "command": "${workspaceFolder}/build-release.sh",
      "group": "build",
      "problemMatcher": ["$gcc"]
    }
  ]
}

Here is my build-release.sh file:

#!/bin/bash
set -e

mkdir -p build/release
cd build/release

# Configure only if not already configured
if [ ! -f CMakeCache.txt ]; then
  cmake ../.. \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_CXX_FLAGS_RELEASE="-O3 -ffunction-sections -fdata-sections -s -DRELEASE_BUILD" \
    -DCMAKE_EXE_LINKER_FLAGS="-Wl,--gc-sections -s"
  fi
  
make -j$(nproc)
strip dirsize
ls -lh dirsize

(The debug version is very similar.)

The existing system works very well. I just want to avoid the use of the shell script to combine two or three steps into one file.

visual-studio-code cmake makefile