CMake用户选项的命令行帮助



我的CMakeLists.txt文件中有一些选项,可以在命令行上使用-D进行选择,如下所示:

# Set some options the user may choose
OPTION(USE_MPI "Use the MPI library for parallelization" OFF)
OPTION(USE_OPENMP "Use OpenMP for parallelization" OFF)
OPTION(TESTING "Enable testing of both Fortran and Python code" OFF)
OPTION(PYTHON_TOOLS "Build the python helper tools" OFF)
OPTION(BUILD_DOCS "Build the documentation; turns on PYTHON_TOOLS" OFF)

我可以用之类的东西激活其中一个

$ cmake . -DUSE_MPI=ON

有时我忘记了我选择的选项是什么。如果有某种-h标志,我可以用它在命令行上以自动的方式(以python的argparse的样式)显示这些标志,那就太好了。

是否有一种自动生成特定CMakeLists.txt的帮助文档的方法,和/或使用某种-h--help标志调用该帮助?我正在寻找能给我这种行为的东西:

$ cmake . --help
USE_MPI - Use the MPI library for parallelization (Default: OFF)
USE_OPENMP - Use OpenMP for parallelization (Default: OFF)
TESTING - Enable testing of both Fortran and Python code (Default: OFF)
PYTHON_TOOLS - Build the python helper tools (Default: OFF)
BUILD_DOCS - Build the documentation; turns on PYTHON_TOOLS (Default: OFF)

如果没有自动化的方法,是否至少有一种简单的方法可以将--help-h传递到CMakeLists.txt,以便我可以手动编写帮助消息?

我认为最接近您想要的是-L命令行arg。运行cmake . -LH应该配置您的项目,然后输出所有缓存的非高级变量及其帮助字符串。

i arg还允许您查看option s的当前值,但这实际上是在命令行"向导模式"中运行cmake——它配置项目,要求您一次设置/更新每个变量。

最新更新