作为项目用户,用Cmake做项目需要做什么?

As a project user, what do I need to do to make a project with Cmake?

我正在处理一个 [曾经] 支持 Autotools 和 Cmake 的项目。过去,我会:

cd project/build
...
../llvm/configure --enable-optimized --enable-cxx11 $OTHER_OPTIONS --prefix=/usr/local
make -j2
sudo make install

该项目有点放弃了对 Autotools 的支持,所以我现在必须使用 Cmake。使用Cmake 来配置看起来应该是比较容易的。

不幸的是,Mac OS X 缺少 Cmake 的手册页,所以我不能 RTFM。我发现的搜索结果讨论了如何构建 Cmake 包(以及其他包维护者会做的事情),而不是如何将它用作一个愚蠢的项目用户。

我尝试简单地使用 Cmake 代替 Configure,但它不起作用:

$ cd project/build
$ OTHER_OPTIONS=" --enable-libcpp"; cmake ../llvm --enable-optimized --enable-cxx11 "$OTHER_OPTIONS" --prefix=/usr/local
CMake Error: The source directory ".../clang-3.6/build/--prefix=/usr/local" does not exist.

为什么 Cmake 将配置选项视为目录 (--prefix=/usr/local)?

如何配置和构建一个使用 Cmake 作为哑项目用户的项目?

您正在尝试像配置 autotools 一样配置 CMake 项目。命令的语法是;

cmake -Doptions -Dmore_options src_dir

src 目录是最后一个参数,这就是它以这种方式对待 --prefix 的原因。不过,您需要知道可用参数的名称。如果您是 CMake 的新手,最好的选择是 运行,Qt gui 或 curses gui(在构建目录中时 ccmake /path/to/src)。这些 gui 工具会让你选择你的选项,配置然后生成。然后你只需要输入 make ....

备注

cmake --help

即使未安装您的手册页,也会提供信息。此外,如果您可以访问 google 和互联网,搜索 "cmake man page" 应该可以访问您丢失的手册页。