I want to build a project #local dictionary.
And in 'CMakeLists.txt' the project A want to find another library B using 'FIND_PACKAGE' command.
The problem is that library B can be found in system directory while I rebuild it # my local directory, so how can I control that case by inputting a additional parameter when typing 'cmake .'?
You can give specify variable values using CMake's -D command line option.
Note that the variable in question has to be stored in the cache for this to work, as the command line simply sets a cache entry and local variables hide cache variables of the same name.
cmake -DMY_AWESOME_VARIABLE=Foo <path_to_source>
CMakeLists.txt
[...]
# set a default value that will be used if no option is given on the command line
set(MY_AWESOME_VARIABLE "Default value" CACHE STRING "")
# this line will output the current value from cache; so either the default
# value or whatever was given last on the command line
message(${MY_AWESOME_VARIABLE})
# local variables hide cache entry, so the next message will always print "Local"
set(MY_AWESOME_VARIABLE "Local")
message(${MY_AWESOME_VARIABLE})
you could temporarily change the PATH environment variable to only your local bin aud or usr... by running cmake with:
PATH=~/bin:~/usr:~/usr/bin cmake
But then you have to put all the required executables in that/those folders.
Related
I have git installed under C:\Program Files\Git\ I do the following from a setupenv.bat:
set PATH="C:\Program Files\Git\bin";%PATH%
So doing the following I can see it:
echo %PATH%
The following will then work:
git --version
>git version 2.21.0.windows.1
But this won't:
where git
>INFO: Could not find files for the given pattern(s)
The issue, is most likely that you have surrounded your location string with double-quotes.
The locations listed within the %Path% string value content are delimited with semi-colons, for that reason your intended addition to that value content should not be double-quoted.
If you take a look at the existing %Path% content, by typing Path at the Command Prompt, and pressing the ENTER key, you'll note the absence of double-quotes, and most likely that there are paths which include space characters.
The solution therefore is to change your set command from:
set PATH="C:\Program Files\Git\bin";%PATH%
to:
set PATH=C:\Program Files\Git\bin;%PATH%
However, I will add that the recommended syntax for the Set command is:
Set "VariableName=Variable Value"
So you should really write it thus:
Set "PATH=C:\Program Files\Git\bin;%PATH%"
It should be noted too that the locations listed within the value of Path are searched in order, which means that you should consider carefully whether your new location should be located and therefore searched first, or last. The precedence could be important depending upon what else is being done within that script.As the Path value string should already be semi-colon terminated, you could just as easily locate it at the end:
Set "Path=%Path%C:\Program Files\Git\bin;"
Also note that there is already an environment variable available for the normal \Program Files\ directory, so you could additionally incorporate that instead:
Set "Path=%ProgramFiles%\Git\bin;%Path%"
The manual https://www.yoctoproject.org/docs/2.5/kernel-dev/kernel-dev.html at section C.1.6 states that:
The Linux kernel command line is typically specified in the machine
config using the APPEND variable.
in my bbappend of my embedded linux recipe I added:
APPEND_append = " isolcpus=2"
I forced a rebuild of virtual/kernel and the image recipe but find /sys/devices/system/cpu/isolated to be empty.
Do I have to set this variable in the machine config? If yes, why is it stated that this is 'typically' done there?
What else could have gone wrong?
EDIT: I put APPEND += "isolcpus=2" into my local.conf. Unfortunately, that line still doesn't make it into my /proc/cmdline of my target image.
The Xcode archive step creates this variable: ${BITRISE_DEPLOY_DIR} and read that pilot uses the PILOT_IPA environment variables for the IPA directory.
Is there a way to assign the output (BITRISE_DEPLOY_DIR) to another environment variable (e.g.: $PILOT_IPA)?
You can do that by using envman (https://github.com/bitrise-io/envman) which is part of the bitrise CLI tool stack.
To assign the value of an existing Environment Variable (Step outputs are just regular Environment Variables) you can use a Script step, and specify this as the content:
#!/bin/bash
echo "BITRISE_DEPLOY_DIR: $BITRISE_DEPLOY_DIR"
envman add --key PILOT_IPA --value "$BITRISE_DEPLOY_DIR"
This'll first print the value of the BITRISE_DEPLOY_DIR environment variable, and then with envman add it'll add a new environment item with the key PILOT_IPA and the value of $BITRISE_DEPLOY_DIR.
As I understand it, when you provide a variable via the command line with cmake (e.g. -DMy_Var=ON), that variable is stored inside the cache. When that variable is then accessed on future runs of the CMake script, it will always get the value stored inside the cache, ignoring any subsequent -DMy_Var=OFF parameters on the command line.
I understand that you can force the cache variable to be overwritten inside the CMakeLists.txt file using FORCE or by deleting the cache file, however I would like to know if there is a nice way for the -DMy_Var=XXX to be effective every time it is specified?
I have a suspicion that the answer is not to change these variables within a single build but rather have separate build sub-dirs for the different configs. Could someone clarify?
I found two methods for changing CMake variables.
The first one is suggested in the previous answer:
cmake -U My_Var -D Mu_Var=new_value
The second approach (I like it some more) is using CMake internal variables. In that case your variables will be still in the CMake cache, but they will be changed with each cmake invocation if they are specified with -D My_Var=.... The drawback is that these variables would not be seen from GUI or from the list of user's cache variables. I use the following approach for internal variables:
if (NOT DEFINED BUILD_NUMBER)
set(BUILD_NUMBER "unknown")
endif()
It allows me to set the BUILD_NUMBER from the command line (which is especially useful on the CI server):
cmake -D BUILD_NUMBER=4242 <source_dir>
With that approach if you don't specify your BUILD_NUMBER (but it was specified in previous invocations), it will use the cached value.
You could use
CMake -UMy_Var -DMy_Var=new_value
see documentation https://cmake.org/cmake/help/v3.9/manual/cmake.1.html
I hope this helps.
Find this post by coincidence.
It seems the behavior described by OP isn't the case for CMake 3.12 onwards. For previous releases, I didn't make some tests so cannot confirm.
Variables provided by -D on command line are stored in CMakeCache.txt. They can be overridden, even the same variable is repeatedly provided and the last one is set to the value for that variable.
For example, a very easy CMake script
message(STATUS "FOO = " ${FOO})
$ cmake -DFOO=123 -DFOO=321 .. # the last one takes effect
-- FOO = 321
-- Configuring done
-- Generating done
-- Build files have been written to: xxx
$ cmake .. # cache is remembered
-- FOO = 321
-- Configuring done
-- Generating done
-- Build files have been written to: xxx
$ cmake -DFOO=changed .. # override it
-- FOO = changed
-- Configuring done
-- Generating done
-- Build files have been written to: xxx
Sorry about my poor English, I hope you can understand what I'm describing
I know how to pass arguments, like -v, -c, etc
Edit Scheme > Run xxx > Arguments
In Termimal.app, when I type the following, it shows the correct result, as expected.
./C_Product < main.c
How should I do this in Xcode?
I tried to add argument < main.c, but it did not affect.
I already copied main.c file to
C_Productxxxxx -> Build -> Products -> Debug
with C_Product at the same place
I don't know of a way to get Xcode to pipe the contents of a file to std in automatically. However, you do have some other options. You could modify your program to take the filename as an argument, and then pass in the filename as an argument as you have above. So you could make -i <foo> be the name of the input file. (Or better yet, -input-file <foo>.)
Alternatively, you could modify your application to read from a file whose path is in an environment variable. So your app could call getenv("MY_INPUT_FILE"); and you could tell Xcode to set the value of "MY_INPUT_FILE" environment variable to the path of the input file in the scheme.