Configure, build and test a CMake project right from within Sublime Text 3.
Run the command
Package Control: Install Package
and look for CMakeBuilder.
Version 1.0.1 and lower do not have server functionality. What follows is the documentation for version 1.0.1 and lower.
-
Open a
.sublime-project
. -
Add this to the project file in your
"settings"
:"cmake": { "build_folder": "$folder/build" }
-
Run the command "CMakeBuilder: Configure" from the command palette.
-
Check out your new build system in your
.sublime-project
. -
Press CTRL + B or ⌘ + B.
-
Hit F4 to jump to errors and/or warnings.
See the example project below for more options.
By "CMake dictionary" we mean the JSON dictionary that you define in your
"settings"
of your sublime project file with key "cmake"
. The CMake
dictionary accepts the following keys:
-
build_folder
[required string]A string pointing to the directory where you want to build the project. A good first choice is
$folder/build
. -
command_line_overrides
[optional dictionary]A dictionary where each value is either a string or a boolean. The key-value pairs are passed to the CMake invocation when you run
cmake_configure
as-D
options. For example, if you have the key-value pair"MY_VAR": "BLOB"
in the dictionary, the CMake invocation will contain-D MY_VAR=BLOB
. Boolean values are converted toON
orOFF
. For instance, if you have the key-value pair"BUILD_SHARED_LIBS": true
in the dictionary, the CMake invocation will contain-D BUILD_SHARED_LIBS=ON
. -
generator
[optional string]A JSON string specifying the CMake generator.
-
Available generators for osx: "Ninja" and "Unix Makefiles".
If no generator is specified on osx, "Unix Makefiles" is the default generator. For "Ninja", you must have ninja installed. Install it with brew.
-
Available generators for linux: "Ninja" and "Unix Makefiles".
If no generator is specified on osx, "Unix Makefiles" is the default generator. For "Ninja", you must have ninja installed. Install it with apt.
-
Available generators for windows: "Ninja" and "Visual Studio".
If no generator is specified on windows, "Visual Studio" is the default generator. You need Microsoft Visual Studio C++ in order to configure your project wether you're using Ninja or Visual Studio.
-
-
root_folder
[optional string]The directory where the root CMakeLists.txt file resides. If this key is not present, the directory where the sublime project file is located is assumed to have the root CMakeLists.txt file.
-
env
[optional dictionary]This is a dict of key-value pairs of strings. Place your environment variables at configure time in here. For example, to select clang as your compiler if you have gcc set as default, you can use
"env": { "CC": "clang", "CXX": "clang++" }
-
platform
[optional string]For generators that support a platform argument. In the case of this plugin that would be Visual Studio. In practise, set this to "x64" to build 64-bit binaries instead of the default 32-bit. This is the
-A
argument passed to CMake. -
toolset
[optional dictionary]For generators that support a toolset argument. In the case of this plugin that would be Visual Studio. In practise, set this to
{ "host": "x64" }
to use the 64-bit compiler instead of the 32-bit compiler. This is the-T
argument passed to CMake. As in the case ofcommand_line_overrides
, the dictionary is converted into a string as inkey1=value1;key2=value2
. -
vs_major_version
[optional integer]When using the Ninja generator on Windows, by default it will use the most recent Visual Studio SDK on the system. If you need another SDK, define the
vs_major_version
number to be 15 or 16.
Any key may be overridden by a platform-specific override. The platform keys
are one of "linux"
, "osx"
or "windows"
. For an example on how this works,
see below.
Here is an example Sublime project to get you started.
{
"folders":
[
{
"path": "."
}
],
"settings":
{
"cmake":
{
"build_folder": "$folder/build",
"command_line_overrides":
{
"BUILD_SHARED_LIBS": true,
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_EXPORT_COMPILE_COMMANDS": true
},
"generator": "Unix Makefiles",
"windows":
{
"generator": "Visual Studio 15 2017",
"platform": "x64",
"toolset": { "host": "x64" }
}
}
}
}
cmake_clear_cache
, arguments:{ with_confirmation : bool }
.cmake_configure
, arguments:None
.cmake_diagnose
, arguments:None
.cmake_open_build_folder
, arguments:None
.
CMakeBuilder: Clear Cache
CMakeBuilder: Configure
CMakeBuilder: Diagnose
CMakeBuilder: Browse Build Folder...
All commands are accessible via both the command palette as well as the tools menu at the top of the window.
-
silence_developer_warnings
: JSON boolIf true, will add the option
-Wno-dev
to the CMake invocation of thecmake_configure
command. -
always_clear_cache_before_configure
: JSON boolIf true, always clears the CMake cache before the
cmake_configure
command is run. -
ctest_command_line_args
: JSON stringCommand line arguments passed to the CTest invocation when you run
cmake_run_ctest
.
To force CMake files re-generation run
CMakeBuilder: Clear Cache
and then run
CMakeBuilder: Configure
If you get stuck and don't know what to do, try running
CMakeBuilder: Diagnose
All commands are also visible in the Tools menu under "CMakeBuilder".
If you have unit tests configured with the add_test function of CMake, then you can run those with the "ctest" build variant.
There is syntax highlighting when building a target, and a suitable line regex is set up for each generator so that you can press F4 to go to an error.
This is a reference list for the valid variable substitutions for your
.sublime-project
file.
- packages
- platform
- file
- file_path
- file_name
- file_base_name
- file_extension
- folder
- project
- project_path
- project_name
- project_base_name
- project_extension