Skip to content
This repository has been archived by the owner on Jul 30, 2019. It is now read-only.

Update to CMake 3.7.1 - but not only #5

Open
wants to merge 70 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
896ecc3
schemes: use original scheme as provided by vim
pboettch Apr 26, 2016
c6cfa56
keywords: add some keywords which are found inside commands
pboettch Apr 26, 2016
0229982
more keywords
pboettch May 1, 2016
b1b0f65
added more keywords
pboettch May 9, 2016
285f6bd
use the same highlighting for properties as for keywords
pboettch May 9, 2016
35be38d
add case-sensitivity for keywords
pboettch May 9, 2016
811649c
add more keywords
pboettch May 9, 2016
2355c6e
more keywords (find_package)
pboettch May 9, 2016
3bf8d6c
add_library keywords
pboettch May 10, 2016
8d09099
keywords: add_custom_command
pboettch May 10, 2016
9ab3445
add script to extract all unique upper-case words from stdin
pboettch May 10, 2016
a6e96f9
update script for extracting upper-case words
pboettch May 10, 2016
00b14d2
add script to generate syntax-file
pboettch May 26, 2016
ab68610
improve script which extract keywords with an unwanted-list
pboettch May 27, 2016
db041eb
keywords: ignore NOTFOUND and NO_
pboettch Jun 28, 2016
c22780c
module: add syntax for ExternalProject
pboettch Jun 28, 2016
d2ff170
add generator-expression highlighting
pboettch Jul 20, 2016
bf86b3d
add some more authors
pboettch Jul 21, 2016
8aaa237
backport from upstream
pboettch Jul 27, 2016
ec8cbae
update script to reflect changes import by upstream
pboettch Jul 27, 2016
7c4a46b
use ModeMsg for GeneratorExpressions as well
pboettch Jul 27, 2016
e782679
remove empty line at EOF - to make KWRobot happy
pboettch Aug 16, 2016
eb4537d
no tab in CMake-files
pboettch Oct 23, 2016
933b6ae
update syntax to cmake-version 3.7.1
pboettch Dec 23, 2016
545bddc
fix highlighting of keyword variables in ${}-regions and cleanups
pboettch May 1, 2017
9c06c8f
README updated
pboettch May 1, 2017
2ca39d2
make keywords contained, to inhibit highlighting when outside highlig…
pboettch May 2, 2017
6cb8352
do not highlight strings outside regions
pboettch May 2, 2017
1552619
update to 3.8.20170502-g7a806
pboettch May 2, 2017
de7c907
extract properties as well
pboettch May 29, 2017
5e4f971
update keywords to latest cmake-revision
pboettch May 29, 2017
96ee548
fix #1 - highlight escaped quotes in strings
pboettch May 23, 2017
d791d3a
README updated, install instruction
pboettch May 29, 2017
e12d6cb
do not highlight cmake-commands in cmake-command argument-list
pboettch May 30, 2017
d2d564a
multi-line comments are now highlighted (again)
pboettch May 31, 2017
0e62850
update keywords to v3.9.1-460-gce2750817
pboettch Aug 14, 2017
84967b5
Skip escaped quotes in cmakeString
blueyed Aug 28, 2017
65932f0
add test-framework and two tests
pboettch Aug 30, 2017
018855b
add cpo-saving and restoring (taken from vim's upstream-syntax-files)
pboettch Aug 30, 2017
8fcb0a7
updated keywords to 3.9.20170830-ge0713
pboettch Aug 30, 2017
40f5f4f
preparations to be for inclusion to vim-repo
pboettch Aug 30, 2017
4e3a59c
Small cleanups asked by Bram
dmerejkowsky Sep 10, 2017
ecff992
Add Dimitri as maintainer for the indent file too
dmerejkowsky Sep 10, 2017
c6a2f17
indent/cmake.vim: save and restore cpo option
dmerejkowsky Sep 10, 2017
9e9ad02
do not force expandtabs for all cmake-users
pboettch Sep 18, 2017
f2a8a21
cmake indent: replace &sw by shiftwidth()
dmerejkowsky Sep 23, 2017
a8a846f
update keywords to 3.10.20171031-gfd2e6
pboettch Oct 31, 2017
2c9d5fd
handle bracket-comments and arguments correctly
pboettch Jun 4, 2018
37d3bcb
add test for bracket-comments and arguments
pboettch Jun 4, 2018
baf680a
Add syntax for new cmake variables
phcerdan Oct 9, 2018
99b4a3d
promote package_config_file-st to .in-file and add test
pboettch Oct 10, 2018
3ed26c2
update to cmake version 3.13.20181010-ga3598
pboettch Oct 10, 2018
ac1957f
update README
pboettch Oct 10, 2018
64ff4bd
break line after each high-lighting keyword (fix #10)
pboettch Oct 18, 2018
4e657a0
update to cmake version 3.13.20181220-g0495c
pboettch Dec 20, 2018
b0ada6e
add <LANG>-replacing in variables.
pboettch Dec 20, 2018
60654a6
Update keywords for version 3.14.20190402-g56ae2
pboettch Apr 2, 2019
33e512b
format brace-encapsulated variables (varname from var)
pboettch Apr 15, 2019
a3628eb
fix keywords of generator-expressions wrongly colored in simple argum…
pboettch May 29, 2019
c42ede9
update to cmake version 3.14.20190529-g067a4f
pboettch May 29, 2019
3925b48
update to cmake version 3.16.20191028-g0e4190b
pboettch Oct 28, 2019
2cf6c04
Add Doxygen keywords
MindTooth Oct 27, 2019
bcc3a97
update to cmake version 3.19.20201028-gdab947f
pboettch Oct 28, 2020
5cb0409
update keywords to 3.26.4
pboettch Jul 13, 2023
ddb54ba
Fix spell checking inside CMake functions
vadz Mar 23, 2020
0f46703
fix bracket-comment-regex
pboettch Jul 13, 2023
7912169
add syntax for FetchContent
pboettch Jul 13, 2023
9578e40
blacklist GNU as keyword
pboettch Jul 13, 2023
7c6f28d
update to cmake version 3.27.20230713-gdc88dd5
pboettch Jul 13, 2023
589a68d
Fix typo in dependency provider method keyword
craigscott-crascit Dec 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
# vim-cmake-syntax
Vim syntax highlighting rules for modern CMake.

The vim syntax rules shipped with vim are out-of-date. These ones are less so.
Vim syntax highlighting rules for modern CMakeLists.txt.

Original code from KitWare.
First hosted on Github by Nicholas Hutchinson.
Extended and modified by Patrick Boettcher and contributors

Keyword update - refer to syntax/cmake.vim-header.

The code of this repository is integrated in and released with CMake and is pulled
into the official cmake-distribution "from time to time".

## Installation

With Pathogen

cd ~/.vim/bundle
git clone git://github.com/pboettch/vim-cmake-syntax.git

With Vundle

" inside .vimrc
Plugin 'pboettch/vim-cmake-syntax'

## Test

There is a ever growing test-suite based on ctest located in test/

cd <build-dir-where-ever-located>
cmake path/to/this/repo/test
ctest
130 changes: 130 additions & 0 deletions cmake.vim.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
" Vim syntax file
" Program: CMake - Cross-Platform Makefile Generator
" Version: @VERSION@
" Language: CMake
" Author: Andy Cedilnik <[email protected]>,
" Nicholas Hutchinson <[email protected]>,
" Patrick Boettcher <[email protected]>
" Maintainer: Dimitri Merejkowsky <[email protected]>
" Former Maintainer: Karthik Krishnan <[email protected]>
" Last Change: @DATE@
"
" Licence: The CMake license applies to this file. See
" https://cmake.org/licensing
" This implies that distribution with Vim is allowed

if exists("b:current_syntax")
finish
endif
let s:keepcpo= &cpo
set cpo&vim

syn region cmakeBracketArgument start="\[\z(=\?\|=[0-9]*\)\[" end="\]\z1\]" contains=cmakeTodo,@Spell

syn region cmakeComment start="#" end="$" contains=cmakeTodo,@Spell
syn region cmakeBracketComment start="\[\z(=*\)\[" end="\]\z1\]" contains=cmakeTodo,@Spell

syn match cmakeEscaped /\(\\\\\|\\"\|\\n\|\\t\)/ contained
syn region cmakeRegistry start="\[" end="]" contained oneline contains=cmakeTodo,cmakeEscaped

syn region cmakeGeneratorExpression start="$<" end=">" contained oneline contains=cmakeVariableValue,cmakeProperty,cmakeGeneratorExpressions,cmakeTodo

syn region cmakeString start='"' end='"' contained contains=cmakeTodo,cmakeVariableValue,cmakeEscaped,@Spell

syn region cmakeVariableValue start="${" end="}" contained oneline contains=cmakeVariable,cmakeTodo,cmakeVariableValue

syn region cmakeEnvironment start="$ENV{" end="}" contained oneline contains=cmakeTodo

syn region cmakeArguments start="(" end=")" contains=ALLBUT,cmakeGeneratorExpressions,cmakeCommand,cmakeCommandConditional,cmakeCommandRepeat,cmakeCommandDeprecated,cmakeCommandManuallyAdded,cmakeArguments,cmakeTodo,@Spell

syn case match

syn keyword cmakeProperty contained
@PROPERTIES@

syn keyword cmakeVariable contained
@VARIABLE_LIST@

syn keyword cmakeModule contained
@MODULES@

@KEYWORDS@

syn keyword cmakeGeneratorExpressions contained
@GENERATOR_EXPRESSIONS@

syn case ignore

syn keyword cmakeCommand
@COMMAND_LIST@
\ nextgroup=cmakeArguments

syn keyword cmakeCommandConditional
@CONDITIONALS@
\ nextgroup=cmakeArguments

syn keyword cmakeCommandRepeat
@LOOPS@
\ nextgroup=cmakeArguments

syn keyword cmakeCommandDeprecated
@DEPRECATED@
\ nextgroup=cmakeArguments

syn case match

syn keyword cmakeTodo
\ TODO FIXME XXX
\ contained

hi def link cmakeBracketArgument String
hi def link cmakeBracketComment Comment
hi def link cmakeCommand Function
hi def link cmakeCommandConditional Conditional
hi def link cmakeCommandDeprecated WarningMsg
hi def link cmakeCommandRepeat Repeat
hi def link cmakeComment Comment
hi def link cmakeEnvironment Special
hi def link cmakeEscaped Special
hi def link cmakeGeneratorExpression WarningMsg
hi def link cmakeGeneratorExpressions Constant
hi def link cmakeModule Include
hi def link cmakeProperty Constant
hi def link cmakeRegistry Underlined
hi def link cmakeString String
hi def link cmakeTodo TODO
hi def link cmakeVariableValue Type
hi def link cmakeVariable Identifier

@KEYWORDS_HIGHLIGHT@

" Manually added - difficult to parse out of documentation
syn case ignore

syn keyword cmakeCommandManuallyAdded
\ configure_package_config_file write_basic_package_version_file
\ nextgroup=cmakeArguments

syn case match

syn keyword cmakeKWconfigure_package_config_file contained
\ INSTALL_DESTINATION PATH_VARS NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO INSTALL_PREFIX

syn keyword cmakeKWconfigure_package_config_file_constants contained
\ AnyNewerVersion SameMajorVersion SameMinorVersion ExactVersion

syn keyword cmakeKWwrite_basic_package_version_file contained
\ VERSION COMPATIBILITY

hi def link cmakeCommandManuallyAdded Function

hi def link cmakeKWconfigure_package_config_file ModeMsg
hi def link cmakeKWwrite_basic_package_version_file ModeMsg
hi def link cmakeKWconfigure_package_config_file_constants Constant

let b:current_syntax = "cmake"

let &cpo = s:keepcpo
unlet s:keepcpo

" vim: set nowrap:
213 changes: 213 additions & 0 deletions extract-upper-case.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
#!/usr/bin/env perl

use strict;
use warnings;
use POSIX qw(strftime);
use JSON;
use File::Basename;

#my $cmake = "/home/pboettch/devel/upstream/cmake/build/bin/cmake";
my $cmake = "cmake";

my @variables;
my @commands;
my @properties;
my @modules;
my %keywords; # command => keyword-list

# find cmake/Modules/ | sed -rn 's/.*CMakeDetermine(.+)Compiler.cmake/\1/p' | sort
my @languages = qw(ASM ASM_MASM ASM_NASM C CSharp CUDA CXX Fortran Java RC Swift HIP);

# unwanted upper-cases
my %unwanted = map { $_ => 1 } qw(VS CXX IDE NOTFOUND NO_ DFOO DBAR NEW GNU);
# cannot remove ALL - exists for add_custom_command

# control-statements
my %conditional = map { $_ => 1 } qw(if else elseif endif);
my %loop = map { $_ => 1 } qw(foreach while endforeach endwhile);

# decrecated
my %deprecated = map { $_ => 1 } qw(build_name exec_program export_library_dependencies install_files install_programs install_targets link_libraries make_directory output_required_files remove subdir_depends subdirs use_mangled_mesa utility_source variable_requires write_file);

# add some (popular) modules
push @modules, "ExternalProject", "FetchContent";

# variables
open(CMAKE, "$cmake --help-variable-list|") or die "could not run cmake";
while (<CMAKE>) {
chomp;

if (/<(.*?)>/) {
if ($1 eq 'LANG') {
foreach my $lang (@languages) {
(my $V = $_) =~ s/<.*>/$lang/;
push @variables, $V;
}

next
} else {
next; # skip if containing < or >
}
}

push @variables, $_;
}
close(CMAKE);

# transform all variables in a hash - to be able to use exists later on
my %variables = map { $_ => 1 } @variables;

# commands
open(CMAKE, "$cmake --help-command-list|");
while (my $cmd = <CMAKE>) {
chomp $cmd;
push @commands, $cmd;
}
close(CMAKE);

# now generate a keyword-list per command
foreach my $cmd (@commands) {
my @word = extract_upper("$cmake --help-command $cmd|");

next if scalar @word == 0;

$keywords{$cmd} = [ sort keys %{ { map { $_ => 1 } @word } } ];
}

# and now for modules
foreach my $mod (@modules) {
my @word = extract_upper("$cmake --help-module $mod|");

next if scalar @word == 0;

$keywords{$mod} = [ sort keys %{ { map { $_ => 1 } @word } } ];
}

# and now for generator-expressions
my @generator_expr = extract_upper("$cmake --help-manual cmake-generator-expressions |");

# properties
open(CMAKE, "$cmake --help-property-list|");
while (<CMAKE>) {
next if /\</; # skip if containing < or >
chomp;
push @properties, $_;
}
close(CMAKE);

# transform all properties in a hash
my %properties = map { $_ => 1 } @properties;

# read in manually written files
my $modules_dir = dirname(__FILE__) . "/modules";
opendir(DIR, $modules_dir) || die "can't opendir $modules_dir: $!";
my @json_files = grep { /\.json$/ && -f "$modules_dir/$_" } readdir(DIR);
closedir DIR;

foreach my $file (@json_files) {
local $/; # Enable 'slurp' mode
open my $fh, "<", $modules_dir."/".$file;
my $json = <$fh>;
close $fh;

my $mod = decode_json($json);
foreach my $var (@{$mod->{variables}}) {
$variables{$var} = 1;
}

while (my ($cmd, $keywords) = each %{$mod->{commands}}) {
$keywords{$cmd} = [ sort @{$keywords} ];
}
}

# version
open(CMAKE, "$cmake --version|");
my $version = 'unknown';
while (<CMAKE>) {
chomp;
$version = $_ if /cmake version/;
}
close(CMAKE);

# generate cmake.vim
open(IN, "<cmake.vim.in") or die "could not read cmake.vim.in";
open(OUT, ">syntax/cmake.vim") or die "could not write to syntax/cmake.vim";

my @keyword_hi;

while(<IN>)
{
if (m/\@([A-Z0-9_]+)\@/) { # match for @SOMETHING@
if ($1 eq "COMMAND_LIST") {
# do not include "special" commands in this list
my @tmp = grep { ! exists $conditional{$_} and
! exists $loop{$_} and
! exists $deprecated{$_} } @commands;
print_list(\*OUT, @tmp);
} elsif ($1 eq "VARIABLE_LIST") {
print_list(\*OUT, keys %variables);
} elsif ($1 eq "MODULES") {
print_list(\*OUT, @modules);
} elsif ($1 eq "GENERATOR_EXPRESSIONS") {
print_list(\*OUT, @generator_expr);
} elsif ($1 eq "CONDITIONALS") {
print_list(\*OUT, keys %conditional);
} elsif ($1 eq "LOOPS") {
print_list(\*OUT, keys %loop);
} elsif ($1 eq "DEPRECATED") {
print_list(\*OUT, keys %deprecated);
} elsif ($1 eq "PROPERTIES") {
print_list(\*OUT, keys %properties);
} elsif ($1 eq "KEYWORDS") {
foreach my $k (sort keys %keywords) {
print OUT "syn keyword cmakeKW$k contained\n";
print_list(\*OUT, @{$keywords{$k}});
print OUT "\n";
push @keyword_hi, "hi def link cmakeKW$k ModeMsg";
}
} elsif ($1 eq "KEYWORDS_HIGHLIGHT") {
print OUT join("\n", @keyword_hi), "\n";
} elsif ($1 eq "VERSION") {
$_ =~ s/\@VERSION\@/$version/;
print OUT $_;
} elsif ($1 eq "DATE") {
my $date = strftime "%Y %b %d", localtime;
$_ =~ s/\@DATE\@/$date/;
print OUT $_;
} else {
print "ERROR do not know how to replace $1\n";
}
} else {
print OUT $_;
}
}
close(IN);
close(OUT);

sub extract_upper
{
my $input = shift;
my @word;

open(KW, $input);
while (<KW>) {
foreach my $w (m/\b([A-Z_]{2,})\b/g) {
next
if exists $variables{$w} or # skip if it is a variable
exists $unwanted{$w} or # skip if not wanted
grep(/$w/, @word); # skip if already in array

push @word, $w;
}
}
close(KW);

return @word;
}

sub print_list
{
my $O = shift;
my $indent = " " x 12 . "\\ ";
print $O $indent, join("\n" . $indent, sort @_), "\n";
}
Loading