I want to record the arguments passed to cmake in my generated scripts. E.g., "my-config.in" will be processed by cmake, it has definition like this:
config="@CMAKE_ARGS@"
After cmake
, my-config
will contain a line something like this:
config="-DLINUX -DUSE_FOO=y -DCMAKE_INSTALL_PREFIX=/usr"
I tried CMAKE_ARGS
, CMAKE_OPTIONS
, but failed. No documents mention this. :-(
I don't know of any variable which provides this information, but you can generate it yourself (with a few provisos).
Any
-D
arguments passed to CMake are added to the cache fileCMakeCache.txt
in the build directory and are reapplied during subsequent invocations without having to be specified on the command line again.So in your example, if you first execute CMake as
then you will find that subsequently running simply
will still have
CMAKE_INSTALL_PREFIX
set to/usr
If what you're looking for from
CMAKE_ARGS
is the full list of variables defined on the command line from every invocation of CMake then the following should do the trick:This is a bit fragile as it depends on the fact that each variable which has been set via the command line has the phrase "No help, variable specified on the command line." specified as its
HELPSTRING
property. If CMake changes this defaultHELPSTRING
, you'd have to update theif
statement accordingly.If this isn't what you want
CMAKE_ARGS
to show, but instead only the arguments from the current execution, then I don't think there's a way to do that short of hacking CMake's source code! However, I expect this isn't what you want since all the previous command line arguments are effectively re-applied every time.One way to store CMake command line arguments, is to have a wrapper script called
~/bin/cmake
(***1) , which does 2 things:./cmake_call.sh
that stores the command line argumentscmake
executable with the command line arguments~/bin/cmake
# code is shown belowUsage:
This will create
cmake_call.sh
with the following content:The 3rd last line stores the cmake arguments. You can now reinvoke the exact command-line that you used by simply calling:
Footnotes:
(***1)
~/bin/cmake
is usually in the PATH because of~/.profile
. When creating~/bin/cmake
the very 1st time, it might be necessary to log out and back in, so that .profile sees~/bin
.