This question already has answers here:
Commenting code in Notepad++
(11 answers)
Closed 2 years ago.
My cmake file looks like this. I want to uncomment the lines 1 through 100 with a single shortcut
#line1
#line2
#line3
.
.
.
#line100
build(a_library
USING
b
c)
if(FALSE) # fake a block comment
endif()
Note that this works well for commenting out a block of valid CMake code, it doesn't allow you write plain text within the if block
As of CMake 3.0 there is a special syntax for block comments which start with #[[ and ends with ]] at the end of block comment.
Related
This question already has answers here:
How to call a function in CMake whose name is stored in a variable
(5 answers)
Closed 11 months ago.
I want to use a CMake macro as a text replacement tool to call a command. This is something I am familiar with in C, but I am not sure if this is allowed in CMake.
what I want to be able to do:
MY_MACRO(
MY_COMMAND(ARGS)
)
I have tried a few different variations on this general idea on how to implement this, but I am not sure it is possible.
MACRO(MY_MACRO)
# do stuff
${ARGN} # Call MY_COMMAND
# do stuff
)
I figured this out based on this thread:
https://gitlab.kitware.com/cmake/cmake/-/issues/20800#note_951424
I haven't tested very thoroughly, but this is the gist at least:
MACRO(MY_MACRO)
#stuff
CMAKE_LANGUAGE(EVAL CODE ${ARGN})
#stuff
ENDMACRO(MY_MACRO)
This question already has answers here:
How do I add a linker or compile flag in a CMake file?
(7 answers)
Closed last year.
I used Set_directory_properties(PROPERTIES COMPILE_DEFINITIONS "--saferc=none") to mask misra check in directory, but I got Warning:
Ccv850:Warning:option "-D--saferc=none" ignored due to invalid argument. Expected name or name=string.
You should basically never use directory properties, ever.
For whichever targets cannot compile without the flag, you can add it like so:
target_compile_options(
my_target
PRIVATE
"$<$<CXX_COMPILER_ID:GHS>:--saferc=none>"
"$<$<C_COMPILER_ID:GHS>:--saferc=none>"
)
My understanding is that --saferc=none is a Green Hills flag, hence the check for $<CXX_COMPILER_ID:GHS>. If you are only using one of C or C++, you can delete the flag for the other language.
This question already has answers here:
cmake generate error on windows as it uses \ as escape seq
(3 answers)
Closed 5 years ago.
The community reviewed whether to reopen this question 4 months ago and left it closed:
Original close reason(s) were not resolved
Is there a robust way to normalize paths in CMake?
Example:
# Let's assume that an environment variable MY_ROOT_DIR is set
# that points to some directory.
set(MYFILE "$ENV{MY_ROOT_DIR}/somefile.txt")
message(${MYFILE})
# This will result for example in
# Win: C:\path\to\my\root\dir/somefile.txt
# Unix based: /path/to/my/root/dir/somefile.txt
In this example, it would be required to normalize MY_ROOT_DIR (that is to replace backslashes with slashes) prior to using it as path component. How would you do this in CMake?
CMake (or the tools further down the toolchain) may handle paths with mixed separators (/ or \), or may not. CMake uses / as the standard separator. A typical warning generated by CMake for paths with the wrong path separator \ may look similar to this:
CMake Warning (dev) at cmake_install.cmake:5 (set):
Syntax error in cmake code at
C:/path/to/my/root/build/cmake_install.cmake:5
when parsing string
C:\path\to\my\root/somefile.txt
Invalid escape sequence \p
Policy CMP0010 is not set: Bad variable reference syntax is an error. Run
"cmake --help-policy CMP0010" for policy details. Use the cmake_policy
command to set the policy and suppress this warning.
Thanks for any hints on this!
You can use the file(TO_CMAKE_PATH) command for this.
The TO_CMAKE_PATH mode converts a native <path> into a cmake-style path with forward-slashes (/). The input can be a single path or a system search path like $ENV{PATH}. A search path will be converted to a cmake-style list separated by ; characters.
Here is an example:
file(TO_CMAKE_PATH "$ENV{MY_DIR_VAR}" ENV_MY_DIR_VAR)
This question already has an answer here:
Multiple Cmake_Prefix_Paths
(1 answer)
Closed 6 years ago.
How can I have several paths for cmake to look for needed libraries. I installed zlib and libpng under /usr/local/zlib and /usr/local/libpng however, what I'm currently doing is first cmake -DCMAKE_PREFIX_PATH=/usr/local/zlib, then issuing a second command `cmake -DCMAKE_PREFIX_PATH=/usr/local/libpng" in order for cmake to recognize both.
Is there a way to have both paths in the same variable?
I tried -DCMAKE_PREFIX_PATH=/usr/local/zlib:/usr/local/libpng but it didn't work.
You need to use ; character instead of : to define lists.
Is there any way to comment a block in CMake in notepad++ editor?
I have tried searching on Google, but couldn't find much.
Help is needed! Thanks,
As of CMake 3.0 there is a special syntax for block comments which start with #[[ and ends with ]] at the end of block comment. See CMake documentation for further explanation.
You can also put a number of equal signs between the brackets as long as the number between the opening [[ and closing ]] are both the same. Ex.
#[===[
hello
]] <- this is not the closing
]===]
# ^ this is the closing
Some editors and IDEs do not support it yet.
if(FALSE) # fake a block comment
endif()
Since CMake version 3.0 there are block comments.
Example from the CMake manual:
#[[This is a bracket comment.
It runs until the close bracket.]]
message("First Argument\n" #[[Bracket Comment]] "Second Argument")
There is no notion of a block comment in CMake syntax. However, to comment several lines at once, select the required lines and hit CTRL+Q.
If the file is a .txt file (e.g. CMakeLists.txt), you can either set Notepad++ to always treat .txt files as CMake files (in Settings -> Style configurator select CMakeFile and add " txt" to "User ext.") or for just that file you can set the Language to CMake.