~redstrate/libxiv

79c482ac97f212cd968ea8717645a05b5bd40fac — Joshua Goins 2 years ago ba13bab
Fix compilation on MSVC

Pugixml is now downloaded if not found, and the CMake messages are now
clearer that the dependency is downloaded from the internet.

The POSIX getline function is now replaced with std::getline, which
works on MSVC.
3 files changed, 28 insertions(+), 11 deletions(-)

M CMakeLists.txt
M src/exlparser.cpp
M src/mdlparser.cpp
M CMakeLists.txt => CMakeLists.txt +17 -3
@@ 9,7 9,7 @@ if(TARGET fmt::fmt)

    set(LIBRARIES fmt::fmt ${LIBRARIES})
else()
    message("Using built-in fmt")
    message("Using downloaded fmt")

    FetchContent_Declare(
    fmt


@@ 41,7 41,7 @@ if(TARGET ZLIB::ZLIB)

    set(LIBRARIES ZLIB::ZLIB ${LIBRARIES})
else()
    message("Using built-in zlib")
    message("Using downloaded zlib")

    FetchContent_Declare(
            zlib


@@ 61,7 61,21 @@ else()
    set(LIBRARIES zlibstatic ${LIBRARIES})
endif()

find_package(pugixml REQUIRED)
find_package(pugixml QUIET)

if(TARGET pugixml::pugixml)
    message("Using system library for zlib")
else()
    message("Using downloaded pugixml")

    FetchContent_Declare(
    pugixml
    GIT_REPOSITORY https://github.com/zeux/pugixml.git
    GIT_TAG        master
    )

    FetchContent_MakeAvailable(pugixml)
endif()

add_library(libxiv STATIC
        src/fiinparser.cpp

M src/exlparser.cpp => src/exlparser.cpp +8 -8
@@ 1,20 1,20 @@
#include "exlparser.h"

#include <stdexcept>
#include <fstream>

EXL readEXL(std::string_view path) {
    FILE* file = fopen(path.data(), "rb");
    if(!file) {
    std::fstream file;
    file.open(path.data(), std::iostream::in);

    if(!file.is_open()) {
        throw std::runtime_error("Failed to read exl file from " + std::string(path.data()));
    }

    EXL exl;

    char* data = nullptr;
    size_t len = 0;

    while ((getline(&data, &len, file)) != -1) {
        std::string line = data;

    std::string line;
    while (std::getline(file, line)) {
        const size_t comma = line.find_first_of(',');

        std::string name = line.substr(0, comma);

M src/mdlparser.cpp => src/mdlparser.cpp +3 -0
@@ 7,6 7,9 @@
#include <fstream>
#include <algorithm>

using ushort = unsigned short;
using uint = unsigned int;

// from lumina.halfextensions
static float Unpack(ushort value) {
    uint num3;