cmake 层次结构 zlib、libpng 和我自己的应用程序

发布于 2024-11-27 03:32:43 字数 1286 浏览 1 评论 0原文

我正在尝试为使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

当梦初醒 2024-12-04 03:32:43

find png 似乎没有 PNG_ROOT 变量,就像 BOOST_ROOT 的情况一样。我怀疑 zlib 库就是这种情况。您可以通过查找 find_png 模块和 find_zlib 模块来检查模块目录。

我将重写这些模块并将它们添加到您的 cmake 配置目录中。重写的版本应如下所示:

# This module defines
#  PNG_INCLUDE_DIR, where to find png.h, etc.
#  PNG_FOUND, If false, do not try to use PNG.
# also defined, but not for general use are
#  PNG_LIBRARY, where to find the PNG library.

FIND_PATH(
  PNG_INCLUDE_DIR png.h
  PATHS
    ${PNG_ROOT}
  PATH_SUFFIXES 
    include
    include/libpng
  NO_DEFAULT_PATH )

FIND_PATH(
  PNG_INCLUDE_DIR png.h
  PATHS
    ${PNG_ROOT}
  PATH_SUFFIXES 
    include
    include/libpng )

SET(PNG_NAMES ${PNG_NAMES} png libpng png12 libpng12)

FIND_LIBRARY(
  PNG_LIBRARY 
  NAMES 
    ${PNG_NAMES}
  PATHS
    ${PNG_ROOT}
  PATH_SUFFIXES
    /lib
  NO_DEFAULT_PATHS )

FIND_LIBRARY(
  PNG_LIBRARY 
  NAMES 
    ${PNG_NAMES}
  PATHS
    ${PNG_ROOT}
  PATH_SUFFIXES
    /lib )

# handle the QUIETLY and REQUIRED arguments and set PNG_FOUND to TRUE if 
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PNG DEFAULT_MSG PNG_LIBRARY PNG_INCLUDE_DIR)

请注意,我添加了两次 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:

# This module defines
#  PNG_INCLUDE_DIR, where to find png.h, etc.
#  PNG_FOUND, If false, do not try to use PNG.
# also defined, but not for general use are
#  PNG_LIBRARY, where to find the PNG library.

FIND_PATH(
  PNG_INCLUDE_DIR png.h
  PATHS
    ${PNG_ROOT}
  PATH_SUFFIXES 
    include
    include/libpng
  NO_DEFAULT_PATH )

FIND_PATH(
  PNG_INCLUDE_DIR png.h
  PATHS
    ${PNG_ROOT}
  PATH_SUFFIXES 
    include
    include/libpng )

SET(PNG_NAMES ${PNG_NAMES} png libpng png12 libpng12)

FIND_LIBRARY(
  PNG_LIBRARY 
  NAMES 
    ${PNG_NAMES}
  PATHS
    ${PNG_ROOT}
  PATH_SUFFIXES
    /lib
  NO_DEFAULT_PATHS )

FIND_LIBRARY(
  PNG_LIBRARY 
  NAMES 
    ${PNG_NAMES}
  PATHS
    ${PNG_ROOT}
  PATH_SUFFIXES
    /lib )

# handle the QUIETLY and REQUIRED arguments and set PNG_FOUND to TRUE if 
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PNG DEFAULT_MSG PNG_LIBRARY PNG_INCLUDE_DIR)

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.

檐上三寸雪 2024-12-04 03:32:43

您必须打开 PNG_BUILD_ZLIB 选项,以防止 libpng 使用 find_package 查找 zlib。

set(PNG_BUILD_ZLIB ON CACHE BOOL "" FORCE)
add_subdirectory(libpng)

# I also had to add some target_include_directories that are
# apparently not set in CMakeLists provided along with zlib and libpng:
target_include_directories(png PUBLIC zlib-1.2.5/ ${CMAKE_CURRENT_BINARY_DIR}/zlib-1.2.5/)
target_include_directories(png PUBLIC libpng154/ ${CMAKE_CURRENT_BINARY_DIR}/libpng154/)

You must turn PNG_BUILD_ZLIB option on to prevent libpng from looking for zlib using find_package.

set(PNG_BUILD_ZLIB ON CACHE BOOL "" FORCE)
add_subdirectory(libpng)

# I also had to add some target_include_directories that are
# apparently not set in CMakeLists provided along with zlib and libpng:
target_include_directories(png PUBLIC zlib-1.2.5/ ${CMAKE_CURRENT_BINARY_DIR}/zlib-1.2.5/)
target_include_directories(png PUBLIC libpng154/ ${CMAKE_CURRENT_BINARY_DIR}/libpng154/)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文