Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

running cmake commands in python script

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.

like image 509
abhay gurrala Avatar asked Jun 20 '26 17:06

abhay gurrala


1 Answers

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.

like image 146
Angew is no longer proud of SO Avatar answered Jun 22 '26 09:06

Angew is no longer proud of SO