如何从Python脚本调用cmake并生成命令?

如何从Python脚本调用cmake并生成命令?,python,python-3.x,cmake,Python,Python 3.x,Cmake,我有以下Python脚本 代码 #!/usr/bin/env python3 import os def Build(cmake_args): cmake cmake_args # How to call cmake here by passing in the arguments? make install # How to call make install here from within Python? os.mkdir('build') os.chdir('b

我有以下Python脚本

代码

#!/usr/bin/env python3

import os

def Build(cmake_args):
    cmake cmake_args  # How to call cmake here by passing in the arguments?
    make install  # How to call make install here from within Python?

os.mkdir('build')
os.chdir('build')

# Call method Build by passing in all correct arguments
Build('-DCMAKE_INSTALL_PREFIX="./install" -DCMAKE_PREFIX_PATH="$PWD/../packages" ../SourceCodeFolder')
问题:
如何通过传入我的
CMakeLists.txt
理解的所有cmake参数来调用
cmake
?然后如何调用
makeinstall

环境:
我正在macOS Catalina上运行Python 3.9.0

PS:
我已确保从bash shell运行时,
mkdir build&&cd build&&cmake-DCMAKE\u INSTALL\u PREFIX=“/INSTALL”-DCMAKE\u PREFIX\u PATH=“$PWD//packages”。/SourceCodeFolder
成功。所以,问题只是如何从我的Python脚本调用cmake和make

编辑:

我想在Macos和Windows上运行我的脚本。这就是从Python脚本运行cmake和make的原因。

您可以使用
子流程。运行([“命令”,“-arg”)


(from)

我相信你可以解释一下你想用cmake做什么,我认为你试图通过使用python自动化一些编译任务,我认为使用python并不是最有效的解决方案