1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
# This CMakeLists.txt doesn't do anything useful,
# but it shoudl demonstrate the cmake syntax highlighting
#
# Alex Turbov <i.zaufi@gmail.com>
#
<beginfold id='1'>#[[.rst:</beginfold id='1'>
Demo
----
This is an **RST** documentation.
<indentfold>::
# Sample code block
blah-blah
</indentfold>But we are about to test CMake here ;-)
<endfold id='1'>#]]</endfold id='1'>
cmake_policy(VERSION 3.11)
project(
Demo VERSION 1.0
DESCRIPTION "For unit testing purposes"
# NOTE that particular languages is a separate style
# to highlight "special" (well known values)
LANGUAGES C CXX
)
set(SOME_TRUE_OPTION TRUE) # `true` value
# `false` value and "internal" variable
set(_ANOTHER_FALSE_OPTION OFF CACHE INTERNAL "Internal option")
#BEGIN Message block
message(FATAL_ERROR "Ordinal message do ${VARIABLE_EXPANSION}")
message(AUTHOR_WARNING "... standard variables have a dedicated style")
message(SEND_ERROR "e.g. ${PROJECT_DESCRIPTION} or ${CMAKE_COMMAND}")
message(
STATUS <beginfold id='2'>[=[</beginfold id='2'>
Raw messages do not do ${VARIABLES_EXPANSION} or \n
escape symbols highlighting...
<endfold id='2'>]=]</endfold id='2'>
)
#END Message block
# ATTENTION Every command highlight only its own named keywords...
# Also, note aliased (most of the time imported) targets higlighted as well
add_library(Foo::foo IMPORTED GLOBAL)
set(KW_HL IMPORTED GLOBAL) # `IMPORTED` and `GLOBAL` are not highlighted here!
# Properties are separate ("special value") style
set_target_properties(Foo::foo PROPERTIES LOCATION "${FOO_LIBRARY}")
# Generator expressions
target_compile_definitions(
# NOTE Ok w/ CMake >= 3.11
Foo::foo
$<$<PLATFORM_ID:Windows>:WINDOWS_FOO>
$<$<PLATFORM_ID:Linux>:
LINUX_FOO
$<$<BOOL:${_has_foo}>:SOME_FOO_PATH=${PROJECT_BINARY_DIR}/foo>
>
)
<beginfold id='1'>#[=======================================================================[.rst:</beginfold id='1'>
.. cmake:command:: my_fun
*RST* documentation ``can`` refer to :cmake:command:`any_commands` or
:cmake:variable:`variables`...
<indentfold>.. code-block:: cmake
:caption: **Synopsys**
my_fun([ANYTHING...])
</indentfold><endfold id='1'>#]=======================================================================]</endfold id='1'>
<beginfold id='3'>function</beginfold id='3'>(my_fun)
# TODO Add implementation
<endfold id='3'>endfunction</endfold id='3'>()
my_fun(
# Custom functions do not highlight "standard" named args ...
PUBLIC LOCATION PARENT_SCOPE
# only some well-known values ...
smth-NOTFOUND ON
# and standard variables
PROJECT_VERSION
# or substitutions
$ENV{HOME} OR ${_internal_var_is_grey}
)
# I dont'recall exactly, but there was some bug with `if`...
<beginfold id='4'>if</beginfold id='4'>((A AND "${B}") OR C OR (var MATCHES "regex"))
# Anyway... it is Ok nowadays ;-)
elseif(POLICY CMP066)
add_executable(${PROJECT_NAME} ${PROJECT_NAME}.cc)
target_link_libraries(
${PROJECT_NAME}
PRIVATE
Qt5::Core
$<$<BOOL:${HAS_FOO}>:Foo::foo>
)
<endfold id='4'>endif</endfold id='4'>()
# In each function call below, all 3 named parameter lines should apply the same highlighting.
add_custom_command(
COMMAND true
COMMAND (true)
COMMAND true
)
add_custom_target(TargetName
WORKING_DIRECTORY somedir
COMMAND (true)
BYPRODUCTS somefile
)
execute_process(
COMMAND true
COMMAND (true)
COMMAND true
)
add_test(
NAME sometest
COMMAND (true)
WORKING_DIRECTORY somedir
)
# nested parentheses
<beginfold id='4'>if</beginfold id='4'>( true AND ( false OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") ) )
<endfold id='4'>endif</endfold id='4'>()
<beginfold id='4'>if</beginfold id='4'>(NOT TARGET Boost::${lib})
add_library(Boost::${lib} INTERFACE IMPORTED)
<endfold id='4'>endif</endfold id='4'>()
|