From 473eae24bfb905fb6306c04206cdae006ce09b24 Mon Sep 17 00:00:00 2001 From: Jorgen Scott Date: Fri, 29 Dec 2017 08:54:17 +0100 Subject: [PATCH] Added a cmake example --- Configuration-Examples-and-Snippets.md | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Configuration-Examples-and-Snippets.md b/Configuration-Examples-and-Snippets.md index fba7331..ecca531 100644 --- a/Configuration-Examples-and-Snippets.md +++ b/Configuration-Examples-and-Snippets.md @@ -122,4 +122,32 @@ endfunction call airline#parts#define('linenr', {'function': 'MyLineNumber', 'accents': 'bold'}) let g:airline_section_z = airline#section#create(['%3p%%: ', 'linenr', ':%3v']) +``` +## Integrate with CMake build system +This example adds CMAKE_BUILD_TYPE and a custom defined cmake variable by peeking into the CMakeCache.txt +```viml +function! CMakeStat() + let l:cmake_build_dir = get(g:, 'cmake_build_dir', 'build') + let l:build_dir = finddir(l:cmake_build_dir, '.;') + + let l:retstr = "" + if l:build_dir != "" + if filereadable(build_dir . '/CMakeCache.txt') + let cmcache = readfile(build_dir . '/CMakeCache.txt') + for line in cmcache + if line =~ "CMAKE_BUILD_TYPE" + let value = reverse(split(line, '='))[0] + let retstr = retstr . value . " " + elseif line =~ "RUN_TESTS" + let value = reverse(split(line, '='))[0] + let retstr = retstr . "T" . value . " " + endif + endfor + endif + endif + return substitute(retstr, '^\s*\(.\{-}\)\s*$', '\1', '') +endfunction + +call airline#parts#define('cmake', {'function': 'CMakeStat'}) +let g:airline_section_b = airline#section#create_left(['cmake']) ``` \ No newline at end of file