我目前有一个链接到两个第三方库的项目。这些库必须自己构建,然后链接到项目中。一个是taglib,另一个是zlib。我注意到,当您在 taglib 目录上使用 Cmake-gui 程序时,您需要指定 zlib 的构建和安装位置。
我的目标是让 CMake 为我的程序做类似的事情。由于这些库的存储位置不一致,如何提示用户提供所需库的路径?
我希望这足够具体。
I currently have a project that links to two third party libraries. These libraries have to be built by themselves and then linked to the project. One is taglib and the other is zlib. I noticed that when you use the Cmake-gui program on the taglib directory you're required to specify where zlib has been built and installed.
My goal is to get CMake to do a similar thing for my program. Since the place these libraries are stored will be inconsistent how can I prompt the user to provide the path to the libraries required?
I hope this is specific enough.
发布评论
评论(2)
对于 ZLib,CMake 提供了 FindZLIB.cmake,您可以“简单地”放置 find_package 在您的 cmakelists 中调用。如有必要,您可以对 findzlib.cmake 进行一些修改以满足您的需求。例如,在搜索库时添加 ZLIB_DIR 作为附加提示。然后用户可以设置该 ZLIB_DIR。
假设您的库/可执行文件名为 YourProject,您可以按如下方式使用它。
您应该对 TagLib 使用相同的方法,但应该编写自己的 FindTagLib.cmake (或搜索一个好的方法)。
这里重要的部分是,您为用户提供了设置 TagLib_DIR 变量的选项,您可以使用该变量来搜索 TagLib 并使用 FindPackageHandleStandardArgs 报告成功或失败。
In the case of ZLib, a FindZLIB.cmake is provided with CMake and you can "simply" put a find_package call in your cmakelists. If necessary you can make some modifications to findzlib.cmake to suit your needs. E.g. adding ZLIB_DIR as an additional hint when searching for the library. This ZLIB_DIR can then be set by the user.
Assuming your library/executable is called YourProject, you can use it as follows.
You should use the same approach for TagLib, but instead should write your own FindTagLib.cmake (or search for a good one).
The important part here is that you give the user the option to set a TagLib_DIR variable, which you use to search for TagLib and that you use FindPackageHandleStandardArgs to report success or failure.
不确定交互式提示,但您始终可以使用环境变量或以下内容:
为 cmake 提供自定义 zlib 或 taglib 位置。
不要忘记更新 FindZLIB.cmake 以处理 FIND_PATH 和 FIND_LIBRARY 中的此变量
Not sure about interactive prompt, but you always can use environment variables or following:
to provide cmake with custom zlib or taglib location.
Don't forget to update FindZLIB.cmake to handle this variables in FIND_PATH and FIND_LIBRARY