Skip to content

Using environment variables to set the compiler now. Also I added a n… #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 53 additions & 32 deletions plugin/cmake.vim
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
" cmake.vim - Vim plugin to make working with CMake a little nicer
" Maintainer: Dirk Van Haerenborgh <http://vhdirk.github.com/>
" 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(<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

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