【问题标题】:How to compile wxWidgets using custom version of required 3rd party libraries如何使用所需 3rd 方库的自定义版本编译 wxWidgets
【发布时间】:2021-11-11 10:51:20
【问题描述】:

假设我有 libTifflibpngzliblibjpeg。我如何告诉 wxWidgets 使用这些而不是系统上的内置或安装的?

我对 wxWidgets 很陌生,并试图将其作为依赖项添加到我的 CMake 项目中,作为回报,该项目已经依赖并构建(使用 ExternalProject)上述库。我不想混合版本(如果我使用内置版本或系统上已经安装的版本,肯定会发生这种情况)。我还希望将所有依赖项与系统上已经存在的依赖项分开,以便于分发。

我检查了 setup.h.in 定义预处理器宏的位置(此处:wxUSE_ZLIBwxUSE_LIBJPEGwxUSE_LIBTIFFwxUSE_LIBPNG)。我还看到 <root of wxWidgets git repo>/build/cmake/lib/ 内部有各种 *.cmake 包含处理不同 3rd 方依赖项的文件。

然而,我很困惑我需要将什么传递给我的cmake 命令,以便将 wxWidgets 配置为从特定位置使用上述库的版本。我已经定义了PNG_LIBRARIESJPEG_LIBRARIES 等(指向*.lib(在Windows 上)或*.so(在Linux 上)文件所在的位置。此外,我还相应地定义了..._INCLUDE_DIRS

目前这是我的外部项目描述的状态(... 是有效路径的占位符)

ExternalProject_Add(wxWidgets
    PREFIX ${CMAKE_CURRENT_BINARY_DIR}/deps/wxwidgets
    
    INSTALL_DIR ...
    DOWNLOAD_DIR ""
    TMP_DIR ...
    STAMP_DIR ...
    LOG_DIR ...
    BINARY_DIR ...
    SOURCE_DIR ...

    INSTALL_COMMAND "${CMAKE_COMMAND}" -E echo "Skipping install step for dependency libzmq"
    INSTALL_PREFIX ...

    BUILD_ALWAYS OFF

    # For build configurations see https://wiki.wxwidgets.org/WxWidgets_Build_Configurations
    # Also setup.h.in and <wxWidgets_root>/build/cmake/libs
    CMAKE_ARGS
        "-DCMAKE_BUILD_TYPE=Release"
        "-DBUILD=release"
        "-DSHARED=1"
        "-DMONOLITHIC=1"
        "-DwxBUILD_TESTS=OFF"
        "-DwxBUILD_DEMOS=OFF"
        "-DwxBUILD_BENCHMARKS=OFF"
        "-DwxUSE_GUI=1"                               # <---- forces dependency requirement for PNG, ZLIB, JPEG, TIFF
        "-DwxUSE_OPENGL=1"
        "-DwxUSE_ZLIB=sys"
        "-DZLIB_LIBRARY=${ZLIB_LIBRARIES}"            # <---- from another ExternalProject
        "-DZLIB_INCLUDE_DIRS=${ZLIB_INCLUDE_DIRS}"    # <---- from another ExternalProject
        "-DwxUSE_LIBJPEG=sys"
        "-DJPEG_LIBRARY=${JPEG_LIBRARIES}"            # <---- from another ExternalProject
        "-DJPEG_INCLUDE_DIR=${JPEG_INCLUDE_DIRS}"     # <---- from another ExternalProject
        "-DwxUSE_LIBPNG=sys"
        "-DPNG_LIBRARY=${PNG_LIBRARIES}"              # <---- from another ExternalProject
        "-DPNG_PNG_INCLUDE_DIR=${PNG_INCLUDE_DIRS}"   # <---- from another ExternalProject
        "-DwxUSE_LIBTIFF=builtin" # TODO Add libTiff to external project dependencies and use here
)

我最初所做的基本上是在OFF 上放东西。 wxWidgets 的配置足够聪明,可以警告我(因为我包含了需要这些库的wxUSE_GUI)相应的库丢失了,它将使用内置的。从那里我发现了它实际上在寻找哪些变量,并通过将 wxUSE_... 设置为 sys 为各自的库。现在我离配置构建越来越近了:

1>------ Rebuild All started: Project: ZERO_CHECK, Configuration: Debug x64 ------
1>Checking Build System
2>------ Rebuild All started: Project: wxWidgets, Configuration: Debug x64 ------
2>Creating directories for 'wxWidgets'
2>Building Custom Rule C:/Users/.../Documents/.../CMakeLists.txt
2>No download step for 'wxWidgets'
2>No update step for 'wxWidgets'
2>No patch step for 'wxWidgets'
2>Performing configure step for 'wxWidgets'
2>-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.19042.
2>-- cotire 1.8.0 loaded.
2>-- Found ZLIB: C:/Users/.../CMakeBuilds/ef5b5ada-ee42-7735-988a-ae37c735ccff/build/deps/build/zlib/Debug/zlibd.lib (found version "1.2.11")
2>-- Found JPEG: C:/Users/rcr-aa/CMakeBuilds/ef5b5ada-ee42-7735-988a-ae37c735ccff/build/deps/build/jpeg/Debug/jpeg.lib (found version "90")
2>-- Found PNG: C:/Users/.../CMakeBuilds/ef5b5ada-ee42-7735-988a-ae37c735ccff/build/deps/build/png/Debug/libpng16d.lib (found version "1.6.38.git")
2>-- Which libraries should wxWidgets use?
2>    wxUSE_STL:      OFF      (use C++ STL classes)
2>    wxUSE_REGEX:    builtin  (enable support for wxRegEx class)
2>    wxUSE_ZLIB:     sys      (use zlib for LZW compression)
2>    wxUSE_EXPAT:    builtin  (use expat for XML parsing)
2>    wxUSE_LIBJPEG:  sys      (use libjpeg (JPEG file format))
2>    wxUSE_LIBPNG:   sys      (use libpng (PNG image format))
2>    wxUSE_LIBTIFF:  builtin  (use libtiff (TIFF file format))
2>    wxUSE_LIBLZMA:  OFF      (use liblzma for LZMA compression)
2>
2>-- Configured wxWidgets 3.1.6 for Windows-10.0.19042
2>    Min OS Version required at runtime:                Windows Vista / Windows Server 2008 (x64 Edition)
2>    Which GUI toolkit should wxWidgets use?            msw
2>    Should wxWidgets be compiled into single library?  OFF
2>    Should wxWidgets be linked as a shared library?    ON
2>    Should wxWidgets support Unicode?                  ON
2>    What wxWidgets compatibility level should be used? 3.0
2>-- Configuring done

在环顾四周时,我还检查了 *.cmake 文件中的库,我想使用自定义版本来确认需要设置的内容。 zlib 的示例如下所示:

#############################################################################
# Name:        build/cmake/lib/zlib.cmake
# Purpose:     Use external or internal zlib
# Author:      Tobias Taschner
# Created:     2016-09-21
# Copyright:   (c) 2016 wxWidgets development team
# Licence:     wxWindows licence
#############################################################################

if(wxUSE_ZLIB STREQUAL "builtin")
    # TODO: implement building zlib via its CMake file, using
    # add_subdirectory or ExternalProject_Add
    wx_add_builtin_library(wxzlib
        src/zlib/adler32.c
        src/zlib/compress.c
        src/zlib/crc32.c
        src/zlib/deflate.c
        src/zlib/gzclose.c
        src/zlib/gzlib.c
        src/zlib/gzread.c
        src/zlib/gzwrite.c
        src/zlib/infback.c
        src/zlib/inffast.c
        src/zlib/inflate.c
        src/zlib/inftrees.c
        src/zlib/trees.c
        src/zlib/uncompr.c
        src/zlib/zutil.c
    )
    if(WIN32)
        # Define this to get rid of many warnings about using open(),
        # read() and other POSIX functions in zlib code. This is much
        # more convenient than having to modify it to avoid them.
        target_compile_definitions(wxzlib PRIVATE _CRT_NONSTDC_NO_WARNINGS)
    endif()
    set(ZLIB_LIBRARIES wxzlib)                           # <----------- set via -DZLIB_LIBRARIES in my ExternalProject 
    set(ZLIB_INCLUDE_DIRS ${wxSOURCE_DIR}/src/zlib)      # <----------- set via -DZLIB_INCLUDE_DIRS in my ExternalProject
elseif(wxUSE_ZLIB)
    find_package(ZLIB REQUIRED)
endif()

我最大的问题是我显然必须为每个第 3 方依赖项设置配置(在我的情况下,将所有其他依赖项设置为 builtin

2>CMake Error at build/cmake/functions.cmake:591 (add_library):
2>  Cannot find source file:
2>
2>    C:/Users/.../Documents/.../deps/wxwidgets/3rdparty/pcre/src/pcre2_auto_possess.c
2>
2>  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
2>  .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc
2>Call Stack (most recent call first):
2>  build/cmake/lib/regex.cmake:13 (wx_add_builtin_library)
2>  build/cmake/lib/CMakeLists.txt:28 (include)
2>
2>
2>CMake Error at build/cmake/functions.cmake:591 (add_library):
2>  Cannot find source file:
2>
2>    C:/Users/.../Documents/.../deps/wxwidgets/src/expat/expat/lib/xmlparse.c
2>
2>  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
2>  .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc
2>Call Stack (most recent call first):
2>  build/cmake/lib/expat.cmake:13 (wx_add_builtin_library)
2>  build/cmake/lib/CMakeLists.txt:28 (include)
2>
2>
2>CMake Error at build/cmake/functions.cmake:591 (add_library):
2>  Cannot find source file:
2>
2>    C:/Users/.../Documents/.../deps/wxwidgets/src/tiff/libtiff/tif_win32.c
2>
2>  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
2>  .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc
2>Call Stack (most recent call first):
2>  build/cmake/lib/tiff.cmake:19 (wx_add_builtin_library)
2>  build/cmake/lib/CMakeLists.txt:28 (include)
2>
2>
2>CMake Error at build/cmake/functions.cmake:591 (add_library):
2>  No SOURCES given to target: wxregex
2>Call Stack (most recent call first):
2>  build/cmake/lib/regex.cmake:13 (wx_add_builtin_library)
2>  build/cmake/lib/CMakeLists.txt:28 (include)
2>
2>
2>CMake Error at build/cmake/functions.cmake:591 (add_library):
2>  No SOURCES given to target: wxexpat
2>Call Stack (most recent call first):
2>  build/cmake/lib/expat.cmake:13 (wx_add_builtin_library)
2>  build/cmake/lib/CMakeLists.txt:28 (include)
2>
2>
2>CMake Error at build/cmake/functions.cmake:591 (add_library):
2>  No SOURCES given to target: wxtiff
2>Call Stack (most recent call first):
2>  build/cmake/lib/tiff.cmake:19 (wx_add_builtin_library)
2>  build/cmake/lib/CMakeLists.txt:28 (include)
2>
2>
2>CMake Generate step failed.  Build files cannot be regenerated correctly.
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(209,5): error MSB6006: "cmd.exe" exited with code 1.
2>Done building project "wxWidgets.vcxproj" -- FAILED.

由于我不熟悉 wxWidgets,所以我想问一下我是否可以将所有其余的依赖项设置为 builtin

【问题讨论】:

  • 最好的解决方案是使用系统提供的库,如果它们不存在(`Winblows1 回退到内置库。否则用户可能最终得到 3 个独立且可能不兼容的版本图书馆。而你最终会试图找到异常崩溃的问题......

标签: cmake wxwidgets


【解决方案1】:

首先,您必须进行设置,以便可以通过 CMake(使用其 find_package())或配置(使用 pkg-config)找到现有库。

其次,使用CMake,我认为您需要将wxUSE_LIBPNG等选项显式设置为sys。使用 configure 构建时,这已经是默认设置了,因为 configure 将首先查找系统库,如果找不到系统库,则仅使用内置库,但您也可以使用其命令行选项,例如 @ 987654325@ 强制使用系统库(如果找不到则配置失败)。

【讨论】:

    猜你喜欢
    • 2015-08-31
    • 1970-01-01
    • 1970-01-01
    • 2014-04-19
    • 1970-01-01
    • 2014-04-20
    • 2018-06-30
    • 2010-11-11
    • 1970-01-01
    相关资源
    最近更新 更多