diff --git a/plugin/cmake.vim b/plugin/cmake.vim
index af10862..fadb8cb 100644
--- a/plugin/cmake.vim
+++ b/plugin/cmake.vim
@@ -1,14 +1,23 @@
" cmake.vim - Vim plugin to make working with CMake a little nicer
" Maintainer: Dirk Van Haerenborgh
-" Version: 0.2
+" Version: 0.3
let s:cmake_plugin_version = '0.2'
-if exists("loaded_cmake_plugin")
+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
@@ -24,62 +33,74 @@ command! -nargs=? CMake call s:cmake()
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
- let s:build_dir = finddir('build', '.;')
-
if s:build_dir !=""
-
- let &makeprg='cmake --build ' . shellescape(s:build_dir) . ' --target '
+ let &makeprg='cmake --build ' . s:build_dir
exec 'cd' s:fnameescape(s:build_dir)
- let s:cleanbuild = 0
let l:argument=[]
- if exists("g:cmake_install_prefix")
- let l:argument+= [ "-DCMAKE_INSTALL_PREFIX:FILEPATH=" . g:cmake_install_prefix ]
+ 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 ]
+ 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:argument+= [ "-DCMAKE_CXX_COMPILER:FILEPATH=" . g:cmake_cxx_compiler ]
- let s:cleanbuild = 1
+ if exists('g:cmake_cxx_compiler')
+ let l:environment+= [ 'CXX="' . g:cmake_cxx_compiler . '"']
endif
- if exists("g:cmake_c_compiler")
- let l:argument+= [ "-DCMAKE_C_COMPILER:FILEPATH=" . g:cmake_c_compiler ]
- let s:cleanbuild = 1
+ 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 ]
+ if exists('g:cmake_build_shared_libs')
+ let l:argument+= [ '-DBUILD_SHARED_LIBS:BOOL=' . g:cmake_build_shared_libs ]
endif
- let l:argumentstr = join(l:argument, " ")
+ let l:environmentstr = join(l:environment, ' ')
+ let l:argumentstr = join(l:argument, ' ')
- if s:cleanbuild > 0
- echo system("rm -r *" )
- endif
-
- let s:cmd = 'cmake '. l:argumentstr . join(a:000) .' .. '
+ 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."
+ echo 'Unable to find build directory.'
endif
endfunction
function! s:cmakeclean()
- let s:build_dir = finddir('build', '.;')
- if s:build_dir !=""
- echo system("rm -r " . s:build_dir. "/*" )
- echo "Build directory has been cleaned."
+ 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
- echo "Unable to find build directory."
+ 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