CMake Editors Support: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
m (Update QtCreator link (it was broken))
(48 intermediate revisions by 18 users not shown)
Line 1: Line 1:
==CMake Editor Modes==
==CMake Editor Modes==


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


* Emacs [http://www.cmake.org/CMakeDocs/cmake-mode.el combined syntax highlighting and indentation mode]. To enable it, add the following to your ''.emacs'' file:
* '''[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://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).


<pre>
; 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)
* '''[http://www.kdevelop.org KDevelop 4]''' supports CMake-based projects natively.
</pre>


* 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:
* '''[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].
:autocmd BufRead,BufNewFile *.cmake,CMakeLists.txt,*.cmake.in runtime! indent/cmake.vim
:autocmd BufRead,BufNewFile *.cmake,CMakeLists.txt,*.cmake.in setf cmake
</pre>


* Eclipse [http://www.cthing.com/CMakeEd.asp CMake Editor]. Plug-in for the Eclipse IDE providing syntax coloring and content assist for editing CMakeLists.txt and any file ending in a .cmake extension. Integrates the CMake command reference documentation into the Eclipse Help system.
* '''[http://www.gnu.org/software/emacs Emacs]''': See the [[CMake/Editors/Emacs|CMake Emacs Support]] page.


* [http://kate.kde.org Kate], KWrite, [http://www.kdevelop.org KDevelop] and all other [http://www.kde.org KDE] applications, which use the kate text-editing component support cmake syntax highlighting. Currently you have to open the settings dialog and choose download (Settings -> Configure Kate -> Editor -> Highlighting -> Download) and there select CMake in the listbox. Then the cmake syntax highlighting definition file for kate will be downloaded and installed. From KDE 3.4 and later cmake syntax highlighting will come with standard KDE.
* '''Enscript''' [http://tristancarel.com/pub/patches/enscript/cmake.st syntax highlighting rules]. To enable it:
 
* UltraEdit (an approach) save the jpg as text: [[Image:wordfile.jpg]]
 
* Enscript [http://tristan-carel.com/pub/patches/enscript/cmake.st syntax highlighting rules]. To enable it:
*# copy <tt>cmake.st</tt> in the <tt>hl/</tt> directory.
*# copy <tt>cmake.st</tt> in the <tt>hl/</tt> directory.
*#add the following in the <tt>namerules</tt> section of the <tt>hl/enscript.st</tt> file:
*#add the following in the <tt>namerules</tt> section of the <tt>hl/enscript.st</tt> file:
Line 39: Line 28:
</pre>
</pre>


* [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 cmake lines.
* '''[http://www.lugaru.com Epsilon]''' has a CMake [http://lugaru.com/ftp/for-v13/cmake.e extension] that supports syntax highlighting, indentation, and auto-completion of expressions for control statements such as if-else-endif, foreach-endforeach, and while-endwhile.


* [http://www.macromates.com TextMate] is a wonderful text editor for OS X. [http://www.bluequartz.net/CMake.tmbundle.zip CMake Bundle]. This plugin adds syntax highlighting for Cmake files.
* '''[http://www.geany.org Geany]''' added CMake support in [http://www.geany.org/Main/20090215 version 0.16]


==Creating New Editor Mode==
* '''[http://kate.kde.org Kate]''', '''KWrite''', '''[http://www.kdevelop.org KDevelop]''' and all other [http://www.kde.org KDE] applications, which use the kate text-editing component support cmake syntax highlighting since KDE 3.4.


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:
* '''NEdit''' [http://www.cmake.org/Wiki/images/c/c6/NEditCMakeHighlighting-0001.tar.gz syntax highlighting support] was added by [http://public.kitware.com/pipermail/cmake/2007-May/014267.html Philippe Poilbarbe]


* CMakeLists.txt
* '''[http://notepad-plus.sourceforge.net/uk/site.htm Notepad++]''' added CMake support in version 4.1
* *.cmake
* *.cmake.in
* *.ctest
* *.ctest.in


* '''[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.


==Using CMake from Eclipse CDT==
* '''[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.eclipse.org Eclipse IDE] is an IDE written in Java that was initially for developing java programs. In the years lots of projects have used eclipse as a base for their own applications. One such project is the "C Development Tools" or CDT [http://
* '''[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.


Download Eclipse from Here. [http://download.eclipse.org/eclipse/downloads/ Download Page]
* '''UltraEdit''' syntax highlighting  [http://www.cmake.org/Wiki/images/5/56/UltraEditWordfile.tar.gz word file.]


CDT can be downloaded from here. [http://www.eclipse.org/cdt/downloads.php CDT Download]
* '''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:


It is important to match CDT with the proper Eclipse version.
<pre>
: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
</pre>


CDT 3.1.2 goes with Eclipse 3.2 --> These are the stable versions as of May 2007.
* '''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.
CDT 4.0 is a Major step forward and needs Eclipse 3.3 to run. Both of these projects are in Beta release as of May 2007. The final releases are supposed to be around mid June 2007.
As of May 13th 2007, if you want to try the latest versions then Eclipse 3.3M7 and CDT 4.0 RC0 are the matched pair that you will need.


Eclipse CDT supports makefile based projects. There are two ways that this is accomplished. You can let Eclipse CDT manage the makefile for you or you can supply your own makefile. This tutorial uses this second approach.
==Creating New Editor Mode==


Eclipse CDT can interoperate with CMake by creating a "Standard Makefile" project, running CMake, and then having CDT to run make on the generated makefiles. Eclipse CDT works better if the build files are somewhere in project directory, either in the top-level directory, or a subdirectory (for example Build).
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:


A typical workflow would be something like this.
* CMakeLists.txt
 
* *.cmake
In a terminal program "cd" into the top level of your project directory ideally where your CMakeLists.txt file resides. Create a directory called "Build".
* *.cmake.in
cd into Build and then run ccmake/cmake using the parent directory as the target for cmake. So, for example if we have a project called "MyGreatProject" located in /Users/mike/Projects, then the terminal commands would look like the following:
* *.ctest
 
* *.ctest.in
[mjackson@Thor:]$ cd /Users/mike/Projects/MyGreatProject
[mjackson@Thor:]$ mkdir Build
[mjackson@Thor:]$ cd Build
[mjackson@Thor:]$ ccmake ../
At this point we have bootstrapped the process somewhat so Eclipse throws less errors when we setup the Eclipse Projects.
 
Getting Eclipse updated with CDT is fairly easy if you download the tar.gz files for both Eclipse and CDT.
Untar the Eclipse distribution. This will create a directory called "eclipse".
Now untar CDT distribution so that the output from CDT merges with the "eclipse" directory. This is easiest done if both the eclipse distribution and the cdt distribution files are in the same directory. Then merely run tar -xvzf on both tar.gz files.
 
Launch Eclipse. Select /Users/mike/Projects as the "Workspace" (using the example from above).
Go to "File->New Project"
Select C++ Standard Makefile Project
Go through the wizard making the appropriate selections and entries.
At some point during this wizard there will be a tab that allows you to over ride the standard "make" command invocation. The tab may have a title such as "Make Builder". Uncheck "Use default" and enter the following into the "Build Command" text field.
 
"make -C ${project_loc}/Build" ( Without the quotes).
For multi-core systems and if you want to use multiple compile jobs, then use:
 
make -j2 -C ${project_loc}/Build  (where '2' is the number of jobs to use.Adjust for your own system)
 
There will also be another tab called "Binary Parsers". Select that tab and be sure that the appropriate binary type is selected for your system. Continue on with the wizard until finished.
 
Your new project should now be ready. Select the project in the C/C++ Projects view then select the "Project->Build Project" Menu to build your project.
 
Now, technically you _could_ use a completely out of source build and this will work with eclipse, but eclipse will be unable to find your binaries when finished, which makes the setup of debugging and running your app from Eclipse a bit more tricky.
 
If you edit your CMakeLists.txt file, then you will need to go back out to your terminal and rerun cmake. OR you can create an external program launch configuration and run cmake from within eclipse. To do this select the "Run->External Tools->Show External Tools Dialog..." menu.
Create a new "Program" and call it Cmake. in the "Location" text field, type the absolute path to cmake (/usr/local/bin/cmake). If the "Working Directory" area insert the following: "${project_loc}/Build" and in the Arguments section insert the following: "../". In the "Refresh Tab" Select ""The project containing the selected resources". In the "Common" tab check the "External Tools" selection. This will put a shortcut in the "Run" menu for you. Click the Apply Button and then run. cmake will now run on your project directory.
 
The CDT Error Parser cannot handle error messages that span more than one line, which is the default gcc behavior. In order to
force gcc to generate single line error messages with no line wrapping, add to your CMakeLists.txt:
 
IF(CMAKE_COMPILER_IS_GNUCC)
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fmessage-length=0")
ENDIF(CMAKE_COMPILER_IS_GNUCC)
IF(CMAKE_COMPILER_IS_GNUCXX)
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmessage-length=0")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
 
In order for the CDT discovery mechanism to catch the compiler options and definitions automatically from the
build output, enable the "Enable build output info discovery" in the project properties and set the CMAKE_VERBOSE_MAKEFILE
variable in your CMakeLists.txt.
 
SET(CMAKE_VERBOSE_MAKEFILE ON)
 
If you don't want to hard-code this behavior in CMakeLists.txt, you can achieve the same effect by
telling CDT to invoke make as
 
make VERBOSE=1
 
 
{{CMake/Template/Footer}}

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