Is it possible to run cmake commands in a python script? I want to set the boost libraries which I installed and compiled manually through the python code.I want something like set(BOOST_INCLUDEDIR "/path/to/boost/include") to happen via python script. So, before running cmake I want the cmake variables to set through the python code.
There are two ways of pre-initialising CMake variables before CMake processing starts, both using command-line arguments of cmake.
The simple one is to pass one or more variables to CMake using the -D command-line option. Something like this:
cmake -DBOOST_INCLUDEDIR:PATH="/path/to/boost/include" ...
The other option is to create an "initial cache file" (basically a file containing just set(...) CMake commands) and pass that initial cache file to CMake using -C:
echo 'set(BOOST_INCLUDEDIR "/path/to/boost/include" CACHE PATH "")' > initial_cache.cmake
cmake -C initial_cache.cmake ...
This option is intended for use the first time CMake is run with a given binary directory, i.e. before it creates its own CMakeCache.txt file.
How you can utilise one or both of these from your Python script depends on your particular setup.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With