cmake 层次结构 zlib、libpng 和我自己的应用程序
我正在尝试为使用 libpng 的应用程序创建 CMake 层次结构。 Libpng 需要 zlib。
由于 CMakeLists.txt 与 zlib 和 libpng 一起分发,我的第一个想法是制作以下结构:
/development
CMakeLists.txt
/zlib-1.2.5
CMakeLists.txt <- provided by zlib
-sources-
-build of zlib?-
/libpng154
CMakeLists.txt <- provided by libpng
-sources-
-build of libpng?-
/myapp
CMakeLists.txt
-sources-
/build
-build of myapp-
-build of zlib?-
-build of libpng?-
...然后,在顶层 CMakeLists.txt 中,放置类似以下内容:
project(everything)
...
add_subdirectory(zlib-1.2.5)
add_subdirectory(libpng154)
add_subdirectory(myapp)
...
但运气不好。 libpng 的 CMakeLists.txt 执行 find_package(ZLIB...) 但它不知道在哪里查找。在 Mac OS 上,可以通过将 zlib“安装”到 /usr 来解决此问题。但这在 Windows 中行不通。
所以我想我不会递归到子目录中。只需独立编译和构建 zlib 和 libpng 并在遍历到我自己的应用程序之前执行 find_package(PNG...) (单独编译和构建 zlib 和 libpng(通过提供的 CMakeLists.txt)可以工作,至少在 Mac OS 上,但同样,只是因为 zlib 安装到 /usr)。
project(everything)
...
find_package(PNG...)
add_subdirectory(myapp)
...
运气不好,find_package(PNG...) 失败。我不知道如何让 find_package(PNG...) 知道在哪里寻找我刚刚构建的 libpng 库。例如,对于 boost,您可以设置“BOOST_ROOT”变量。 libpng 有类似的东西吗?
亲切的问候,
丹尼尔·德克斯
I'm trying to create a CMake hierarchy for an application that uses libpng. Libpng requires zlib.
Since a CMakeLists.txt is distributed with both zlib and libpng my first idea was to make the following structure:
/development
CMakeLists.txt
/zlib-1.2.5
CMakeLists.txt <- provided by zlib
-sources-
-build of zlib?-
/libpng154
CMakeLists.txt <- provided by libpng
-sources-
-build of libpng?-
/myapp
CMakeLists.txt
-sources-
/build
-build of myapp-
-build of zlib?-
-build of libpng?-
... and then, in the top level CMakeLists.txt, place something like:
project(everything)
...
add_subdirectory(zlib-1.2.5)
add_subdirectory(libpng154)
add_subdirectory(myapp)
...
But no luck. The CMakeLists.txt of libpng performs a find_package(ZLIB...) but it doesn't know where to look. This might be solved on Mac OS by "installing" zlib to /usr. But this wouldn't work in Windows.
So then i thought i would not recurse into the subdirectories. Just compile and build zlib and libpng independently and do a find_package(PNG...) prior to traversing down into my own app
(compiling and building zlib and libpng individually (via the provided CMakeLists.txt) works, at least on Mac OS but again, only because zlib is installed to /usr).
project(everything)
...
find_package(PNG...)
add_subdirectory(myapp)
...
No luck, find_package(PNG...) fails. I have no idea how to let find_package(PNG...) know where to look for the libpng library i have just built. For instance for boost, you can set the "BOOST_ROOT" variable. Is there anything simular for libpng?
Kind Regards,
Daniel Dekkers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
find png 似乎没有 PNG_ROOT 变量,就像 BOOST_ROOT 的情况一样。我怀疑 zlib 库就是这种情况。您可以通过查找 find_png 模块和 find_zlib 模块来检查模块目录。
我将重写这些模块并将它们添加到您的 cmake 配置目录中。重写的版本应如下所示:
请注意,我添加了两次 find_ 命令。第一次跳过默认目录。第二个不跳过默认目录。如果第一次搜索成功,则第二次搜索不会完成。如果定义了 PNG_INCLUDE_DIR 或 PNG_LIBRARY,则第二次搜索将知道第一个搜索成功。
It doesn't seem like the find png has PNG_ROOT variable, as is the case with BOOST_ROOT. I suspect that this is the case with the zlib library. You can check in your modules directory by looking for the find_png module and find_zlib module.
I would rewrite these modules and add them to your cmake configure directory. The re-written version should look like:
Note that I'm adding the find_ commands twice. The first time skips the default directories. The second one does not skip the default directories. If the first search succeeds the second one is not done. The second search will know that the first one suceeded if the PNG_INCLUDE_DIR or PNG_LIBRARY is defined.
您必须打开
PNG_BUILD_ZLIB
选项,以防止 libpng 使用find_package
查找 zlib。You must turn
PNG_BUILD_ZLIB
option on to prevent libpng from looking for zlib usingfind_package
.