-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathcmake.vim
More file actions
106 lines (89 loc) · 2.82 KB
/
cmake.vim
File metadata and controls
106 lines (89 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
" cmake.vim - Vim plugin to make working with CMake a little nicer
" Maintainer: Dirk Van Haerenborgh <http://vhdirk.github.com/>
" Version: 0.3
let s:cmake_plugin_version = '0.2'
if exists('loaded_cmake_plugin')
finish
endif
let loaded_cmake_plugin = 1
" Allow the user to select custom build and source directories
" Off by default
if !exists('g:cmake_custom_dirs')
let g:cmake_custom_dirs = 0
endif
let s:build_dir = ''
let s:source_dir = ''
" Utility function
" Thanks to tpope/vim-fugitive
function! s:fnameescape(file) abort
if exists('*fnameescape')
return fnameescape(a:file)
else
return escape(a:file," \t\n*?[{`$\\%#'\"|!<")
endif
endfunction
" Public Interface:
command! -nargs=? CMake call s:cmake(<f-args>)
command! CMakeClean call s:cmakeclean()
function! s:cmake(...)
if g:cmake_custom_dirs
let s:build_dir = input ('Build directory: ', getcwd())
let s:source_dir = input ('Source directory: ', getcwd())
echo ' '
else
let s:build_dir = finddir('build', '.;')
let s:source_dir = ".."
endif
if s:build_dir !=""
let &makeprg='cmake --build ' . s:build_dir
exec 'cd' s:fnameescape(s:build_dir)
let l:argument=[]
let l:environment=[]
if exists('g:cmake_install_prefix')
let l:argument+= [ '-DCMAKE_INSTALL_PREFIX:FILEPATH=' . g:cmake_install_prefix ]
endif
if exists('g:cmake_build_type' )
let l:argument+= [ '-DCMAKE_BUILD_TYPE:STRING=' . g:cmake_build_type ]
endif
if exists('g:cmake_cxx_compiler')
let l:environment+= [ 'CXX="' . g:cmake_cxx_compiler . '"']
endif
if exists('g:cmake_c_compiler')
let l:environment+= [ 'CC="' . g:cmake_c_compiler . '"' ]
endif
if exists('g:cmake_build_shared_libs')
let l:argument+= [ '-DBUILD_SHARED_LIBS:BOOL=' . g:cmake_build_shared_libs ]
endif
let l:environmentstr = join(l:environment, ' ')
let l:argumentstr = join(l:argument, ' ')
let s:cmd = l:environmentstr . ' cmake ' . l:argumentstr . join(a:000) . ' ' . s:source_dir . ' '
echo s:cmd
let s:res = system(s:cmd)
echo s:res
exec 'cd - '
else
echo 'Unable to find build directory.'
endif
endfunction
function! s:cmakeclean()
if g:cmake_custom_dirs
if s:build_dir !=''
exec 'cd' s:fnameescape(s:build_dir)
echo system('make clean')
echo system('rm -r CMakeFiles' )
echo system('rm CMakeCache.txt' )
echo system('rm cmake_install.cmake' )
echo 'Build directory has been cleaned.'
exec 'cd - '
else
echo "Unable to find build directory."
endif
else
if s:build_dir !=""
echo system("rm -r " . s:build_dir. "/*" )
echo 'Build directory has been cleaned.'
else
echo 'Unable to find build directory.'
endif
endif
endfunction