Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 13 commits
  • 9 files changed
  • 0 commit comments
  • 1 contributor
Commits on Feb 20, 2014
@jalcine Touched up flags. 6d9d11c
Commits on Feb 24, 2014
@jalcine I didn't even need this. f7791ef
Commits on Feb 27, 2014
@jalcine Updated plugin logic. ab015ff
Commits on Feb 28, 2014
@jalcine Changed bangs on functions and added Dispatch.
  * Added logic to handle git://github.com/tpope/vim-dispatch for handling the
    invocation of commands.

  * Removed bangs at the end of 'endfunc'.
f4f2d19
@jalcine Merge branch 'feature/8-compile-commands' into develop
* feature/8-compile-commands:
  Changed bangs on functions and added Dispatch.
  Updated plugin logic.
  I didn't even need this.
7586712
@jalcine Made less logic jumps. 6ab236a
@jalcine Ensured proper setting of the makeprg. e7a51fb
@jalcine Ensured commands were added only on CMake project buffers. 1138678
@jalcine Dropped the need for a tailing 'if' block. dfde886
@jalcine Tightened use of CMake command detection. e612aff
Commits on Mar 02, 2014
@jalcine Updated commands and utilities. 3cbdd06
@jalcine 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.
0991dc0
@jalcine Updated files post-release. db07ef8
Showing with 119 additions and 154 deletions.
  1. +2 −2 README.md
  2. +32 −41 autoload/cmake/commands.vim
  3. +43 −54 autoload/cmake/flags.vim
  4. +10 −12 autoload/cmake/targets.vim
  5. +26 −33 autoload/cmake/util.vim
  6. +1 −2 autoload/cmake/variables.vim
  7. +2 −2 doc/cmake.txt
  8. +3 −4 plugin/cmake.vim
  9. +0 −4 python/vim/cmake.py
View
4 README.md
@@ -8,7 +8,7 @@
---
-[`cmake.vim 0.2.2`][release] is a Vim plugin that allows you to use [CMake][cmake]
+[`cmake.vim 0.3.0`][release] is a Vim plugin that allows you to use [CMake][cmake]
within Vim for your projects. **This is alpha-grade software and may turn your CMake
project into a cat-overrun Telnet session**.
@@ -100,4 +100,4 @@ firehose so follow with caution!
[jalcine]: http://jalcine.me
[vimux]: https://github.com/benmills/vimux
[site]: http://jalcine.github.io/cmake.vim
-[release]: https://github.com/jalcine/cmake.vim/tree/v0.2.2
+[release]: https://github.com/jalcine/cmake.vim/tree/v0.3.0
View
73 autoload/cmake/commands.vim
@@ -1,27 +1,28 @@
" 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
-" Version: 0.2.2
-" Last Modified: 2013-09-28 15:21:51 EDT
+" Version: 0.3.0
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 +34,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 +95,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,15 +110,14 @@ 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()
@@ -138,15 +125,19 @@ func! s:clean_then_build()
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
97 autoload/cmake/flags.vim
@@ -3,51 +3,35 @@
" Author: Jacky Alciné <me@jalcine.me>
" License: MIT
" Website: https://jalcine.github.io/cmake.vim
-" Version: 0.2.2
-" Last Modified: 2013-09-28 15:21:21 EDT
+" Version: 0.3.0
-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 +43,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
22 autoload/cmake/targets.vim
@@ -3,8 +3,7 @@
" Author: Jacky Alciné <me@jalcine.me>
" License: MIT
" Website: https://jalcine.github.io/cmake.vim
-" Version: 0.2.2
-" Last Modified: 2013-09-28 15:21:40 EDT
+" Version: 0.3.0
func! cmake#targets#build(target)
echomsg "[cmake] Building target '" . a:target . "'..."
@@ -51,13 +50,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 +73,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 +106,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!
View
59 autoload/cmake/util.vim
@@ -3,44 +3,41 @@
" Author: Jacky Alciné <me@jalcine.me>
" License: MIT
" Website: https://jalcine.github.io/cmake.vim
-" Version: 0.2.2
-" Last Modified: 2013-09-28 15:21:31 EDT
+" Version: 0.3.0
func! cmake#util#binary_dir()
- " If we found it already, don't waste effort.
if exists("b:cmake_binary_dir")
return b:cmake_binary_dir
endif
let l:proposed_dir = 0
-
- " Check in the currenty directory as well.
let l:directories = g:cmake_build_directories + [ getcwd() ]
for l:directory in l:directories
let l:directory = fnamemodify(l:directory, ':p')
- " TODO: Make paths absolute.
- let l:proposed_cmake_file = findfile(directory . "/CMakeCache.txt", ".;")
+ let l:file = findfile(directory . "/CMakeCache.txt", ".;")
- if filereadable(l:proposed_cmake_file)
- " If we found it, drop off that CMakeCache.txt reference and cache the
- " value to this buffer.
- let l:proposed_dir = substitute(l:proposed_cmake_file, "/CMakeCache.txt", "", "")
+ if filereadable(l:file)
+ let l:proposed_dir = substitute(l:file, "/CMakeCache.txt", "", "")
let b:cmake_binary_dir = l:proposed_dir
endif
endfor
return l:proposed_dir
-endfunc!
+endfunc
+
+func! cmake#util#has_project()
+ return cmake#util#binary_dir() == 0
+endfunc
-" TODO; Resolve path to absolute-ness.
+" TODO: Resolve path to absolute-ness.
func! cmake#util#source_dir()
if cmake#util#binary_dir() == 0
return ""
endif
return cmake#util#read_from_cache("Project_SOURCE_DIR")
-endfunc!
+endfunc
func! cmake#util#cache_file_path()
let l:bindir = cmake#util#binary_dir()
@@ -49,14 +46,12 @@ func! cmake#util#cache_file_path()
endif
return 0
-endfunc!
+endfunc
func! cmake#util#read_from_cache(property)
let l:cmake_cache_file = cmake#util#cache_file_path()
let l:property_width = strlen(a:property) + 2
- " If we can't find the cache file, then there's no point in trying to read
- " it.
if !filereadable(cmake#util#cache_file_path())
return ""
endif
@@ -75,20 +70,16 @@ func! cmake#util#read_from_cache(property)
let l:property_fields[1] = substitute(l:property_fields[1], "\n", "", "g")
return l:property_fields
-endfunc!
+endfunc
func! cmake#util#write_to_cache(property,value)
call cmake#util#run_cmake('-D' . a:property . '=' . shellescape(a:value))
-endfunc!
+endfunc
func! cmake#util#run_make(command)
let l:command = "make -C " . cmake#util#binary_dir() . " " . a:command
- if g:cmake_use_vimux == 1 && g:loaded_vimux == 1
- call VimuxRunCommand(l:command)
- else if g:cmake_set_makeprg == 1
- call make(a:command)
- endif
-endfunc!
+ call cmake#util#shell_exec(l:command)
+endfunc
func! cmake#util#run_cmake(command, binary_dir, source_dir)
let l:binary_dir = a:binary_dir
@@ -111,22 +102,24 @@ func! cmake#util#run_cmake(command, binary_dir, source_dir)
\ l:binary_dir . ' ' . l:source_dir
return cmake#util#shell_exec(l:command)
-endfunc!
+endfunc
func! cmake#util#handle_injection()
call cmake#commands#install_ex()
call cmake#util#apply_makeprg()
call cmake#flags#inject()
-endfunc!
+endfunc
func! cmake#util#shell_exec(command)
- if g:cmake_use_vimux == 1 && g:loaded_vimux == 1
+ if g:cmake_use_dispatch == 1 && g:loaded_dispatch == 1
+ return dispatch#compile_command("", a:command)
+ else if g:cmake_use_vimux == 1 && g:loaded_vimux == 1
call VimuxRunCommand(a:command)
return 0
else
return system(a:command)
endif
-endfunc!
+endfunc
func! cmake#util#targets()
let dirs = glob(cmake#util#binary_dir() ."**/*.dir", 0, 1)
@@ -140,8 +133,8 @@ func! cmake#util#targets()
endfunc
func! cmake#util#apply_makeprg()
- let build_dir = cmake#util#binary_dir()
- if exists('g:cmake_set_makeprg') && g:cmake_set_makeprg == 1
- let &makeprg="make -C " . l:build_dir
+ " TODO Take a copy of the old 'makeprg' and place it in 'g:oldmakeprg'
+ if g:cmake_set_makeprg == 1 && cmake#util#has_project() == 1
+ let &makeprg="make -C " . cmake#util#binary_dir()
endif
-endfunc!
+endfunc
View
3 autoload/cmake/variables.vim
@@ -3,8 +3,7 @@
" Author: Jacky Alciné <me@jalcine.me>
" License: MIT
" Website: https://jalcine.github.io/cmake.vim
-" Version: 0.2.2
-" Last Modified: 2013-09-28 15:22:11 EDT
+" Version: 0.3.0
func! cmake#variables#exists(variable)
let l:val = cmake#util#read_from_cache(variable)
View
4 doc/cmake.txt
@@ -36,8 +36,8 @@ plugin goes a step further and automatically sets 'makeprg' for you to help
other tools related to Java, C++, C, Objective C or Fortan-based programming
easily invoke CMake's version of the build system.
-'cmake' version 0.1.6 provides this integration with minimal effort to the
-developer using Vim.
+'cmake' provides this integration with minimal effort to the developer using
+Vim.
2. QUICK START ~
*cmake-quickstart*
View
7 plugin/cmake.vim
@@ -3,8 +3,7 @@
" Author: Jacky Alciné <me@jalcine.me>
" License: MIT
" Website: https://jalcine.github.io/cmake.vim
-" Version: 0.2.2
-" Last Modified: 2013-09-28 19:32:47 EDT
+" Version: 0.3.0
" If we're here, don't reload man.
if exists("g:loaded_cmake")
@@ -29,6 +28,7 @@ let s:options = {
\ 'g:cmake_build_shared_libs': 1,
\ 'g:cmake_set_makeprg': 1,
\ 'g:cmake_use_vimux': exists('g:loaded_vimux'),
+ \ 'g:cmake_use_dispatch': exists('g:loaded_dispatch'),
\ 'g:cmake_filter_flags': 1,
\ 'g:cmake_inject_flags': {
\ 'syntastic': exists('g:loaded_syntastic_plugin'),
@@ -42,6 +42,5 @@ endfor
augroup cmake
au!
- au FileWritePost * call cmake#util#handle_injection()
- au BufEnter * call cmake#util#handle_injection()
+ au VimEnter,BufEnter,FileReadPre * call cmake#util#handle_injection()
augroup END
View
4 python/vim/cmake.py
@@ -1,4 +0,0 @@
-import vim
-
-def flags(filetype="cpp"):
- return vim.eval('b:cmake_flags["' + filetype + '"]')

No commit comments for this range

Something went wrong with that request. Please try again.