# mars_vfs -- the layered virtual filesystem: .gob (ZIP) archives under a
# loose-file override directory. Include from the root with
# add_subdirectory(src/mars/vfs); link mars_vfs. Headers are mars/vfs/*.h.
#
# DEFLATE + CRC-32 come from the vendored miniz (third_party/miniz, MIT).
# The target is created here only if nobody else has already (another
# module may vendor and build the same file).
if(NOT TARGET miniz)
    add_library(miniz STATIC ${CMAKE_CURRENT_SOURCE_DIR}/../../../third_party/miniz/miniz.c)
    target_include_directories(miniz PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../../third_party/miniz)
    # inflate + crc only: no archive/zlib-name surface, no stdio, no time.
    target_compile_definitions(miniz PUBLIC
        MINIZ_NO_ARCHIVE_APIS MINIZ_NO_ARCHIVE_WRITING_APIS MINIZ_NO_STDIO MINIZ_NO_TIME
        MINIZ_NO_ZLIB_COMPATIBLE_NAMES)
    set_target_properties(miniz PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()

add_library(mars_vfs STATIC
    path.cpp
    zip_archive.cpp
    vfs.cpp
)
target_include_directories(mars_vfs PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../..)
target_link_libraries(mars_vfs PRIVATE miniz)
target_compile_features(mars_vfs PUBLIC cxx_std_17)
target_compile_options(mars_vfs PRIVATE -Wall -Wextra -Werror)
