Skip to content

Instantly share code, notes, and snippets.

@TSedlar
Created September 22, 2018 03:59
Show Gist options
  • Save TSedlar/a7490b24d781de3715435db7c67b1435 to your computer and use it in GitHub Desktop.
Save TSedlar/a7490b24d781de3715435db7c67b1435 to your computer and use it in GitHub Desktop.
CMake & Make VSCode setup
cmake_minimum_required(VERSION 3.2)
include("cmake/HunterGate.cmake")
HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.10.9.tar.gz"
SHA1 "53b198e364dc7bc8360fc545f798563229bd7e20"
)
hunter_add_package(Boost COMPONENTS regex system filesystem)
find_package(Boost CONFIG REQUIRED regex system filesystem)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ./bin)
file(GLOB children src/ src/*/)
foreach(child ${children})
get_filename_component(dirname "${child}" NAME)
project(${dirname})
set(FILE_SRCS, "")
file(GLOB FILE_SRCS "${child}/*.cpp")
add_executable(${dirname} ${FILE_SRCS})
target_link_libraries(${dirname} PUBLIC Boost::regex Boost::system Boost::filesystem)
endforeach()
// place in .vscode
// plugins required:
// - ext install fabiospampinato.vscode-terminals
// - ext install fabiospampinato.vscode-commands
// - ext install ryuta46.multi-command
const path = require('path')
const fs = require('fs')
const HOME = path.join(__dirname, '../')
let terminals = {
"autorun": false,
"terminals": [
{
"name": "CMake",
"focus": true,
"commands": [
"cmake .",
"exit 0"
],
"cwd": HOME
},
{
"name": "Make",
"focus": true,
"command": "make all",
"cwd": HOME
},
{
"name": "Update Settings",
"focus": true,
"commands": [
"node .vscode/update-workspace.js",
"exit 0"
],
"cwd": HOME
}
]
}
let settings = {
"files.watcherExclude": {
"**/libs/**": true
},
"multiCommand.commands": [
{
"command": `multiCommand.make-and-update`,
"interval": 500,
"sequence": [
{"command": "terminals.runTerminalByName", "args": "CMake"},
{"command": "terminals.runTerminalByName", "args": "Make"},
{"command": "terminals.runTerminalByName", "args": "Update Settings"},
"commands.refresh"
]
}
]
}
let commands = {
"commands": [
{
"text": "",
"command": "multiCommand.make-and-update",
"tooltip": "Run Make"
}
]
}
let binDir = path.join(__dirname, '../bin')
let bins = fs.readdirSync(binDir)
for (let bin of bins) {
terminals['terminals'].push({
"name": bin,
"focus": true,
"command": `./${bin}`,
"cwd": binDir
})
commands['commands'].push({
"text": bin,
"command": `terminals.runTerminalByName`,
"arguments": [bin],
"tooltip": `Run ${bin}`
})
}
let terminalsFile = path.join(__dirname, '/terminals.json')
let settingsFile = path.join(__dirname, '/settings.json')
let commandsFile = path.join(__dirname, '/commands.json')
fs.writeFileSync(terminalsFile, JSON.stringify(terminals, null, 2), 'utf-8')
fs.writeFileSync(settingsFile, JSON.stringify(settings, null, 2), 'utf-8')
fs.writeFileSync(commandsFile, JSON.stringify(commands, null, 2), 'utf-8')
console.log('Updated workspace')
@TSedlar
Copy link
Author

TSedlar commented Sep 22, 2018

Place update-workspace.js inside of .vscode, and run it one time initially.

It creates the gears on the bottom left of the status bar (if you installed the three plugins listed in the js file).

Upon clicking the gears, it will create the CMake configuration and run make all, then it will add a runnable button of the binary that is listed inside of the output bin directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment