I have been trying to play with SublimeText2 for some time now. While it is very easy to work with Python in it almost out of the box, working with C++ is a bit more tricky. I can manage to set up a CMake build script by copying and modifying the existing Makefile script, but there are many things that just don't work as they do in a CMake supported IDE, like Eclipse CDT. SublimeText 2 does not seem to understand the concept of a separate build directory, it also cannot get me autocomplete through SublimeClang, if I include the libraries with reference to the directories added in CMake. SublimeClang keeps complaining that it cannot find the libraries, and when I try to #include
, it cannot even offer me autocomplete on standard STL header file names, e.g., algorithm. If someone has a pipeline figured out, I would be obliged to hear about it.
I have asked this question in more general purpose usage-related forums before, where I did not get any response, which is why I thought of posting it here.
I use Sublime Text 2 with CMake and SublimeClang. I also use SublimeGDB. My build directory is under [project root]/build
. Have a look at my project file and see if it helps you:
{
"folders":
[
{
"path": "."
}
],
"build_systems":
[
{
"name": "Build",
"cmd": [ "make", "-C", "build" ],
"file_regex": "/([^/:]+):(\\d+):(\\d+): "
}
],
"settings":
{
"sublimegdb_commandline": "gdb --interpreter=mi myapp",
"sublimegdb_workingdir": "build",
"sublimeclang_options" :
[
"-Wno-reorder"
],
"sublimeclang_options_script": "${project_path:scripts/compileflags.rb} ${project_path:build}"
}
}
The compileflags.rb
script is used to search for flags.make
files in the CMake build tree which is where CMake keeps its compile flags. These flags are needed so that SublimeClang knows where to find your includes.
Here is that script, located under scripts/
:
#!/usr/bin/env ruby
# Searches for a flags.make in a CMake build tree and prints the compile flags.
def search_dir(dir, &block)
Dir.foreach(dir) do |filename|
next if (filename == ".") || (filename == "..")
path ="#{dir}/#{filename}"
if File.directory?(path)
search_dir(path, &block)
else
search_file(path, &block)
end
end
end
def search_file(filename)
return if File.basename(filename) != "flags.make"
File.open(filename) do |io|
io.read.scan(/[a-zA-Z]+_(?:FLAGS|DEFINES)\s*=\s*(.*)$/) do |match|
yield(match.first.split(/\s+/))
end
end
end
root = ARGV.empty? ? Dir.pwd : ARGV[0]
params = to_enum(:search_dir, root).reduce { |a, b| a | b }
puts params
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With