Created
September 12, 2022 22:20
-
-
Save DavidEGrayson/072036c16215cc812212676dbe483c94 to your computer and use it in GitHub Desktop.
Convert GCC command in VSCode configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# Takes a command line for GCC (or similar) on as a file or on its | |
# standard input, extracts the preprocessor macros defined and the | |
# include paths, and outputs them in a format suitable for | |
# pasting into c_cpp_properties.json so that VSCode can understand | |
# your C/C++ project better. | |
require 'json' | |
input = ARGF.read | |
defines = [] | |
include_path = [] | |
input.split do |i| | |
if i.start_with?('-D') | |
defines << i[2..-1] | |
end | |
if i.start_with?('-I') | |
include_path << i[2..-1].sub(/^\/C\//, 'C:/') | |
end | |
end | |
data = {defines: defines, includePath: include_path} | |
puts JSON.generate(data, indent: " ", object_nl: "\n", array_nl: "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment