Permalink
Browse files

Merge branch 'release/0.3.0'

* release/0.3.0:
  Updated commands and utilities.
  Tightened use of CMake command detection.
  Dropped the need for a tailing 'if' block.
  Ensured commands were added only on CMake project buffers.
  Ensured proper setting of the makeprg.
  Made less logic jumps.
  Changed bangs on functions and added Dispatch.
  Updated plugin logic.
  I didn't even need this.
  Touched up flags.
  • Loading branch information...
2 parents 266e2cb + 3cbdd06 commit 0991dc0bcc4286d1494b164af89cf4bb8e838c05 @jalcine committed Mar 2, 2014
Showing with 109 additions and 138 deletions.
  1. +31 −39 autoload/cmake/commands.vim
  2. +42 −52 autoload/cmake/flags.vim
  3. +9 −10 autoload/cmake/targets.vim
  4. +25 −31 autoload/cmake/util.vim
  5. +2 −2 plugin/cmake.vim
  6. +0 −4 python/vim/cmake.py
@@ -1,5 +1,5 @@
" File: autoload/cmake/commands.vim
-" Description: The "API" of cmake.vim.
+" Description: The API of 'cmake.vim'.
" Author: Jacky Alciné <me@jalcine.me>
" License: MIT
" Website: https://jalcine.github.io/cmake.vim
@@ -8,20 +8,22 @@
func! cmake#commands#build()
echomsg "[cmake] Building all targets..."
- let l:output = cmake#util#run_cmake("--build", "","")
- if l:output != 0
- echomsg l:output
- echomsg "[cmake] Built all targets."
- end
+ call cmake#util#run_cmake("--build", "","")
+ echomsg "[cmake] Built all targets."
endfunc
func! cmake#commands#invoke_target(target)
echomsg "[cmake] Invoking target '" . a:target . "'..."
- call cmake#util#run_cmake("--build ". cmake#util#binary_dir() . " --target " . a:target. " --", "", "")
+ call cmake#util#run_cmake("--build ". cmake#util#binary_dir() .
+ \ " --target " . a:target. " --", "", "")
+endfunc
+
+func! cmake#commands#build_current()
+ call cmake#commands#build_target_for_file(fnamemodify(bufname('%'), ':p'))
endfunc
func! cmake#commands#build_target_for_file(file)
- let target = cmake#targets#corresponding_file(a:file)
+ let target = cmake#targets#for_file(a:file)
if empty(target)
return 0
endif
@@ -33,37 +35,25 @@ endfunc
func! cmake#commands#clean()
echomsg "[cmake] Cleaning build..."
- let l:output = cmake#util#run_make("clean")
- if l:output != 0
- echomsg l:output
- end
+ call cmake#util#run_make("clean")
echomsg "[cmake] Cleaned build."
endfunc
func! cmake#commands#test()
echomsg "[cmake] Testing build..."
- let l:output = cmake#util#run_make("test")
- if l:output != 0
- echomsg l:output
- end
+ call cmake#util#run_make("test")
echomsg "[cmake] Tested build."
endfunc
func! cmake#commands#rebuild_cache()
echomsg "[cmake] Rebuilding cache for CMake.."
- let l:output = cmake#util#run_make("rebuild_cache")
- if l:output != 0
- echomsg l:output
- end
+ call cmake#util#run_make("rebuild_cache")
echomsg "[cmake] Rebuilt cache for CMake."
endfunc
func! cmake#commands#install()
echomsg "[cmake] Installing project..."
- let l:output = cmake#util#run_make("install")
- if l:output != 0
- echomsg l:output
- end
+ call cmake#util#run_make("install")
echomsg "[cmake] Installed project."
endfunc
@@ -106,7 +96,6 @@ func! cmake#commands#set_var(variable,value)
endfunc!
function! cmake#commands#install_ex()
- " Set Ex commands.
command! -buffer -nargs=0 CMakeBuild
\ :call cmake#commands#build()
command! -buffer -nargs=0 CMakeRebuildCache
@@ -122,31 +111,34 @@ function! cmake#commands#install_ex()
command! -buffer -nargs=0 CMakeClearBufferOpts
\ :unlet b:cmake_binary_dir
command! -buffer -nargs=0 CMakeBuildCurrent
- \ :call cmake#commands#build_target_for_file(fnamemodify(bufname('%'), ':p'))
-
- command! -buffer -nargs=1 CMakeTarget
- \ :call cmake#targets#build("<args>")
- command! -buffer -nargs=1 CMakeCreateBuild
- \ :call cmake#commands#create_build("<args>")
- \ -complete=dir
+ \ :call cmake#commands#build_current()
+ command! -buffer -nargs=1 -complete=customlist,s:get_targets
+ \ CMakeTarget :call cmake#targets#build("<args>")
command! -buffer -nargs=1 CMakeGetVar
\ :echo cmake#commands#get_var("<args>")
+
+ command! -nargs=1 -complete=dir CMakeCreateBuild
+ \ :call cmake#commands#create_build("<args>")
endfunc!
func! s:clean_then_build()
call cmake#commands#clean()
call cmake#commands#build()
endfunc
+func! s:get_targets(A,L,P)
+ return cmake#targets#list()
+endfunc
+
func! s:get_build_opts()
let l:command = [ '-G "Unix Makefiles" ']
- let l:command += [ "-DCMAKE_EXPORT_COMPILE_COMMANDS=1"]
- let l:command += [ "-DCMAKE_INSTALL_PREFIX:FILEPATH=" . g:cmake_install_prefix ]
- let l:command += [ "-DCMAKE_BUILD_TYPE:STRING=" . g:cmake_build_type ]
- let l:command += [ "-DCMAKE_CXX_COMPILER:FILEPATH=" . g:cmake_cxx_compiler ]
- let l:command += [ "-DCMAKE_C_COMPILER:FILEPATH=" . g:cmake_c_compiler ]
- let l:command += [ "-DBUILD_SHARED_LIBS:BOOL=" . g:cmake_build_shared_libs ]
- let l:commandstr = join(l:command, " ")
+ let l:command += [ '-DCMAKE_EXPORT_COMPILE_COMMANDS=1']
+ let l:command += [ '-DCMAKE_INSTALL_PREFIX:FILEPATH=' . g:cmake_install_prefix ]
+ let l:command += [ '-DCMAKE_BUILD_TYPE:STRING=' . g:cmake_build_type ]
+ let l:command += [ '-DCMAKE_CXX_COMPILER:FILEPATH=' . g:cmake_cxx_compiler ]
+ let l:command += [ '-DCMAKE_C_COMPILER:FILEPATH=' . g:cmake_c_compiler ]
+ let l:command += [ '-DBUILD_SHARED_LIBS:BOOL=' . g:cmake_build_shared_libs ]
+ let l:commandstr = join(l:command, ' ')
return l:commandstr
endfunc!
View
@@ -6,48 +6,33 @@
" Version: 0.2.2
" Last Modified: 2013-09-28 15:21:21 EDT
-func! cmake#flags#parse(flagstr)
- let l:flags = split(a:flagstr)
-
- if g:cmake_filter_flags == 1
+" TODO: Filter the flags so that we only have warnings and includes passed
+" into the mix.
+func! cmake#flags#filter(flags)
+ let l:flags = a:flags
+ if g:cmake_filter_flags == 1 && !empty(l:flags)
for flag in flags
- let l:index = index(flags, flag)
- let l:isAInclude = stridx(flag, '-I')
- let l:isAIncludeFlagger = stridx(flag, '-i')
- let l:isAWarning = stridx(flag, '-W')
- let l:isValidFlag = !(isAInclude == -1 &&
- \ isAWarning == -1 &&
- \ isAIncludeFlagger == -1
- \ )
-
- if !isValidFlag
- unlet flags[index]
- continue
- else
- if isdirectory(flag) &&
- \ (stridx(flags[index - 1], '-i') || stridx(flags[index - 1], '-I'))
- continue
- endif
- endif
+ let l:index = index(flags, flag)
+ let l:isAInclude = stridx(flag, '-I') || stridx(flag, '-i')
+ let l:isAWarning = stridx(flag, '-W')
endfor
endif
- return flags
+ return l:flags
endfunc!
func! cmake#flags#inject()
- if empty(g:cmake_inject_flags)
- return 0
- endif
-
- let target = cmake#targets#corresponding_file(fnamemodify(bufname('%'), ':p'))
+ let target = cmake#targets#for_file(fnamemodify(bufname('%'), ':p'))
- if !empty(target)
- call cmake#flags#inject_to_ycm(target)
- call cmake#flags#inject_to_syntastic(target)
+ if empty(target)
+ return
endif
+
+ call cmake#flags#inject_to_ycm(target)
+ call cmake#flags#inject_to_syntastic(target)
endfunc
+" TODO Fix this; it doesn't use the right Syntastic option.
func! cmake#flags#inject_to_syntastic(target)
if g:cmake_inject_flags.syntastic != 1
return
@@ -59,34 +44,39 @@ func! cmake#flags#inject_to_syntastic(target)
endif
for l:language in keys(l:flags)
- let l:checker_val = "g:syntastic_" . l:language . "_checkers"
- if !exists(l:checker_val)
- continue
- endif
+ "let l:checker_val = "g:syntastic_" . l:language . "_checkers"
+ "if !exists(l:checker_val)
+ "continue
+ "endif
- let l:checkers = eval(l:checker_val)
- for l:checker in l:checkers
- let l:args = l:flags[l:language]
- let l:sy_flag = "g:syntastic_" . l:language . "_" . l:checker . "_args"
- exec("let " . l:sy_flag . "='" . join(l:args, " ") . "'")
- endfor
+ "let l:checkers = eval(l:checker_val)
+ "for l:checker in l:checkers
+ "let l:args = l:flags[l:language]
+ "let l:sy_flag = "g:syntastic_" . l:language . "_" . l:checker . "_args"
+ "exec("let " . l:sy_flag . "='" . join(l:args, " ") . "'")
+ "endfor
endfor
endfunc!
+func! cmake#flags#collect(flags_file, prefix)
+ let l:flags = split(system("grep '" . a:prefix . "_FLAGS = ' " . a:flags_file .
+ \ ' | cut -b ' . (strlen(a:prefix) + strlen('_FLAGS = ')) . '-'))
+ let l:flags = cmake#flags#filter(l:flags)
+
+ let l:defines = split(system("grep '" . a:prefix . "_DEFINES = ' " . a:flags_file
+ \ . ' | cut -b ' . (strlen(a:prefix) + strlen('_DEFINES = ')) . '-'))
+
+ let l:params = l:flags + l:defines
+ return l:params
+endfunc!
+
+" TODO: Don't clobber the values for vim data in YCM.
func! cmake#flags#inject_to_ycm(target)
if g:cmake_inject_flags.ycm != 1
return
endif
- " First, let's pass in the flags that one could add in directly for
- " individual targets for the .ycm_extra_conf.py.
- let b:cmake_flags = string(cmake#targets#flags(a:target)[&filetype])
- if empty(g:ycm_extra_conf_vim_data)
- let g:ycm_extra_conf_vim_data = ['b:cmake_flags']
- elseif get(g:ycm_extra_conf_vim_data,'b:cmake_flags','NONE') == 'NONE'
- add(ycm_extra_conf_vim_data,'b:cmake_flags')
- endif
-
- " Secondly, provide the full path where the JSON compilation file could be
- " found.
+ let g:cmake_binary_dir = cmake#util#binary_dir()
+ let g:cmake_current_flags = cmake#targets#flags(a:target)
+ let g:ycm_extra_conf_vim_data = ['g:cmake_binary_dir', 'g:cmake_current_flags']
endfunc!
View
@@ -51,13 +51,15 @@ func! cmake#targets#exists(target)
return index(cmake#targets#list(), a:target) != -1
endfunc
-func! cmake#targets#corresponding_file(filepath)
+func! cmake#targets#for_file(filepath)
" A bit intensive of a method, searches each target if the provided file is
" within. This value is cached.
if exists("b:cmake_corresponding_target")
return b:cmake_corresponding_target
endif
+ let b:cmake_corresponding_target = 0
+
for target in cmake#targets#list()
if exists("l:files")
unlet l:files
@@ -72,11 +74,7 @@ func! cmake#targets#corresponding_file(filepath)
endif
endfor
- if exists("b:cmake_corresponding_target")
- return b:cmake_corresponding_target
- endif
-
- return 0
+ return b:cmake_corresponding_target
endfunc!
func! cmake#targets#files(target)
@@ -109,14 +107,15 @@ func! cmake#targets#flags(target)
return 0
endif
- let l:flags_file = cmake#targets#binary_dir(a:target) . "/flags.make"
+ let l:flags_file = cmake#targets#binary_dir(a:target) . '/flags.make'
if !filereadable(l:flags_file)
return 0
endif
+ " Scan flags.make for the flags and defines to be passed into the mix.
return {
- \ "c" : cmake#flags#parse(system("grep 'C_FLAGS = ' " . l:flags_file . " | cut -b 11-")),
- \ "cpp" : cmake#flags#parse(system("grep 'CXX_FLAGS = ' " . l:flags_file . " | cut -b 13-"))
- \ }
+ \ 'c' : cmake#flags#collect(l:flags_file, 'C'),
+ \ 'cpp' : cmake#flags#collect(l:flags_file, 'CXX')
+ \ }
endfunc!
Oops, something went wrong.

0 comments on commit 0991dc0

Please sign in to comment.