From fa134d534a9a4776cd4897c232544b99542d172b Mon Sep 17 00:00:00 2001 From: Squareys Date: Wed, 22 Mar 2017 07:52:58 +0100 Subject: [PATCH 01/29] Add initial vader test Signed-off-by: Squareys --- .gitignore | 1 + test/cmake.vader | 48 +++++++++++++++++++++++++++++ test/test project/CMakeLists.txt | 9 ++++++ test/test project/configure.h.cmake | 1 + test/test project/main.cpp | 10 ++++++ 5 files changed, 69 insertions(+) create mode 100644 .gitignore create mode 100644 test/cmake.vader create mode 100644 test/test project/CMakeLists.txt create mode 100644 test/test project/configure.h.cmake create mode 100644 test/test project/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1954172 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +test/test project/build/ diff --git a/test/cmake.vader b/test/cmake.vader new file mode 100644 index 0000000..3ecfe2f --- /dev/null +++ b/test/cmake.vader @@ -0,0 +1,48 @@ +Before: + " Ensure we are in the test directory + if isdirectory("test") + cd test + endif + + if !exists("test_dir") + let test_dir = fnamemodify(getcwd(), ':p') + endif + + if !isdirectory("test project/build") + echo system("mkdir 'test project/build'") + endif + + Assert isdirectory("test project/build"), "TEST ERROR: build directory was not created" + +After: + exec "cd" fnameescape(test_dir) + echo system("rm -rf 'test project/build'") + +Execute (Find build directory from working dir): + cd test\ project + CMake + + Assert filereadable("build/CMakeCache.txt"), "CMakeCache.txt should be generated" + +Execute (Find build directory from currently open file): + e test\ project/CMakeLists.txt + CMake + Assert filereadable("test project/build/CMakeCache.txt"), "CMakeCache.txt should be generated" + +Execute (Open already configured cmake project): + cd test\ project/build + silent !cmake .. -DWITH_BYE=ON + e ../CMakeLists.txt + CMake + silent make + + enew + if has("win32") || has("win32unix") + read !Debug/hello.exe + else + read !./hello + endif +Expect: + + Hello World + Bye World diff --git a/test/test project/CMakeLists.txt b/test/test project/CMakeLists.txt new file mode 100644 index 0000000..82ccdff --- /dev/null +++ b/test/test project/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 2.8.12) + +project(HelloWorld) + +option(WITH_BYE "Print bye world" OFF) + +configure_file(configure.h.cmake configure.h) +add_executable(hello main.cpp) +target_include_directories(hello PRIVATE ${CMAKE_BINARY_DIR}) diff --git a/test/test project/configure.h.cmake b/test/test project/configure.h.cmake new file mode 100644 index 0000000..6fc9dad --- /dev/null +++ b/test/test project/configure.h.cmake @@ -0,0 +1 @@ +#cmakedefine WITH_BYE diff --git a/test/test project/main.cpp b/test/test project/main.cpp new file mode 100644 index 0000000..f5879ca --- /dev/null +++ b/test/test project/main.cpp @@ -0,0 +1,10 @@ +#include +#include "configure.h" + +int main() { + std::cout << "Hello World" << std::endl; +#ifdef WITH_BYE + std::cout << "Bye World" << std::endl; +#endif + return 0; +} From cd0c4c26c970bc2899bf1378e135c24fb1a91803 Mon Sep 17 00:00:00 2001 From: Jonathan Hale Date: Mon, 20 Mar 2017 11:07:02 +0100 Subject: [PATCH 02/29] Add .travis.yml for linux CI builds Signed-off-by: Squareys --- .travis.yml | 16 ++++++++++++++++ test/.vimrc | 7 +++++++ 2 files changed, 23 insertions(+) create mode 100644 .travis.yml create mode 100644 test/.vimrc diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f85420c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,16 @@ +language: vim + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + - kubuntu-backports + packages: + - g++-4.7 + - cmake + +before_script: | + git clone https://github.com/junegunn/vader.vim.git + +script: | + vim -Nu 'test/.vimrc' -c 'Vader! test/cmake.vader' diff --git a/test/.vimrc b/test/.vimrc new file mode 100644 index 0000000..4113900 --- /dev/null +++ b/test/.vimrc @@ -0,0 +1,7 @@ +filetype off + +set rtp+=vader.vim +set rtp+=. +filetype plugin indent on +syntax enable + From 2d2ff7886c9c14cebca68ee2aac77c02099527b3 Mon Sep 17 00:00:00 2001 From: Squareys Date: Thu, 6 Apr 2017 15:06:03 +0200 Subject: [PATCH 03/29] Add appveyor.yml config for windows CI builds Signed-off-by: Squareys --- appveyor.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..7afdcd7 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,10 @@ +os: Visual Studio 2015 + +install: + - cinst vim + - cinst cmake + - set PATH=%PATH%;C:\Program Files\CMake\bin + - git clone https://github.com/junegunn/vader.vim + +build_script: + - vim -Nu test/.vimrc -c 'Vader! test/cmake.vader' --not-a-term From 9d6a17510fab7598efb2b4837c54381969afbd36 Mon Sep 17 00:00:00 2001 From: Jonathan Hale Date: Tue, 21 Mar 2017 21:59:05 +0100 Subject: [PATCH 04/29] Add Travis and AppVeyor badges Signed-off-by: Squareys --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a2ac0c4..6cf7ae4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ # vim-cmake +[![Travis (Linux)](https://travis-ci.org/Squareys/vim-cmake.svg?branch=master)](https://travis-ci.org/Squareys/vim-cmake) +[![AppVeyor (Windows)](https://ci.appveyor.com/api/projects/status/8x1tk0wbu4564m43?svg=true)](https://ci.appveyor.com/project/Squareys/vim-cmake) vim-cmake is a Vim plugin to make working with CMake a little nicer. From 7de17c93d778ecabe7c2d93dd3affe14a1c97a97 Mon Sep 17 00:00:00 2001 From: Squareys Date: Thu, 6 Apr 2017 12:36:12 +0200 Subject: [PATCH 05/29] Make code formatting consistent Signed-off-by: Squareys --- plugin/cmake.vim | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/plugin/cmake.vim b/plugin/cmake.vim index 7a3be60..9b45b82 100644 --- a/plugin/cmake.vim +++ b/plugin/cmake.vim @@ -28,33 +28,32 @@ function! s:cmake(...) let g:cmake_build_dir = get(g:, 'cmake_build_dir', 'build') let s:build_dir = finddir(g:cmake_build_dir, '.;') - if s:build_dir !="" - - let &makeprg='cmake --build ' . shellescape(s:build_dir) . ' --target ' + if s:build_dir != "" + let &makeprg = 'cmake --build ' . shellescape(s:build_dir) . ' --target' exec 'cd' s:fnameescape(s:build_dir) let s:cleanbuild = 0 - let l:argument=[] + let l:argument = [] if exists("g:cmake_project_generator") - let l:argument+= [ "-G \"" . g:cmake_project_generator . "\"" ] + let l:argument += [ "-G \"" . g:cmake_project_generator . "\"" ] endif if exists("g:cmake_install_prefix") - let l:argument+= [ "-DCMAKE_INSTALL_PREFIX:FILEPATH=" . 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 ] + 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 l:argument += [ "-DCMAKE_CXX_COMPILER:FILEPATH=" . g:cmake_cxx_compiler ] let s:cleanbuild = 1 endif if exists("g:cmake_c_compiler") - let l:argument+= [ "-DCMAKE_C_COMPILER:FILEPATH=" . g:cmake_c_compiler ] + let l:argument += [ "-DCMAKE_C_COMPILER:FILEPATH=" . g:cmake_c_compiler ] let s:cleanbuild = 1 endif if exists("g:cmake_build_shared_libs") - let l:argument+= [ "-DBUILD_SHARED_LIBS:BOOL=" . g:cmake_build_shared_libs ] + let l:argument += [ "-DBUILD_SHARED_LIBS:BOOL=" . g:cmake_build_shared_libs ] endif let l:argumentstr = join(l:argument, " ") @@ -68,7 +67,7 @@ function! s:cmake(...) let s:res = system(s:cmd) echo s:res - exec 'cd - ' + exec 'cd -' else echo "Unable to find build directory." @@ -79,8 +78,8 @@ endfunction function! s:cmakeclean() let s:build_dir = finddir('build', '.;') - if s:build_dir !="" - echo system("rm -r '" . s:build_dir. "'/*" ) + if s:build_dir != "" + echo system("rm -r '" . s:build_dir. "'/*") echo "Build directory has been cleaned." else echo "Unable to find build directory." From 40eefdfeb9d85013524e1a36163dc56d2ff48e0c Mon Sep 17 00:00:00 2001 From: Squareys Date: Thu, 6 Apr 2017 12:40:52 +0200 Subject: [PATCH 06/29] Extract new function cmake_configure() Signed-off-by: Squareys --- plugin/cmake.vim | 81 +++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/plugin/cmake.vim b/plugin/cmake.vim index 9b45b82..ce876ec 100644 --- a/plugin/cmake.vim +++ b/plugin/cmake.vim @@ -9,6 +9,47 @@ if exists("loaded_cmake_plugin") endif let loaded_cmake_plugin = 1 + +function! s:cmake_configure() + exec 'cd' s:fnameescape(s:build_dir) + + let s:cleanbuild = 0 + let l:argument = [] + if exists("g:cmake_project_generator") + let l:argument += [ "-G \"" . g:cmake_project_generator . "\"" ] + endif + 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:argument += [ "-DCMAKE_CXX_COMPILER:FILEPATH=" . g:cmake_cxx_compiler ] + let s:cleanbuild = 1 + endif + if exists("g:cmake_c_compiler") + let l:argument += [ "-DCMAKE_C_COMPILER:FILEPATH=" . g:cmake_c_compiler ] + let s:cleanbuild = 1 + endif + 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, " ") + + if s:cleanbuild > 0 + echo system("rm -r *" ) + endif + + let s:cmd = 'cmake '. l:argumentstr . " " . join(a:000) .' .. ' + echo s:cmd + let s:res = system(s:cmd) + echo s:res + + exec 'cd -' +endfunction + " Utility function " Thanks to tpope/vim-fugitive function! s:fnameescape(file) abort @@ -30,45 +71,7 @@ function! s:cmake(...) if s:build_dir != "" let &makeprg = 'cmake --build ' . shellescape(s:build_dir) . ' --target' - - exec 'cd' s:fnameescape(s:build_dir) - - let s:cleanbuild = 0 - let l:argument = [] - if exists("g:cmake_project_generator") - let l:argument += [ "-G \"" . g:cmake_project_generator . "\"" ] - endif - 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:argument += [ "-DCMAKE_CXX_COMPILER:FILEPATH=" . g:cmake_cxx_compiler ] - let s:cleanbuild = 1 - endif - if exists("g:cmake_c_compiler") - let l:argument += [ "-DCMAKE_C_COMPILER:FILEPATH=" . g:cmake_c_compiler ] - let s:cleanbuild = 1 - endif - 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, " ") - - if s:cleanbuild > 0 - echo system("rm -r *" ) - endif - - let s:cmd = 'cmake '. l:argumentstr . " " . join(a:000) .' .. ' - echo s:cmd - let s:res = system(s:cmd) - echo s:res - - exec 'cd -' - + call s:cmake_configure() else echo "Unable to find build directory." endif From 644a644332bbd0af82d4b811fcb34dca28e7e9a0 Mon Sep 17 00:00:00 2001 From: Squareys Date: Thu, 6 Apr 2017 12:45:29 +0200 Subject: [PATCH 07/29] Extract and reuse s:find_build_dir() Signed-off-by: Squareys --- plugin/cmake.vim | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugin/cmake.vim b/plugin/cmake.vim index ce876ec..59ae0bc 100644 --- a/plugin/cmake.vim +++ b/plugin/cmake.vim @@ -9,6 +9,10 @@ if exists("loaded_cmake_plugin") endif let loaded_cmake_plugin = 1 +function! s:find_build_dir() + let g:cmake_build_dir = get(g:, 'cmake_build_dir', 'build') + let s:build_dir = finddir(g:cmake_build_dir, '.;') +endfunction function! s:cmake_configure() exec 'cd' s:fnameescape(s:build_dir) @@ -65,9 +69,7 @@ command! -nargs=? CMake call s:cmake() command! CMakeClean call s:cmakeclean() function! s:cmake(...) - - let g:cmake_build_dir = get(g:, 'cmake_build_dir', 'build') - let s:build_dir = finddir(g:cmake_build_dir, '.;') + call s:find_build_dir() if s:build_dir != "" let &makeprg = 'cmake --build ' . shellescape(s:build_dir) . ' --target' @@ -79,8 +81,8 @@ function! s:cmake(...) endfunction function! s:cmakeclean() + call s:find_build_dir() - let s:build_dir = finddir('build', '.;') if s:build_dir != "" echo system("rm -r '" . s:build_dir. "'/*") echo "Build directory has been cleaned." From 8c15efa7bebfc89237c8b20026101c1cf752801e Mon Sep 17 00:00:00 2001 From: Squareys Date: Thu, 6 Apr 2017 12:50:28 +0200 Subject: [PATCH 08/29] Store build dir as absolute path Fixes problems where the user "cd"s out of the directory in which he called CMake() command, which would make the build dir invalid. Signed-off-by: Squareys --- plugin/cmake.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/cmake.vim b/plugin/cmake.vim index 59ae0bc..7d533aa 100644 --- a/plugin/cmake.vim +++ b/plugin/cmake.vim @@ -11,7 +11,7 @@ let loaded_cmake_plugin = 1 function! s:find_build_dir() let g:cmake_build_dir = get(g:, 'cmake_build_dir', 'build') - let s:build_dir = finddir(g:cmake_build_dir, '.;') + let s:build_dir = expand(finddir(g:cmake_build_dir, '.;')) endfunction function! s:cmake_configure() From 26f04631523b77d0e55d18951a5483d137dfab53 Mon Sep 17 00:00:00 2001 From: Squareys Date: Thu, 6 Apr 2017 12:52:24 +0200 Subject: [PATCH 09/29] Do not reconfigure project if already configured In some circumstances the user may have already configured a cmake project with a certain generator or other variables, which would be overwritten with the config values set with the g:cmake_* variables. Instead the user should be required to do a clean build if this behaviour is requested. Signed-off-by: Squareys --- plugin/cmake.vim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugin/cmake.vim b/plugin/cmake.vim index 7d533aa..b53b7c0 100644 --- a/plugin/cmake.vim +++ b/plugin/cmake.vim @@ -15,6 +15,12 @@ function! s:find_build_dir() endfunction function! s:cmake_configure() + if filereadable(s:build_dir . "/CMakeCache.txt") && !s:cleanbuild + " Only change values of variables, if project is not configured + " already, otherwise we override existing configuration. + return + endif + exec 'cd' s:fnameescape(s:build_dir) let s:cleanbuild = 0 From 90ef71ce355769d6d343ffae3a9ced0fe80eb7e4 Mon Sep 17 00:00:00 2001 From: Squareys Date: Thu, 6 Apr 2017 12:56:07 +0200 Subject: [PATCH 10/29] Use echom(sg) instead of echo to store messages in message-history Otherwise they will be displayed and then disappear. This way you can re- read the message using :messages Signed-off-by: Squareys --- plugin/cmake.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/cmake.vim b/plugin/cmake.vim index b53b7c0..7cd59fe 100644 --- a/plugin/cmake.vim +++ b/plugin/cmake.vim @@ -81,7 +81,7 @@ function! s:cmake(...) let &makeprg = 'cmake --build ' . shellescape(s:build_dir) . ' --target' call s:cmake_configure() else - echo "Unable to find build directory." + echom "Unable to find build directory." endif endfunction @@ -91,9 +91,9 @@ function! s:cmakeclean() if s:build_dir != "" echo system("rm -r '" . s:build_dir. "'/*") - echo "Build directory has been cleaned." + echom "Build directory has been cleaned." else - echo "Unable to find build directory." + echom "Unable to find build directory." endif endfunction From fb2ee0c3e19acc8ddd7875e8794b5f32b3a1b4ba Mon Sep 17 00:00:00 2001 From: Squareys Date: Thu, 6 Apr 2017 13:02:34 +0200 Subject: [PATCH 11/29] Setting the generator requires clean build Signed-off-by: Squareys --- plugin/cmake.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/cmake.vim b/plugin/cmake.vim index 7cd59fe..9f3f744 100644 --- a/plugin/cmake.vim +++ b/plugin/cmake.vim @@ -27,6 +27,7 @@ function! s:cmake_configure() let l:argument = [] if exists("g:cmake_project_generator") let l:argument += [ "-G \"" . g:cmake_project_generator . "\"" ] + let s:cleanbuild = 1 endif if exists("g:cmake_install_prefix") let l:argument += [ "-DCMAKE_INSTALL_PREFIX:FILEPATH=" . g:cmake_install_prefix ] From 506c005658ede99903f8762f57d5f28931651342 Mon Sep 17 00:00:00 2001 From: Squareys Date: Thu, 6 Apr 2017 13:19:13 +0200 Subject: [PATCH 12/29] Add documentation and force parameter to s:cmake_configure() Signed-off-by: Squareys --- plugin/cmake.vim | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/plugin/cmake.vim b/plugin/cmake.vim index 9f3f744..0978065 100644 --- a/plugin/cmake.vim +++ b/plugin/cmake.vim @@ -14,8 +14,23 @@ function! s:find_build_dir() let s:build_dir = expand(finddir(g:cmake_build_dir, '.;')) endfunction -function! s:cmake_configure() - if filereadable(s:build_dir . "/CMakeCache.txt") && !s:cleanbuild +" Configure the cmake project in the currently set build dir. +" +" :param force: Force configuration even if CMakeCache.txt already exists in +" build dir. This will override any of the following variables if the +" corresponding vim variable is set: +" * CMAKE_INSTALL_PREFIX +" * CMAKE_BUILD_TYPE +" * CMAKE_BUILD_SHARED_LIBS +" In addition, previous configuration files will be deleted if the +" corresponding vim variables for the following are set: +" * CMAKE_CXX_COMPILER +" * CMAKE_C_COMPILER +" * The generator +" +" Will do nothing if the project is already configured and force is disabled. +function! s:cmake_configure(force) + if filereadable(s:build_dir . "/CMakeCache.txt") && !a:force " Only change values of variables, if project is not configured " already, otherwise we override existing configuration. return @@ -80,7 +95,7 @@ function! s:cmake(...) if s:build_dir != "" let &makeprg = 'cmake --build ' . shellescape(s:build_dir) . ' --target' - call s:cmake_configure() + call s:cmake_configure(0) else echom "Unable to find build directory." endif From 41fade59983b8d5c7753ac41a0c652e17f8e7773 Mon Sep 17 00:00:00 2001 From: Squareys Date: Thu, 6 Apr 2017 13:42:25 +0200 Subject: [PATCH 13/29] Update the README.md Fixed a typo, added doc for recently merged branches and added loads for acknoledgements for people who I found had commits on this project. Signed-off-by: Squareys --- README.md | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6cf7ae4..63caf26 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ vim-cmake is a Vim plugin to make working with CMake a little nicer. -I got tired of navitating to the build directory each time, and I also -disliked setting makeprg manually each time. This plugin does just that. +I got tired of navigating to the build directory each time, and I also +disliked setting makeprg manually each time. This plugin does just that. ## Usage @@ -14,7 +14,7 @@ disliked setting makeprg manually each time. This plugin does just that. * `:CMake` searches for the closest directory named build in an upwards search, and whenever one is found, it runs the cmake command there, assuming the CMakeLists.txt file is just one directory above. Any arguments given to :CMake will be directly passed -on to the cmake command. It also sets the working directory of the make command, so +on to the cmake command. It also sets the working directory of the make command, so you can just use quickfix as with a normal Makefile project. * `:CMakeClean` deletes all files in the build directory. You can think of this as a CMake version of make clean. @@ -31,12 +31,15 @@ you can just use quickfix as with a normal Makefile project. * `g:cmake_build_shared_libs` same as `-DBUILD_SHARED_LIBS` + * `g:cmake_project_generator` same as `-G`. The build directory will be cleared the next time you run :CMake. + ## Installation -If you don't have a preferred installation method, I recommend -installing [pathogen.vim](https://github.com/tpope/vim-pathogen), and -then simply copy and paste: + +### Vim-pathogen + +With [pathogen.vim](https://github.com/tpope/vim-pathogen) simply copy and paste: cd ~/.vim/bundle git clone git://github.com/vhdirk/vim-cmake.git @@ -44,13 +47,24 @@ then simply copy and paste: Once help tags have been generated, you can view the manual with `:help cmake`. +### Vundle +With [Vundle.vim](https://github.com/VundleVim/Vundle.vim) simply add this repository to your plugins list: + + Plugin 'vhdirk/vim-cmake' ## Acknowledgements * Thanks to [Tim Pope](http://tpo.pe/), his plugins are really awesome. - * Thanks to @SteveDeFacto for extending this with more fine grained control. - + * Also thanks to + * @SteveDeFacto for extending this with more fine grained control. + * @snikulov for enhancing makeprg. + * @dapicester for allowing specifying targets. + * @thomasgubler for the build dir option. + * @antmd for fixing a bug with handing of spaces in directory names. + * @jmirabel for fixing concatenation of cmake arguments. + * @T4ng10r for the project generator option. + * @Squareys for a small overhaul of the project, the initial test and travis setup. ## License From 7f2c0c4f8f47042e3c3bf59a99e9603aff46cb2d Mon Sep 17 00:00:00 2001 From: Squareys Date: Thu, 6 Apr 2017 15:27:45 +0200 Subject: [PATCH 14/29] Issue error message if cmake executable was not found Signed-off-by: Squareys --- plugin/cmake.vim | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugin/cmake.vim b/plugin/cmake.vim index 0978065..4ccea0d 100644 --- a/plugin/cmake.vim +++ b/plugin/cmake.vim @@ -7,8 +7,17 @@ let s:cmake_plugin_version = '0.2' if exists("loaded_cmake_plugin") finish endif + +" We set this variable here even though the plugin may not actually be loaded +" because the executable is not found. Otherwise the error message will be +" displayed more than once. let loaded_cmake_plugin = 1 +if !executable("cmake") + echoerr "vim-cmake requires cmake executable. Please make sure it is installed and on PATH." + finish +endif + function! s:find_build_dir() let g:cmake_build_dir = get(g:, 'cmake_build_dir', 'build') let s:build_dir = expand(finddir(g:cmake_build_dir, '.;')) From d8261e884f1a63ae760f6f3e1b6f0d13fe53c6cd Mon Sep 17 00:00:00 2001 From: Squareys Date: Sat, 8 Apr 2017 17:15:48 +0200 Subject: [PATCH 15/29] Allow finding build/ in directory of current file Signed-off-by: Squareys --- plugin/cmake.vim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin/cmake.vim b/plugin/cmake.vim index 4ccea0d..c235dac 100644 --- a/plugin/cmake.vim +++ b/plugin/cmake.vim @@ -20,7 +20,12 @@ endif function! s:find_build_dir() let g:cmake_build_dir = get(g:, 'cmake_build_dir', 'build') - let s:build_dir = expand(finddir(g:cmake_build_dir, '.;')) + let s:build_dir = finddir(g:cmake_build_dir, '.;') + + if s:build_dir == "" + " Find build directory in path of current file + let s:build_dir = finddir(g:cmake_build_dir, expand("%:p:h") . ';') + endif endfunction " Configure the cmake project in the currently set build dir. From cfa3b92859b1542d19cb539a729091f1b8cae766 Mon Sep 17 00:00:00 2001 From: Squareys Date: Sat, 8 Apr 2017 17:17:25 +0200 Subject: [PATCH 16/29] Do not expand path if not found If found and we are in the build/ directory itself, finddir() will return the full path and not "". Signed-off-by: Squareys --- plugin/cmake.vim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugin/cmake.vim b/plugin/cmake.vim index c235dac..b004ec4 100644 --- a/plugin/cmake.vim +++ b/plugin/cmake.vim @@ -26,6 +26,12 @@ function! s:find_build_dir() " Find build directory in path of current file let s:build_dir = finddir(g:cmake_build_dir, expand("%:p:h") . ';') endif + + if s:build_dir != "" + " expand() would expand "" to working directory, but we need + " this as an indicator that build was not found + let s:build_dir = fnamemodify(s:build_dir, ':p') + endif endfunction " Configure the cmake project in the currently set build dir. From 22e1787804e970f6ba718d30f171d96eb828362a Mon Sep 17 00:00:00 2001 From: Squareys Date: Sat, 8 Apr 2017 17:20:59 +0200 Subject: [PATCH 17/29] Suppress "Press ENTER or type command to continue" prompts Signed-off-by: Squareys --- plugin/cmake.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/cmake.vim b/plugin/cmake.vim index b004ec4..a502fc5 100644 --- a/plugin/cmake.vim +++ b/plugin/cmake.vim @@ -85,12 +85,12 @@ function! s:cmake_configure(force) let l:argumentstr = join(l:argument, " ") if s:cleanbuild > 0 - echo system("rm -r *" ) + silent echo system("rm -r *" ) endif let s:cmd = 'cmake '. l:argumentstr . " " . join(a:000) .' .. ' echo s:cmd - let s:res = system(s:cmd) + silent let s:res = system(s:cmd) echo s:res exec 'cd -' @@ -126,7 +126,7 @@ function! s:cmakeclean() call s:find_build_dir() if s:build_dir != "" - echo system("rm -r '" . s:build_dir. "'/*") + silent echo system("rm -r '" . s:build_dir. "'/*") echom "Build directory has been cleaned." else echom "Unable to find build directory." From 8e27bf3d6ffc7c87f53754e8436f6e3116d9f1a7 Mon Sep 17 00:00:00 2001 From: Squareys Date: Sat, 8 Apr 2017 17:21:35 +0200 Subject: [PATCH 18/29] Reorder cmake arguments Saves an addition string concatenation which reads nicer. Signed-off-by: Squareys --- plugin/cmake.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/cmake.vim b/plugin/cmake.vim index a502fc5..e9b2656 100644 --- a/plugin/cmake.vim +++ b/plugin/cmake.vim @@ -88,7 +88,7 @@ function! s:cmake_configure(force) silent echo system("rm -r *" ) endif - let s:cmd = 'cmake '. l:argumentstr . " " . join(a:000) .' .. ' + let s:cmd = 'cmake .. '. l:argumentstr . " " . join(a:000) echo s:cmd silent let s:res = system(s:cmd) echo s:res From 3182afbf9acecfec2e9dda518d79476ebafa1bb6 Mon Sep 17 00:00:00 2001 From: Squareys Date: Sat, 8 Apr 2017 17:58:17 +0200 Subject: [PATCH 19/29] Add option to export compile commands for YCM Signed-off-by: Squareys --- plugin/cmake.vim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugin/cmake.vim b/plugin/cmake.vim index e9b2656..926f7ca 100644 --- a/plugin/cmake.vim +++ b/plugin/cmake.vim @@ -12,6 +12,9 @@ endif " because the executable is not found. Otherwise the error message will be " displayed more than once. let loaded_cmake_plugin = 1 +if !exists("g:cmake_export_compile_commands") + let g:cmake_export_compile_commands = 0 +endif if !executable("cmake") echoerr "vim-cmake requires cmake executable. Please make sure it is installed and on PATH." @@ -81,6 +84,9 @@ function! s:cmake_configure(force) if exists("g:cmake_build_shared_libs") let l:argument += [ "-DBUILD_SHARED_LIBS:BOOL=" . g:cmake_build_shared_libs ] endif + if g:cmake_export_compile_commands + let l:argument += [ "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON" ] + endif let l:argumentstr = join(l:argument, " ") From d2eb207a1feaf77a4b281b951e61f6c016aa708b Mon Sep 17 00:00:00 2001 From: Squareys Date: Sat, 8 Apr 2017 18:19:43 +0200 Subject: [PATCH 20/29] Update vim documentation Signed-off-by: Squareys --- doc/cmake.txt | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/doc/cmake.txt b/doc/cmake.txt index 057357a..600a69e 100644 --- a/doc/cmake.txt +++ b/doc/cmake.txt @@ -28,16 +28,22 @@ g:cmake_install_prefix same as -DCMAKE_INSTALL_PREFIX g:cmake_build_type same as -DCMAKE_BUILD_TYPE -g:cmake_cxx_compiler same as -DCMAKE_CXX_COMPILER, however, do note that - the build directory will be cleared the next time you - run :CMake. +g:cmake_cxx_compiler same as -DCMAKE_CXX_COMPILER, however, this will have + no effect until you run :CMakeClean and :CMake. -g:cmake_c_compiler same as -DCMAKE_C_COMPILER, however, do note that the - build directory will be cleared the next time you - run :CMake. +g:cmake_c_compiler same as -DCMAKE_C_COMPILER, however, this will have + no effect until you run :CMakeClean and :CMake. g:cmake_build_shared_libs same as -DBUILD_SHARED_LIBS g:cmake_build_dir set the cmake 'build' directory, default: 'build' -g:cmake_project_generator set project generator +g:cmake_project_generator set project generator, however, this will have + no effect until you run :CMakeClean and :CMake. + + +OPTIONS *cmake-options* + +g:cmake_export_compile_commands same as -DCMAKE_EXPORT_COMPILE_COMMANDS=ON, useful for + exporting a compilation database to be used with YCM + (https://github.com/Valloric/YouCompleteMe#c-family-semantic-completion) From f0e126f4aaea2ba7a4b90a97c568953c8bc25b44 Mon Sep 17 00:00:00 2001 From: Squareys Date: Sat, 8 Apr 2017 18:30:58 +0200 Subject: [PATCH 21/29] Never implicitly delete existing cmake config See vim documentation. Just have the user use :CMakeClean explicitly, some projects have alot of configuration which should never get deleted by accident when using :CMake. Signed-off-by: Squareys --- plugin/cmake.vim | 54 +++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/plugin/cmake.vim b/plugin/cmake.vim index 926f7ca..a0aa3b9 100644 --- a/plugin/cmake.vim +++ b/plugin/cmake.vim @@ -12,6 +12,8 @@ endif " because the executable is not found. Otherwise the error message will be " displayed more than once. let loaded_cmake_plugin = 1 + +" Set option defaults if !exists("g:cmake_export_compile_commands") let g:cmake_export_compile_commands = 0 endif @@ -39,48 +41,42 @@ endfunction " Configure the cmake project in the currently set build dir. " -" :param force: Force configuration even if CMakeCache.txt already exists in -" build dir. This will override any of the following variables if the +" This will override any of the following variables if the " corresponding vim variable is set: " * CMAKE_INSTALL_PREFIX " * CMAKE_BUILD_TYPE " * CMAKE_BUILD_SHARED_LIBS -" In addition, previous configuration files will be deleted if the -" corresponding vim variables for the following are set: +" If the project is not configured already, the following variables will be set +" whenever the corresponding vim variable for the following is set: " * CMAKE_CXX_COMPILER " * CMAKE_C_COMPILER -" * The generator -" -" Will do nothing if the project is already configured and force is disabled. -function! s:cmake_configure(force) - if filereadable(s:build_dir . "/CMakeCache.txt") && !a:force - " Only change values of variables, if project is not configured - " already, otherwise we override existing configuration. - return - endif - +" * The generator (-G) +function! s:cmake_configure() exec 'cd' s:fnameescape(s:build_dir) - let s:cleanbuild = 0 let l:argument = [] - if exists("g:cmake_project_generator") - let l:argument += [ "-G \"" . g:cmake_project_generator . "\"" ] - let s:cleanbuild = 1 + " Only change values of variables, if project is not configured + " already, otherwise we overwrite existing configuration. + let l:configured = filereadable(s:build_dir . "/CMakeCache.txt") + + if !l:configured + if exists("g:cmake_project_generator") + let l:argument += [ "-G \"" . g:cmake_project_generator . "\"" ] + endif + if exists("g:cmake_cxx_compiler") + let l:argument += [ "-DCMAKE_CXX_COMPILER:FILEPATH=" . g:cmake_cxx_compiler ] + endif + if exists("g:cmake_c_compiler") + let l:argument += [ "-DCMAKE_C_COMPILER:FILEPATH=" . g:cmake_c_compiler ] + endif endif + 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:argument += [ "-DCMAKE_CXX_COMPILER:FILEPATH=" . g:cmake_cxx_compiler ] - let s:cleanbuild = 1 - endif - if exists("g:cmake_c_compiler") - let l:argument += [ "-DCMAKE_C_COMPILER:FILEPATH=" . g:cmake_c_compiler ] - let s:cleanbuild = 1 - endif if exists("g:cmake_build_shared_libs") let l:argument += [ "-DBUILD_SHARED_LIBS:BOOL=" . g:cmake_build_shared_libs ] endif @@ -90,10 +86,6 @@ function! s:cmake_configure(force) let l:argumentstr = join(l:argument, " ") - if s:cleanbuild > 0 - silent echo system("rm -r *" ) - endif - let s:cmd = 'cmake .. '. l:argumentstr . " " . join(a:000) echo s:cmd silent let s:res = system(s:cmd) @@ -121,7 +113,7 @@ function! s:cmake(...) if s:build_dir != "" let &makeprg = 'cmake --build ' . shellescape(s:build_dir) . ' --target' - call s:cmake_configure(0) + call s:cmake_configure() else echom "Unable to find build directory." endif From 06ff54d12307c3013d4d8b89cf60d0bed3fff31d Mon Sep 17 00:00:00 2001 From: Squareys Date: Sat, 8 Apr 2017 19:54:01 +0200 Subject: [PATCH 22/29] Add option to symlink compilation database for YouCompleteMe Including Vader test and vim documentation Signed-off-by: Squareys --- doc/cmake.txt | 4 ++++ plugin/cmake.vim | 16 +++++++++++++++- test/cmake.vader | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/doc/cmake.txt b/doc/cmake.txt index 600a69e..6107b1a 100644 --- a/doc/cmake.txt +++ b/doc/cmake.txt @@ -47,3 +47,7 @@ OPTIONS *cmake-options* g:cmake_export_compile_commands same as -DCMAKE_EXPORT_COMPILE_COMMANDS=ON, useful for exporting a compilation database to be used with YCM (https://github.com/Valloric/YouCompleteMe#c-family-semantic-completion) + CMake only supports this flag with Ninja and Makefile generators. + +g:cmake_ycm_symlinks create a symlink to the compile_commands.json file in the + root of the project (build/..) if the file is found. diff --git a/plugin/cmake.vim b/plugin/cmake.vim index a0aa3b9..81ceaae 100644 --- a/plugin/cmake.vim +++ b/plugin/cmake.vim @@ -17,6 +17,9 @@ let loaded_cmake_plugin = 1 if !exists("g:cmake_export_compile_commands") let g:cmake_export_compile_commands = 0 endif +if !exists("g:cmake_ycm_symlinks") + let g:cmake_ycm_symlinks = 0 +endif if !executable("cmake") echoerr "vim-cmake requires cmake executable. Please make sure it is installed and on PATH." @@ -37,6 +40,7 @@ function! s:find_build_dir() " this as an indicator that build was not found let s:build_dir = fnamemodify(s:build_dir, ':p') endif + endfunction " Configure the cmake project in the currently set build dir. @@ -57,7 +61,7 @@ function! s:cmake_configure() let l:argument = [] " Only change values of variables, if project is not configured " already, otherwise we overwrite existing configuration. - let l:configured = filereadable(s:build_dir . "/CMakeCache.txt") + let l:configured = filereadable("CMakeCache.txt") if !l:configured if exists("g:cmake_project_generator") @@ -91,6 +95,16 @@ function! s:cmake_configure() silent let s:res = system(s:cmd) echo s:res + " Create symbolic link to compilation database for use with YouCompleteMe + if g:cmake_ycm_symlinks && filereadable("compile_commands.json") + if has("win32") + exec "mklink" "../compile_commands.json" "compile_commands.json" + else + silent echo system("ln -s " . s:fnameescape(s:build_dir) ."/compile_commands.json ../compile_commands.json") + endif + echom "Created symlink to compilation database" + endif + exec 'cd -' endfunction diff --git a/test/cmake.vader b/test/cmake.vader index 3ecfe2f..0ac37b1 100644 --- a/test/cmake.vader +++ b/test/cmake.vader @@ -17,18 +17,32 @@ Before: After: exec "cd" fnameescape(test_dir) echo system("rm -rf 'test project/build'") + echo system("rm -f 'test project/compile_commands.json'") Execute (Find build directory from working dir): cd test\ project CMake Assert filereadable("build/CMakeCache.txt"), "CMakeCache.txt should be generated" + Assert !filereadable("build/compile_commands.json"), "Compile commands should not be exported by default" Execute (Find build directory from currently open file): e test\ project/CMakeLists.txt CMake Assert filereadable("test project/build/CMakeCache.txt"), "CMakeCache.txt should be generated" +Execute (Create symlink to compilation database): + let g:cmake_export_compile_commands = 1 + let g:cmake_ycm_symlinks = 1 + cd test\ project + CMake + + " Exporting compile commands does not work with Visual Studio generator + if !has("win32") && !has("win32unix") + Assert filereadable("build/compile_commands.json"), "Compile commands should be exported" + Assert filereadable(resolve("compile_commands.json")), "A symlink should be generated" + endif + Execute (Open already configured cmake project): cd test\ project/build silent !cmake .. -DWITH_BYE=ON From ff18ad028c17a23bb6bcb56aa0b2710fe8a4a7b7 Mon Sep 17 00:00:00 2001 From: Squareys Date: Sun, 9 Apr 2017 08:56:57 +0200 Subject: [PATCH 23/29] Suppress "--- More ---" prompts Signed-off-by: Squareys --- plugin/cmake.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/cmake.vim b/plugin/cmake.vim index 81ceaae..daa7648 100644 --- a/plugin/cmake.vim +++ b/plugin/cmake.vim @@ -93,7 +93,7 @@ function! s:cmake_configure() let s:cmd = 'cmake .. '. l:argumentstr . " " . join(a:000) echo s:cmd silent let s:res = system(s:cmd) - echo s:res + silent echo s:res " Create symbolic link to compilation database for use with YouCompleteMe if g:cmake_ycm_symlinks && filereadable("compile_commands.json") From ab2c44a909ff8ccb898387d7949ca24bd3383e32 Mon Sep 17 00:00:00 2001 From: Squareys Date: Sun, 9 Apr 2017 09:15:18 +0200 Subject: [PATCH 24/29] Ensure every test runs on a clean build directory Signed-off-by: Squareys --- test/cmake.vader | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/cmake.vader b/test/cmake.vader index 0ac37b1..74c2657 100644 --- a/test/cmake.vader +++ b/test/cmake.vader @@ -8,10 +8,8 @@ Before: let test_dir = fnamemodify(getcwd(), ':p') endif - if !isdirectory("test project/build") - echo system("mkdir 'test project/build'") - endif - + Assert !isdirectory("test project/build"), "TEST ERROR: build directory was not properly deleted" + echo system("mkdir 'test project/build'") Assert isdirectory("test project/build"), "TEST ERROR: build directory was not created" After: From e33b7f14506fe27df4bab789fa8503afe36f3a06 Mon Sep 17 00:00:00 2001 From: Squareys Date: Sun, 9 Apr 2017 10:44:09 +0200 Subject: [PATCH 25/29] Fix build folder being found in path rather than cwd or path of buffer Signed-off-by: Squareys --- plugin/cmake.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/cmake.vim b/plugin/cmake.vim index daa7648..6f7fb67 100644 --- a/plugin/cmake.vim +++ b/plugin/cmake.vim @@ -28,7 +28,7 @@ endif function! s:find_build_dir() let g:cmake_build_dir = get(g:, 'cmake_build_dir', 'build') - let s:build_dir = finddir(g:cmake_build_dir, '.;') + let s:build_dir = finddir(g:cmake_build_dir, expand(".") . ';') if s:build_dir == "" " Find build directory in path of current file From ad618b4ea19ba7fefd98ca425e3906f6a6ba5210 Mon Sep 17 00:00:00 2001 From: Squareys Date: Sun, 9 Apr 2017 11:07:08 +0200 Subject: [PATCH 26/29] Make build_dir variable buffer local Useful when working with multple projects with different build dirs. Also prevents re-searching for the build_dir if already found. Allows specifying a autocommand when switching buffers. Signed-off-by: Squareys --- plugin/cmake.vim | 52 +++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/plugin/cmake.vim b/plugin/cmake.vim index 6f7fb67..d457521 100644 --- a/plugin/cmake.vim +++ b/plugin/cmake.vim @@ -27,18 +27,29 @@ if !executable("cmake") endif function! s:find_build_dir() + " Do not overwrite already found build_dir, may be set explicitly + " by user. + if exists("b:build_dir") && b:build_dir != "" + return 1 + endif + let g:cmake_build_dir = get(g:, 'cmake_build_dir', 'build') - let s:build_dir = finddir(g:cmake_build_dir, expand(".") . ';') + let b:build_dir = finddir(g:cmake_build_dir, expand(".") . ';') - if s:build_dir == "" + if b:build_dir == "" " Find build directory in path of current file - let s:build_dir = finddir(g:cmake_build_dir, expand("%:p:h") . ';') + let b:build_dir = finddir(g:cmake_build_dir, expand("%:p:h") . ';') endif - if s:build_dir != "" + if b:build_dir != "" " expand() would expand "" to working directory, but we need " this as an indicator that build was not found - let s:build_dir = fnamemodify(s:build_dir, ':p') + let b:build_dir = fnamemodify(b:build_dir, ':p') + echom "Found cmake build directory: " . s:fnameescape(b:build_dir) + return 1 + else + echom "Unable to find cmake build directory." + return 0 endif endfunction @@ -56,7 +67,7 @@ endfunction " * CMAKE_C_COMPILER " * The generator (-G) function! s:cmake_configure() - exec 'cd' s:fnameescape(s:build_dir) + exec 'cd' s:fnameescape(b:build_dir) let l:argument = [] " Only change values of variables, if project is not configured @@ -100,7 +111,7 @@ function! s:cmake_configure() if has("win32") exec "mklink" "../compile_commands.json" "compile_commands.json" else - silent echo system("ln -s " . s:fnameescape(s:build_dir) ."/compile_commands.json ../compile_commands.json") + silent echo system("ln -s " . s:fnameescape(b:build_dir) ."/compile_commands.json ../compile_commands.json") endif echom "Created symlink to compilation database" endif @@ -121,27 +132,28 @@ endfunction " Public Interface: command! -nargs=? CMake call s:cmake() command! CMakeClean call s:cmakeclean() +command! CMakeFindBuildDir call s:cmake_find_build_dir() -function! s:cmake(...) +function! s:cmake_find_build_dir() + unlet b:build_dir call s:find_build_dir() +endfunction - if s:build_dir != "" - let &makeprg = 'cmake --build ' . shellescape(s:build_dir) . ' --target' - call s:cmake_configure() - else - echom "Unable to find build directory." +function! s:cmake(...) + if !s:find_build_dir() + return endif + let &makeprg = 'cmake --build ' . shellescape(b:build_dir) . ' --target' + call s:cmake_configure() endfunction function! s:cmakeclean() - call s:find_build_dir() - - if s:build_dir != "" - silent echo system("rm -r '" . s:build_dir. "'/*") - echom "Build directory has been cleaned." - else - echom "Unable to find build directory." + if !s:find_build_dir() + return endif + silent echo system("rm -r '" . b:build_dir. "'/*") + echom "Build directory has been cleaned." endfunction + From 9269c7d5ea3fc0b3798454b275825900cdc4cbc3 Mon Sep 17 00:00:00 2001 From: Squareys Date: Sun, 9 Apr 2017 11:18:45 +0200 Subject: [PATCH 27/29] Update README.md Signed-off-by: Squareys --- README.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 63caf26..d38357a 100644 --- a/README.md +++ b/README.md @@ -19,19 +19,27 @@ you can just use quickfix as with a normal Makefile project. * `:CMakeClean` deletes all files in the build directory. You can think of this as a CMake version of make clean. + * `:CMakeFindBuildDir` resets the build directory path set for the current buffer and then tries to find a new one. Useful if it previously found a wrong path to then reset it after a new build folder has been created for example. + ### Variables * `g:cmake_install_prefix` same as `-DCMAKE_INSTALL_PREFIX` * `g:cmake_build_type` same as `-DCMAKE_BUILD_TYPE` - * `g:cmake_cxx_compiler` same as `-DCMAKE_CXX_COMPILER`. The build directory will be cleared the next time you run :CMake. + * `g:cmake_cxx_compiler` same as `-DCMAKE_CXX_COMPILER`. Changes will have no effect until you run :CMakeClean and then :CMake. - * `g:cmake_c_compiler` same as `-DCMAKE_C_COMPILER`. The build directory will be cleared the next time you run :CMake. + * `g:cmake_c_compiler` same as `-DCMAKE_C_COMPILER`. Changes will have no effect until you run :CMakeClean and then :CMake. * `g:cmake_build_shared_libs` same as `-DBUILD_SHARED_LIBS` - * `g:cmake_project_generator` same as `-G`. The build directory will be cleared the next time you run :CMake. + * `g:cmake_project_generator` same as `-G`. Changes will have no effect until you run :CMakeClean and then :CMake. + + * `g:cmake_export_compile_commands` same as `-DCMAKE_EXPORT_COMPILE_COMMANDS`. + + * `g:cmake_ycm_symlinks` create symlinks to the generated compilation database for use with [YouCompleteMe](https://github.com/Valloric/YouCompleteMe/). + + * `b:build_dir` is the path to the cmake build directory for the current buffer. This variable is set with the first :CMake or :CMakeFindBuildDir call. Once found, it will not be searched for again unless you call :CMakeFindBuildDir. If automatic finding is not sufficient you can set this variable manually to the build dir of your choice. ## Installation @@ -56,6 +64,7 @@ With [Vundle.vim](https://github.com/VundleVim/Vundle.vim) simply add this repos ## Acknowledgements * Thanks to [Tim Pope](http://tpo.pe/), his plugins are really awesome. + * Thanks to [Junegunn Choi](https://junegunn.kr/), for [vader.vim](https://github.com/junegunn/vader.vim), which is the testing framework used for this plugin. * Also thanks to * @SteveDeFacto for extending this with more fine grained control. * @snikulov for enhancing makeprg. From a14c1adb885461764be3e563a40cb4a870c57839 Mon Sep 17 00:00:00 2001 From: Squareys Date: Sun, 9 Apr 2017 11:21:07 +0200 Subject: [PATCH 28/29] Update vim documentation Signed-off-by: Squareys --- doc/cmake.txt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/doc/cmake.txt b/doc/cmake.txt index 6107b1a..dc770a3 100644 --- a/doc/cmake.txt +++ b/doc/cmake.txt @@ -2,6 +2,7 @@ Authors: Dirk Van Haerenborgh Steven Batchelor + Jonathan Hale License: Same terms as Vim itself (see |license|) @@ -19,8 +20,13 @@ COMMANDS *cmake-commands* Also modifies the :make command to build in that directory. -:CMakeClean deletes all files in the build directory. You can - think of this as a CMake version of make clean. +:CMakeClean deletes all files in the build directory. You can + think of this as a CMake version of make clean. + +:CMakeFindBuildDir resets the build directory path set for the current buffer + and then tries to find a new one. Useful if it previously + found a wrong path to then reset it after a new build folder + has been created for example. VARIABLES *cmake-variables* @@ -41,6 +47,11 @@ g:cmake_build_dir set the cmake 'build' directory, default: 'buil g:cmake_project_generator set project generator, however, this will have no effect until you run :CMakeClean and :CMake. +b:build_dir the path to the cmake build directory for the current buffer. + This variable is set with the first :CMake or :CMakeFindBuildDir call. + Once found, it will not be searched for again unless you call + :CMakeFindBuildDir. If automatic finding is not sufficient you can set + this variable manually to the build dir of your choice. OPTIONS *cmake-options* From 5171f870fce30eef21a5e8647f3028f991896e7c Mon Sep 17 00:00:00 2001 From: Squareys Date: Sun, 9 Apr 2017 11:58:14 +0200 Subject: [PATCH 29/29] Fix some quirks with build dir finding especially on Travis CI Signed-off-by: Squareys --- plugin/cmake.vim | 4 ++-- test/cmake.vader | 23 ++++++++++++++--------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/plugin/cmake.vim b/plugin/cmake.vim index d457521..44a42db 100644 --- a/plugin/cmake.vim +++ b/plugin/cmake.vim @@ -34,11 +34,11 @@ function! s:find_build_dir() endif let g:cmake_build_dir = get(g:, 'cmake_build_dir', 'build') - let b:build_dir = finddir(g:cmake_build_dir, expand(".") . ';') + let b:build_dir = finddir(g:cmake_build_dir, ';') if b:build_dir == "" " Find build directory in path of current file - let b:build_dir = finddir(g:cmake_build_dir, expand("%:p:h") . ';') + let b:build_dir = finddir(g:cmake_build_dir, s:fnameescape(expand("%:p:h")) . ';') endif if b:build_dir != "" diff --git a/test/cmake.vader b/test/cmake.vader index 74c2657..a18ee77 100644 --- a/test/cmake.vader +++ b/test/cmake.vader @@ -8,26 +8,31 @@ Before: let test_dir = fnamemodify(getcwd(), ':p') endif - Assert !isdirectory("test project/build"), "TEST ERROR: build directory was not properly deleted" - echo system("mkdir 'test project/build'") - Assert isdirectory("test project/build"), "TEST ERROR: build directory was not created" + Assert !isdirectory("test project/tmp-build"), "TEST ERROR: build directory was not properly deleted" + echo system("mkdir 'test project/tmp-build'") + Assert isdirectory("test project/tmp-build"), "TEST ERROR: build directory was not created" + " Under travis CI the entire project is in a build/ directory + " which will make the search from cwd always return a result. + " To be able to test searching build dir from current file, the + " build dir needs to be named differently as a workaround. + let g:cmake_build_dir = "tmp-build" After: exec "cd" fnameescape(test_dir) - echo system("rm -rf 'test project/build'") + echo system("rm -rf 'test project/tmp-build'") echo system("rm -f 'test project/compile_commands.json'") Execute (Find build directory from working dir): cd test\ project CMake - Assert filereadable("build/CMakeCache.txt"), "CMakeCache.txt should be generated" - Assert !filereadable("build/compile_commands.json"), "Compile commands should not be exported by default" + Assert filereadable("tmp-build/CMakeCache.txt"), "CMakeCache.txt should be generated" + Assert !filereadable("tmp-build/compile_commands.json"), "Compile commands should not be exported by default" Execute (Find build directory from currently open file): e test\ project/CMakeLists.txt CMake - Assert filereadable("test project/build/CMakeCache.txt"), "CMakeCache.txt should be generated" + Assert filereadable("test project/tmp-build/CMakeCache.txt"), "CMakeCache.txt should be generated" Execute (Create symlink to compilation database): let g:cmake_export_compile_commands = 1 @@ -37,12 +42,12 @@ Execute (Create symlink to compilation database): " Exporting compile commands does not work with Visual Studio generator if !has("win32") && !has("win32unix") - Assert filereadable("build/compile_commands.json"), "Compile commands should be exported" + Assert filereadable("tmp-build/compile_commands.json"), "Compile commands should be exported" Assert filereadable(resolve("compile_commands.json")), "A symlink should be generated" endif Execute (Open already configured cmake project): - cd test\ project/build + cd test\ project/tmp-build silent !cmake .. -DWITH_BYE=ON e ../CMakeLists.txt CMake