Jayesh
Jayesh

Reputation: 53345

How to find the CMake command line I used for the build?

This is what typically happens.

I get source code that has cmake build scripts.
I create a build subdirectory, change to it, run cmake <options> ...
Depending upon the project and its dependencies I have to repeat the last step until it finds all necessary dependencies and generates makefiles.
I successfully build and use the project.
A few days pass, I forget about this installation.

Then one day I'm trying to setup the same project on another machine and now I can't recall what exact CMake command line I used in the past to get things working.

I still have the old build directory on the old machine.
Can I find the cmake command line I used in the past, by looking into some of the autogenerated files in the build directory? I was expecting CMake would just put the exact command line I used in one of these files in commented form. But if it does so, I haven't found it yet.

How can I find the original CMake command line I used?

Upvotes: 22

Views: 5741

Answers (2)

playing4time
playing4time

Reputation: 71

My workaround, assuming I can modify toplevel CMakeLists.txt

near beginning of toplevel CMakeLists.txt, add:

message("-- GUESSED_CMAKE_CMD=cmake -DCMAKE_MODULE_PATH=${CMAKE_MODULE_PATH} -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -B ${CMAKE_BINARY_DIR}")

Now when I want to do-over cmake for a project where I have a build directory:

$ cmake -B path/to/build/dir
-- GUESSED_CMAKE_CMD=cmake -DCMAKE_MODULE_PATH=/home/roland/local2/share/cmake -DCMAKE_PREFIX_PATH=/home/roland/local2 -DCMAKE_BUILD_TYPE= -B /home/roland/proj/xo/xo-unit/.build
...

Upvotes: 0

Peter Petrik
Peter Petrik

Reputation: 10185

You can't.

Original CMake command can be guessed from analysis of CMakeCache.txt

As a workaround, you could always create a simple wrapper to store the original command line used. Something along these lines:

#!/bin/bash
echo "$@" > cmake_command.log
$@

Upvotes: 14

Related Questions