tmxlite icon indicating copy to clipboard operation
tmxlite copied to clipboard

Allow to use external miniz & pugixml

Open SpaceIm opened this issue 3 years ago • 1 comments

It would be nice to be able to use externally installed miniz & pugixml, vendoring is bad for package managers (ODR violation).

  • Move miniz & pugixml files in specific folders (vendor/miniz & vendor/pugixml for example)
  • edit most cpp files with #include <pugixml.hpp> instead of #include "detail/pugixml.hpp" (this modification is tedious for package managers)
  • Add 2 options in Meson & CMake files, like TMXLLITE_EXTERNAL_MINIZ and TMXLLITE_EXTERNAL_PUGIXML
  • Depending on option values, inject vendored deps or find & inject external deps.

SpaceIm avatar Jun 16 '21 08:06 SpaceIm

Hi, thanks for the feedback. This is a good idea.

I'd propose to simplify it a bit by making it something like TMXLITE_EXTERNAL_LIBS in which case you either use the supplied libraries or choose your own. This would also allow further configuration such as alternative zip libraries like zlib or zstdlib (for which there is already an issue) if users prefer.

fallahn avatar Jun 16 '21 12:06 fallahn

I have build a ZLIB switch into my fork, but only for the code, I am not so firm with cmake.. see here for details: https://github.com/ldornbusch/tmxlite/commit/4d61d98f973c5db13c67e547dd75bd33d6d43db0

ldornbusch avatar Feb 14 '23 13:02 ldornbusch

If you're only using a preprocessor definition then cmake is quite easy to update. First you'd need a cmake variable somewhere near the top of the file:

SET(TMXLITE_EXTERNAL_LIBS FALSE CACHE BOOL "Should tmxlite use external zlib and pugixml libraries?")

which lets the user configure it to true or false. Then:

if(TMXLITE_EXTERNAL_LIBS)
    add_definitions(-DUSE_ZIP_LIB -DUSE_PUGIXML_LIB)
endif()

to add the preprocessor defs. You'll also need to tell cmake to find the libraries (probably the most complicated part depending on the library support for cmake)

if(TMX_EXTERNAL_LIBS)
    find_package(zlib)
    find_package(pugixml)

    #optionally do other stuff here if libs not found like pull from github/package manager/build from source
endif()

and then finally tell cmake where the include dirs and libraries to link are

if(TMX_EXTERNAL_LIBS)
    include_directories(${ZLIB_INCLUDE} ${PUGIXML_INCLUDE})
    target_link_libraries(${ZLIB_LIBRARIES} ${PUGIXML_LIBRARIES})
endif

Although the exact include/lib variables will depend on how cmake finds them. As for meson, I have no idea, I've never used it 😅

fallahn avatar Feb 14 '23 13:02 fallahn

ok I will try this out but will take some time

ldornbusch avatar Feb 14 '23 16:02 ldornbusch

The standard way to do this in meson is actually to delete:

  • all custom options
  • the local copies of the library and rely on the global builtin option: --wrap-mode=forcefallback.

You'd then use dependency() as the sole way to get either external dependency, and run meson wrap install pugixml && meson wrap install miniz -- this would install two small INI files describing where to download the sources from on demand.

See https://mesonbuild.com/Wrap-dependency-system-manual.html

eli-schwartz avatar Apr 05 '23 06:04 eli-schwartz

Oh, OK. I'm not really familiar with meson, support was kindly provided by @KingDuckZ and I modified it as best I knew how to work with this update. Thanks for the tip!

fallahn avatar Apr 05 '23 08:04 fallahn