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.
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:
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.
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 answers here:
Closed 12 years ago.
Possible Duplicate:
Obj C - #import < > and “ ”
This may be a simple question, but googling it is difficult. What's the difference between following two statements?
#import "GrowlDisplayPlugin.h"
#import <GrowlDisplayPlugin.h>
They work in different ways for me, so I thought it's about time I understand what I'm doing.
In particular, the second one says 'No such file or directory' and the first one following linking error.
Undefined symbols:
"_OBJC_METACLASS_$_GrowlDisplayPlugin"
Thank you
" are used for local files. That means files in the current directory or in directories specified by the -iqoute flag for the GCC compiler.
< and > are used for system files found in the folders of your path. /usr/include is probably one of them. The -I flag can be used to specify more directories to search when looking for those files.
Using <> imports from the library search paths. Using "" imports the file from your user search paths (usually just the directory containing your project)
The difference is in the order, in which the compiler searches different folders for files. The "fine.h" form gives precedence to the current folder (the one where the containing source file is). The <> form searches the system include folder first.