[
  {
    "path": ".gitignore",
    "content": "test/test project/build/\ndoc/tags\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: vim\n\naddons:\n  apt:\n    sources:\n    - ubuntu-toolchain-r-test\n    - kubuntu-backports\n    packages:\n    - g++-4.7\n    - cmake\n\nbefore_script: |\n  git clone https://github.com/junegunn/vader.vim.git\n\nscript: |\n  vim -Nu 'test/.vimrc' -c 'Vader! test/cmake.vader'\n"
  },
  {
    "path": "README.md",
    "content": "# vim-cmake\n[![Travis (Linux)](https://travis-ci.org/vhdirk/vim-cmake.svg?branch=master)](https://travis-ci.org/vhdirk/vim-cmake)\n[![AppVeyor (Windows)](https://ci.appveyor.com/api/projects/status/ns1o9252o2rrmv6g?svg=true)](https://ci.appveyor.com/project/vhdirk/vim-cmake)\n\nvim-cmake is a Vim plugin to make working with CMake a little nicer.\n\nI got tired of navigating to the build directory each time, and I also\ndisliked setting makeprg manually each time. This plugin does just that.\n\n## Usage\n\n### Commands\n\n * `:CMake` searches for the closest directory named build in an upwards search,\nand whenever one is found, it runs the cmake command there, assuming the CMakeLists.txt\nfile is just one directory above. Any arguments given to :CMake will be directly passed\non to the cmake command. It also sets the working directory of the make command, so\nyou can just use quickfix as with a normal Makefile project.\nIf you have the [AsyncRun plugin](https://github.com/skywind3000/asyncrun.vim)\ninstalled, it will be used automatically and you will be able to check the\nresult of the cmake command in the quickfix as well.\n\n * `:CMakeClean` deletes all files in the build directory. You can think of this as a CMake version of make clean.\n\n * `: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.\n\n### Variables\n\n * `g:cmake_install_prefix` same as `-DCMAKE_INSTALL_PREFIX`\n\n * `g:cmake_build_type` same as `-DCMAKE_BUILD_TYPE`\n\n * `g:cmake_cxx_compiler` same as `-DCMAKE_CXX_COMPILER`. Changes will have no effect until you run :CMakeClean and then :CMake.\n\n * `g:cmake_c_compiler` same as `-DCMAKE_C_COMPILER`. Changes will have no effect until you run :CMakeClean and then :CMake.\n\n * `g:cmake_build_shared_libs` same as `-DBUILD_SHARED_LIBS`\n\n * `g:cmake_toolchain_file` same as `-DCMAKE_TOOLCHAIN_FILE`\n\n * `g:cmake_project_generator` same as `-G`. Changes will have no effect until you run :CMakeClean and then :CMake.\n\n * `g:cmake_export_compile_commands` same as `-DCMAKE_EXPORT_COMPILE_COMMANDS`.\n\n * `g:cmake_ycm_symlinks` create symlinks to the generated compilation database for use with [YouCompleteMe](https://github.com/Valloric/YouCompleteMe/).\n\n * `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.\n\n\n## Installation\n\n\n### Vim-pathogen\n\nWith [pathogen.vim](https://github.com/tpope/vim-pathogen) simply copy and paste:\n\n    cd ~/.vim/bundle\n    git clone git://github.com/vhdirk/vim-cmake.git\n\nOnce help tags have been generated, you can view the manual with\n`:help cmake`.\n\n### Vundle\n\nWith [Vundle.vim](https://github.com/VundleVim/Vundle.vim) simply add this repository to your plugins list:\n\n    Plugin 'vhdirk/vim-cmake'\n\n## Acknowledgements\n\n * Thanks to [Tim Pope](http://tpo.pe/), his plugins are really awesome.\n * 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.\n * Also thanks to\n    * @SteveDeFacto for extending this with more fine grained control.\n    * @snikulov for enhancing makeprg.\n    * @dapicester for allowing specifying targets.\n    * @thomasgubler for the build dir option.\n    * @antmd for fixing a bug with handing of spaces in directory names.\n    * @jmirabel for fixing concatenation of cmake arguments.\n    * @T4ng10r for the project generator option.\n    * @Squareys for a small overhaul of the project, the initial test and travis setup.\n\n## License\n\nCopyright (c) Dirk Van Haerenborgh, @SteveDeFacto. Distributed under the same terms as Vim itself.\nSee `:help license`.\n"
  },
  {
    "path": "appveyor.yml",
    "content": "os: Visual Studio 2015\n\ninstall:\n  - cinst vim\n  - cinst cmake\n  - set PATH=%PATH%;C:\\Program Files\\CMake\\bin\n  - git clone https://github.com/junegunn/vader.vim\n\nbuild_script:\n  - vim -Nu test/.vimrc -c 'Vader! test/cmake.vader' --not-a-term\n"
  },
  {
    "path": "doc/cmake.txt",
    "content": "*cmake.txt*  Vim plugin to make working with CMake a little nicer\n\nAuthors:  Dirk Van Haerenborgh <http://vhdirk.github.com/>\n          Steven Batchelor <http://SteveDeFacto.github.com/>\n          Jonathan Hale <http://github.com/Squareys/>\nLicense: Same terms as Vim itself (see |license|)\n\n\nINTRODUCTION                                    *cmake*\n\nWhen working on a CMake project, this plugin provides a single command that\nchanges the makeprg make command's working directory to the closest 'build'\ndirectory (see g:cmake_build_dir) upwards\n\nCOMMANDS                                        *cmake-commands*\n\n:CMake [args]           Runs the cmake command as 'cmake ..', starting in\n                        first directory called 'build', found in an upwards\n                        search. All arguments are directly passed on to CMake.\n                        Also modifies the :make command to build in\n                        that directory.\n\n:CMakeClean             deletes all files in the build directory. You can\n                        think of this as a CMake version of make clean.\n\n:CMakeFindBuildDir      resets the build directory path set for the current buffer\n                        and then tries to find a new one. Useful if it previously\n                        found a wrong path to then reset it after a new build folder\n                        has been created for example.\n\nVARIABLES                                        *cmake-variables*\n\ng:cmake_install_prefix           same as -DCMAKE_INSTALL_PREFIX\n\ng:cmake_build_type               same as -DCMAKE_BUILD_TYPE\n\ng:cmake_cxx_compiler             same as -DCMAKE_CXX_COMPILER, however, this will have\n                                 no effect until you run :CMakeClean and :CMake.\n\ng:cmake_c_compiler               same as -DCMAKE_C_COMPILER, however, this will have\n                                 no effect until you run :CMakeClean and :CMake.\n\ng:cmake_build_shared_libs        same as -DBUILD_SHARED_LIBS\n\ng:cmake_toolchain_file           same as -DCMAKE_TOOLCHAIN_FILE\n\ng:cmake_build_dir                set the cmake 'build' directory, default: 'build'\n\ng:cmake_project_generator        set project generator, however, this will have\n                                 no effect until you run :CMakeClean and :CMake.\n\ng:cmake_usr_args                 custom user arguments. Ex: 'let g:cmake_usr_args=\"-DDEBUG=YES\"'\n\nb:build_dir                      the path to the cmake build directory for the current buffer.\n                                 This variable is set with the first :CMake or :CMakeFindBuildDir call.\n                                 Once found, it will not be searched for again unless you call\n                                 :CMakeFindBuildDir. If automatic finding is not sufficient you can set\n                                 this variable manually to the build dir of your choice.\n\nOPTIONS                                        *cmake-options*\n\ng:cmake_export_compile_commands  same as -DCMAKE_EXPORT_COMPILE_COMMANDS=ON, useful for\n                                 exporting a compilation database to be used with YCM\n                                 (https://github.com/Valloric/YouCompleteMe#c-family-semantic-completion)\n                                 CMake only supports this flag with Ninja and Makefile generators.\n\ng:cmake_ycm_symlinks             create a symlink to the compile_commands.json file in the\n                                 root of the project (build/..) if the file is found.\n\n"
  },
  {
    "path": "plugin/cmake.vim",
    "content": "\" cmake.vim - Vim plugin to make working with CMake a little nicer\n\" Maintainer:   Dirk Van Haerenborgh <http://vhdirk.github.com/>\n\" Version:      0.2\n\nlet s:cmake_plugin_version = '0.2'\n\nif exists(\"loaded_cmake_plugin\")\n  finish\nendif\n\n\" We set this variable here even though the plugin may not actually be loaded\n\" because the executable is not found. Otherwise the error message will be\n\" displayed more than once.\nlet loaded_cmake_plugin = 1\n\n\" Set option defaults\nif !exists(\"g:cmake_export_compile_commands\")\n  let g:cmake_export_compile_commands = 0\nendif\nif !exists(\"g:cmake_ycm_symlinks\")\n  let g:cmake_ycm_symlinks = 0\nendif\nif !exists(\"g:cmake_use_smp\")\n  let g:cmake_use_smp = 0\nendif\n\nif !executable(\"cmake\")\n  echoerr \"vim-cmake requires cmake executable. Please make sure it is installed and on PATH.\"\n  finish\nendif\n\nfunction! s:find_build_dir()\n  \" Do not overwrite already found build_dir, may be set explicitly\n  \" by user.\n  if exists(\"b:build_dir\") && b:build_dir != \"\"\n    return 1\n  endif\n\n  let g:cmake_build_dir = get(g:, 'cmake_build_dir', 'build')\n  let b:build_dir = finddir(g:cmake_build_dir, ';')\n\n  if b:build_dir == \"\"\n    \" Find build directory in path of current file\n    let b:build_dir = finddir(g:cmake_build_dir, s:fnameescape(expand(\"%:p:h\")) . ';')\n  endif\n\n  if b:build_dir != \"\"\n    \" expand() would expand \"\" to working directory, but we need\n    \" this as an indicator that build was not found\n    let b:build_dir = fnamemodify(b:build_dir, ':p')\n    echom \"Found cmake build directory: \" . s:fnameescape(b:build_dir)\n    return 1\n  else\n    echom \"Unable to find cmake build directory.\"\n    return 0\n  endif\n\nendfunction\n\n\" Configure the cmake project in the currently set build dir.\n\"\n\" This will override any of the following variables if the\n\" corresponding vim variable is set:\n\"   * CMAKE_INSTALL_PREFIX\n\"   * CMAKE_BUILD_TYPE\n\"   * CMAKE_BUILD_SHARED_LIBS\n\" If the project is not configured already, the following variables will be set\n\" whenever the corresponding vim variable for the following is set:\n\"   * CMAKE_CXX_COMPILER\n\"   * CMAKE_C_COMPILER\n\"   * The generator (-G)\nfunction! s:cmake_configure(cmake_vim_command_args)\n  exec 'cd' s:fnameescape(b:build_dir)\n\n  let l:argument = []\n  \" Only change values of variables, if project is not configured\n  \" already, otherwise we overwrite existing configuration.\n  let l:configured = filereadable(\"CMakeCache.txt\")\n\n  if !l:configured\n    if exists(\"g:cmake_project_generator\")\n        let l:argument += [ \"-G \\\"\" . g:cmake_project_generator . \"\\\"\" ]\n    endif\n    if exists(\"g:cmake_cxx_compiler\")\n        let l:argument += [ \"-DCMAKE_CXX_COMPILER:FILEPATH=\"     . g:cmake_cxx_compiler ]\n    endif\n    if exists(\"g:cmake_c_compiler\")\n        let l:argument += [ \"-DCMAKE_C_COMPILER:FILEPATH=\"       . g:cmake_c_compiler ]\n    endif\n\n    if exists(\"g:cmake_usr_args\")\n      let l:argument+= [ g:cmake_usr_args ]\n    endif\n  endif\n\n  if exists(\"g:cmake_install_prefix\")\n    let l:argument += [ \"-DCMAKE_INSTALL_PREFIX:FILEPATH=\"  . g:cmake_install_prefix ]\n  endif\n  if exists(\"g:cmake_build_type\" )\n    let l:argument += [ \"-DCMAKE_BUILD_TYPE:STRING=\"         . g:cmake_build_type ]\n  endif\n  if exists(\"g:cmake_build_shared_libs\")\n    let l:argument += [ \"-DBUILD_SHARED_LIBS:BOOL=\"          . g:cmake_build_shared_libs ]\n  endif\n  if exists(\"g:cmake_toolchain_file\")\n    let l:argument += [ \"-DCMAKE_TOOLCHAIN_FILE:FILEPATH=\"  . g:cmake_toolchain_file ]\n  endif\n  if g:cmake_export_compile_commands\n    let l:argument += [ \"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON\" ]\n  endif\n\n  let l:argumentstr = join(l:argument, \" \")\n  let l:escaped_build_dir=s:fnameescape(b:build_dir)\n  let l:home_dir = \"-H\".l:escaped_build_dir.\"/..\"\n  let l:build_dir_path = \"-B\".l:escaped_build_dir\n  let s:cmd = 'cmake '.l:home_dir.' '.l:build_dir_path.' '.l:argumentstr . \" \" . join(a:cmake_vim_command_args)\n\n  echo s:cmd\n  if exists(\":AsyncRun\")\n    execute 'copen'\n    execute 'AsyncRun ' . s:cmd\n    execute 'wincmd p'\n  else\n    silent let s:res = system(s:cmd)\n    silent echo s:res\n  endif\n\n  \" Create symbolic link to compilation database for use with YouCompleteMe\n  if g:cmake_ycm_symlinks && filereadable(\"compile_commands.json\")\n    if has(\"win32\")\n      exec \"mklink\" \"../compile_commands.json\" \"compile_commands.json\"\n    else\n      silent echo system(\"ln -s \" . s:fnameescape(b:build_dir) .\"/compile_commands.json ../compile_commands.json\")\n    endif\n    echom \"Created symlink to compilation database\"\n  endif\n\n  exec 'cd -'\nendfunction\n\n\" Utility function\n\" Thanks to tpope/vim-fugitive\nfunction! s:fnameescape(file) abort\n  if exists('*fnameescape')\n    return fnameescape(a:file)\n  else\n    return escape(a:file,\" \\t\\n*?[{`$\\\\%#'\\\"|!<\")\n  endif\nendfunction\n\nfunction! s:find_smp()\n  if executable('nproc')\n    let l:nproc = system('nproc')\n    let b:smp = '-j' . substitute(l:nproc, '\\n\\+$', '', '')\n    return 1\n  endif\n  return 0\nendfunction\n\ncommand! -complete=customlist,ListTargets -nargs=1 Make :make <args>\nfunction! ListTargets(A, L, C)\n    if !exists(\"b:build_dir\")\n        return []\n    endif\n    let all_targets = split(system(\"cmake --build \". b:build_dir . \" --target help | awk ' NR > 1 {print $2}'\"), '\\n')\n    let targets = filter(all_targets, \"v:val =~ '^\" .. a:A .. \"'\")\n    return targets\nendfunction\n\n\" Public Interface:\ncommand! -nargs=? CMake call s:cmake(<f-args>)\ncommand! CMakeClean call s:cmakeclean()\ncommand! CMakeFindBuildDir call s:cmake_find_build_dir()\n\nfunction! s:cmake_find_build_dir()\n  unlet! b:build_dir\n  call s:find_build_dir()\nendfunction\n\nfunction! s:cmake(...)\n  if !s:find_build_dir()\n    return\n  endif\n\n  if g:cmake_use_smp && s:find_smp()\n    let l:smp = ' ' . shellescape(b:smp)\n  else\n    let l:smp = ''\n  endif\n\n  let &makeprg = 'cmake --build ' . shellescape(b:build_dir) . l:smp . ' --target'\n  call s:cmake_configure(a:000)\nendfunction\n\nfunction! s:cmakeclean()\n  if !s:find_build_dir()\n    return\n  endif\n\n  silent echo system(\"rm -r '\" . b:build_dir. \"'/*\")\n  echom \"Build directory has been cleaned.\"\nendfunction\n\n"
  },
  {
    "path": "test/.vimrc",
    "content": "filetype off\n\nset rtp+=vader.vim\nset rtp+=.\nfiletype plugin indent on\nsyntax enable\n\n"
  },
  {
    "path": "test/cmake.vader",
    "content": "Before:\n  \" Ensure we are in the test directory\n  if isdirectory(\"test\")\n    cd test\n  endif\n\n  if !exists(\"test_dir\")\n    let test_dir = fnamemodify(getcwd(), ':p')\n  endif\n\n  Assert !isdirectory(\"test project/tmp-build\"), \"TEST ERROR: build directory was not properly deleted\"\n  echo system(\"mkdir 'test project/tmp-build'\")\n  Assert isdirectory(\"test project/tmp-build\"), \"TEST ERROR: build directory was not created\"\n\n  \" Under travis CI the entire project is in a build/ directory\n  \" which will make the search from cwd always return a result.\n  \" To be able to test searching build dir from current file, the\n  \" build dir needs to be named differently as a workaround.\n  let g:cmake_build_dir = \"tmp-build\"\nAfter:\n  exec \"cd\" fnameescape(test_dir)\n  echo system(\"rm -rf 'test project/tmp-build'\")\n  echo system(\"rm -f 'test project/compile_commands.json'\")\n\nExecute (Find build directory from working dir):\n  cd test\\ project\n  CMake\n\n  Assert filereadable(\"tmp-build/CMakeCache.txt\"), \"CMakeCache.txt should be generated\"\n  Assert !filereadable(\"tmp-build/compile_commands.json\"), \"Compile commands should not be exported by default\"\n\nExecute (Find build directory from currently open file):\n  e test\\ project/CMakeLists.txt\n  CMake\n  Assert filereadable(\"test project/tmp-build/CMakeCache.txt\"), \"CMakeCache.txt should be generated\"\n\nExecute (Create symlink to compilation database):\n  let g:cmake_export_compile_commands = 1\n  let g:cmake_ycm_symlinks = 1\n  cd test\\ project\n  CMake\n\n  \" Exporting compile commands does not work with Visual Studio generator\n  if !has(\"win32\") && !has(\"win32unix\")\n    Assert filereadable(\"tmp-build/compile_commands.json\"), \"Compile commands should be exported\"\n    Assert filereadable(resolve(\"compile_commands.json\")), \"A symlink should be generated\"\n  endif\n\nExecute (Open already configured cmake project):\n  cd test\\ project/tmp-build\n  silent !cmake .. -DWITH_BYE=ON\n  e ../CMakeLists.txt\n  CMake\n  silent make\n\n  enew\n  if has(\"win32\") || has(\"win32unix\")\n    read !Debug/hello.exe\n  else\n    read !./hello\n  endif\nExpect:\n\n  Hello World\n  Bye World\n"
  },
  {
    "path": "test/test project/CMakeLists.txt",
    "content": "cmake_minimum_required(VERSION 2.8.12)\n\nproject(HelloWorld)\n\noption(WITH_BYE \"Print bye world\" OFF)\n\nconfigure_file(configure.h.cmake configure.h)\nadd_executable(hello main.cpp)\ntarget_include_directories(hello PRIVATE ${CMAKE_BINARY_DIR})\n"
  },
  {
    "path": "test/test project/configure.h.cmake",
    "content": "#cmakedefine WITH_BYE\n"
  },
  {
    "path": "test/test project/main.cpp",
    "content": "#include <iostream>\n#include \"configure.h\"\n\nint main() {\n    std::cout << \"Hello World\" << std::endl;\n#ifdef WITH_BYE\n    std::cout << \"Bye World\" << std::endl;\n#endif\n    return 0;\n}\n"
  }
]