CMake Editors Support: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
m (geany)
m (Update QtCreator link (it was broken))
(14 intermediate revisions by 9 users not shown)
Line 3: Line 3:
There are [[CMake]] syntax highlighting and indentation supports for many editors:
There are [[CMake]] syntax highlighting and indentation supports for many editors:


* '''Eclipse''' There are two plugins for Eclipse:
* '''[http://www.eclipse.org/cdt/ Eclipse]''' There are two plugins for Eclipse:
** The [http://cmakeed.sourceforge.net CMakeEd] plugin for Eclipse provides syntax coloring and content assist for editing CMakeLists.txt and any file ending in a .cmake extension. It also integrates the CMake command reference documentation into the Eclipse Help system. This plugin does NOT do project management for you or generate CMake files for you. You are still responsible for this part. CMakeEd just makes writing the CMakeLists.txt files easier.
** The [http://cmakeed.sourceforge.net CMakeEd] plugin for Eclipse provides syntax coloring and content assist for editing CMakeLists.txt and any file ending in a .cmake extension. It also integrates the CMake command reference documentation into the Eclipse Help system. This plugin does NOT do project management for you or generate CMake files for you. You are still responsible for this part. CMakeEd just makes writing the CMakeLists.txt files easier.
** The [http://www.cmakebuilder.com/ CMakeBuilder] plugin provides a user friendly interface to easily manage CMake-based projects, with the following features: advanced parser, Advanced CMake outline, CMakeBuilder perspective, symbol table and environment inspector, CMake files editor with syntax highlighting, code assist, wizard-oriented project management, Project Nature CMakeBuilder for CDT projects, and incremental project builders.
** The [http://www.cmakebuilder.com/ CMakeBuilder] plugin provides a user friendly interface to easily manage CMake-based projects, with the following features: advanced parser, Advanced CMake outline, CMakeBuilder perspective, symbol table and environment inspector, CMake files editor with syntax highlighting, code assist, wizard-oriented project management, Project Nature CMakeBuilder for CDT projects, and incremental project builders.
** '''[[Eclipse_CDT4_Generator|Here]]''' you find documentation how to use the Eclipse CDT project generator of CMake.
** '''[[CMake:Eclipse_UNIX_Tutorial|Here]]''' you find documentation how to use Eclipse with the regular Makefile generator of CMake (for versions < 2.6 of CMake).


* '''Emacs''' [http://www.cmake.org/CMakeDocs/cmake-mode.el combined syntax highlighting and indentation mode].  The file in the repository used to not function properly when running fill-paragraph (M-q).  There was a [[CMake Emacs mode patch for comment formatting|patched version]] to fix this, but it is largely unnecessary now that the one in the repository works properly now.  To enable it, add the following to your ''.emacs'' file:


<pre>
* '''[http://www.kdevelop.org KDevelop 4]''' supports CMake-based projects natively.
; Add cmake listfile names to the mode list.
(setq auto-mode-alist
  (append
  '(("CMakeLists\\.txt\\'" . cmake-mode))
  '(("\\.cmake\\'" . cmake-mode))
  auto-mode-alist))
 
(autoload 'cmake-mode "~/CMake/Docs/cmake-mode.el" t)
</pre>
 
I've been long irritated with having to deal with multiple buffers all name CMakeLists.txt.  Emacs by default will call them CMakeLists.txt, CMakeLists.txt<2>, CMakeLists.txt<3>, etc..  This is really hard to switch back and forth when the buffer names are difficult to associate with location.
 
I've found a couple of solutions to this problem.
 
<ol><li>Use uniquify emacs package.  This gives several options to automatically rename buffers based on their location on disk.
 
<pre>
;; uniquify.el is a helper routine to help give buffer names a better unique name.
(when (load "uniquify" 'NOERROR)
  (require 'uniquify)
  (setq uniquify-buffer-name-style 'forward)
  ;(setq uniquify-buffer-name-style 'post-forward)
  )
</pre>
</li>


<li>Rename the buffer as part of the cmake-mode
* '''[http://qt-project.org/wiki/category:tools::qtcreator QtCreator]''' supports CMake-based projects [https://qt-project.org/doc/qtcreator-2.8/creator-project-cmake.html natively since version 1.1].


<pre>
* '''[http://www.netbeans.org NetBeans]''' supports CMake-based projects [http://forums.netbeans.org/ntopic26390.html natively since version 6.8].
(defun cmake-rename-buffer ()
  "Renames a CMakeLists.txt buffer to cmake-<directory name>."
  (interactive)
  ;(print (concat "buffer-filename = " (buffer-file-name)))
  ;(print (concat "buffer-name    = " (buffer-name)))
  (when (and (buffer-file-name) (string-match "CMakeLists.txt" (buffer-name)))
      ;(setq file-name (file-name-nondirectory (buffer-file-name)))
      (setq parent-dir (file-name-nondirectory (directory-file-name (file-name-directory (buffer-file-name)))))
      ;(print (concat "parent-dir = " parent-dir))
      (setq new-buffer-name (concat "cmake-" parent-dir))
      ;(print (concat "new-buffer-name= " new-buffer-name))
      (rename-buffer new-buffer-name t)
      )
  )


(add-hook 'cmake-mode-hook (function cmake-rename-buffer))
* '''[http://www.gnu.org/software/emacs Emacs]''': See the [[CMake/Editors/Emacs|CMake Emacs Support]] page.
</pre>
</li></ol>
 
I actually prefer renaming my buffers with my cmake-rename-buffer function, because the buffer names start with a lower case letter. :)


* '''Enscript''' [http://tristancarel.com/pub/patches/enscript/cmake.st syntax highlighting rules]. To enable it:
* '''Enscript''' [http://tristancarel.com/pub/patches/enscript/cmake.st syntax highlighting rules]. To enable it:
Line 82: Line 40:
* '''[http://scintilla.sourceforge.net/SciTEDownload.html SciTE]''' version 1.73 has CMake support. To enable the feature edit SciTEGlobal.Properties and remove the comment before the CMake lines.
* '''[http://scintilla.sourceforge.net/SciTEDownload.html SciTE]''' version 1.73 has CMake support. To enable the feature edit SciTEGlobal.Properties and remove the comment before the CMake lines.


* '''[http://www.macromates.com TextMate]''' is a wonderful text editor for OS X. [http://www.bluequartz.net/software/files/CMake.tmbundle.pkg CMake Bundle]. This plugin adds syntax highlighting for CMake files and rudimentary completion for command, properties and cmake variables.
* '''[http://www.sublimetext.com/ Sublime Text]''' Sublime Text is a sophisticated text editor for code, markup and prose. You'll love the slick user interface, extraordinary features and amazing performance. CMake synatx support is provided through the [https://sublime.wbond.net/ Package Control] and the [https://sublime.wbond.net/packages/CMake CMake Package].
 
* '''[http://www.macromates.com TextMate]''' is a wonderful text editor for OS X. [http://www.bluequartz.net/binaries/CMake.tmbundle.zip CMake Bundle]. This plugin adds syntax highlighting for CMake files and rudimentary completion for command, properties and cmake variables.


* '''UltraEdit''' syntax highlighting  [http://www.cmake.org/Wiki/images/5/56/UltraEditWordfile.tar.gz word file.]
* '''UltraEdit''' syntax highlighting  [http://www.cmake.org/Wiki/images/5/56/UltraEditWordfile.tar.gz word file.]


* '''VIM''' [http://www.cmake.org/CMakeDocs/cmake-syntax.vim syntax highlighting] and [http://www.cmake.org/CMakeDocs/cmake-indent.vim indentation mode]. To enable indentation, copy indentation file to your .vim/indent directory, syntax highlighting file to your .vim/syntax directory and add the following to your .vimrc:
* '''VIM''' [http://cmake.org/gitweb?p=cmake.git;a=blob_plain;hb=master;f=Docs/cmake-syntax.vim syntax highlighting] and [http://cmake.org/gitweb?p=cmake.git;a=blob_plain;hb=master;f=Docs/cmake-indent.vim indentation mode]. To enable indentation, copy indentation file to your .vim/indent directory, syntax highlighting file to your .vim/syntax directory and add the following to your .vimrc:


<pre>
<pre>
Line 93: Line 53:
:autocmd BufRead,BufNewFile *.ctest,*.ctest.in setf cmake
:autocmd BufRead,BufNewFile *.ctest,*.ctest.in setf cmake
</pre>
</pre>
* '''Visual Studio 2010 Professional''' and above have two extensions available for editing CMake files.  [http://code.google.com/p/vissemee Vissemee] provides syntax highlighting for CMake.  [http://cmaketools.codeplex.com CMake Tools for Visual Studio] provides both syntax highlighting and IntelliSense for CMake.


==Creating New Editor Mode==
==Creating New Editor Mode==

Revision as of 03:33, 9 September 2014

CMake Editor Modes

There are CMake syntax highlighting and indentation supports for many editors:

  • Eclipse There are two plugins for Eclipse:
    • The CMakeEd plugin for Eclipse provides syntax coloring and content assist for editing CMakeLists.txt and any file ending in a .cmake extension. It also integrates the CMake command reference documentation into the Eclipse Help system. This plugin does NOT do project management for you or generate CMake files for you. You are still responsible for this part. CMakeEd just makes writing the CMakeLists.txt files easier.
    • The CMakeBuilder plugin provides a user friendly interface to easily manage CMake-based projects, with the following features: advanced parser, Advanced CMake outline, CMakeBuilder perspective, symbol table and environment inspector, CMake files editor with syntax highlighting, code assist, wizard-oriented project management, Project Nature CMakeBuilder for CDT projects, and incremental project builders.
    • Here you find documentation how to use the Eclipse CDT project generator of CMake.
    • Here you find documentation how to use Eclipse with the regular Makefile generator of CMake (for versions < 2.6 of CMake).


  • KDevelop 4 supports CMake-based projects natively.
  • Enscript syntax highlighting rules. To enable it:
    1. copy cmake.st in the hl/ directory.
    2. add the following in the namerules section of the hl/enscript.st file:
  /CMakeLists\.txt/               cmake;
  /\.cmake.*$/                    cmake;
  /\.ctest.*$/                    cmake;
  • Epsilon has a CMake extension that supports syntax highlighting, indentation, and auto-completion of expressions for control statements such as if-else-endif, foreach-endforeach, and while-endwhile.
  • Kate, KWrite, KDevelop and all other KDE applications, which use the kate text-editing component support cmake syntax highlighting since KDE 3.4.
  • SciTE version 1.73 has CMake support. To enable the feature edit SciTEGlobal.Properties and remove the comment before the CMake lines.
  • Sublime Text Sublime Text is a sophisticated text editor for code, markup and prose. You'll love the slick user interface, extraordinary features and amazing performance. CMake synatx support is provided through the Package Control and the CMake Package.
  • TextMate is a wonderful text editor for OS X. CMake Bundle. This plugin adds syntax highlighting for CMake files and rudimentary completion for command, properties and cmake variables.
  • VIM syntax highlighting and indentation mode. To enable indentation, copy indentation file to your .vim/indent directory, syntax highlighting file to your .vim/syntax directory and add the following to your .vimrc:
:autocmd BufRead,BufNewFile *.cmake,CMakeLists.txt,*.cmake.in runtime! indent/cmake.vim 
:autocmd BufRead,BufNewFile *.cmake,CMakeLists.txt,*.cmake.in setf cmake
:autocmd BufRead,BufNewFile *.ctest,*.ctest.in setf cmake
  • Visual Studio 2010 Professional and above have two extensions available for editing CMake files. Vissemee provides syntax highlighting for CMake. CMake Tools for Visual Studio provides both syntax highlighting and IntelliSense for CMake.

Creating New Editor Mode

The best way to start is to check the logic in existing ones. Make sure to enable indentation for files that match the following file names:

  • CMakeLists.txt
  • *.cmake
  • *.cmake.in
  • *.ctest
  • *.ctest.in