Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ if(MSVC)
add_compile_options(/permissive- /utf-8)
endif()

# MinGW is finicky with unicode
if(MINGW)
if(HEDGELIB_WIN32_FORCE_ANSI)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
else()
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -municode -static")
endif()
endif()

# Make CMake check for packages in "Dependencies" subdirectory
list(APPEND CMAKE_PREFIX_PATH
${HEDGELIB_LOCAL_DEPENDENCIES_DIR}
Expand Down
10 changes: 10 additions & 0 deletions HedgeLib/include/hedgelib/hl_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ OutputIt move_strong(InputIt begin, InputIt end, OutputIt dst) noexcept(
{
#ifdef _MSC_VER
return _aligned_malloc(size, __STDCPP_DEFAULT_NEW_ALIGNMENT__);
#elif __MINGW32__
return _aligned_malloc(size, __STDCPP_DEFAULT_NEW_ALIGNMENT__);
#else
return std::malloc(size);
#endif
Expand All @@ -296,6 +298,8 @@ OutputIt move_strong(InputIt begin, InputIt end, OutputIt dst) noexcept(
{
#ifdef _MSC_VER
return _aligned_malloc(size, alignment);
#elif __MINGW32__
return _aligned_malloc(size, alignment);
#else
return std::aligned_alloc(alignment, size);
#endif
Expand Down Expand Up @@ -344,6 +348,8 @@ template<typename T>
{
#ifdef _MSC_VER
return _aligned_realloc(ptr, size, __STDCPP_DEFAULT_NEW_ALIGNMENT__);
#elif __MINGW32__
return _aligned_realloc(ptr, size, __STDCPP_DEFAULT_NEW_ALIGNMENT__);
#else
return std::realloc(ptr, size);
#endif
Expand All @@ -365,6 +371,8 @@ template<typename T>
{
#ifdef _MSC_VER
return _aligned_realloc(ptr, size, alignment);
#elif __MINGW32__
return _aligned_realloc(ptr, size, alignment);
#else
const auto mem = std::aligned_alloc(alignment, size);
if (mem)
Expand Down Expand Up @@ -428,6 +436,8 @@ inline void free(void* ptr) noexcept
{
#ifdef _MSC_VER
_aligned_free(ptr);
#elif __MINGW32__
_aligned_free(ptr);
#else
std::free(ptr);
#endif
Expand Down
4 changes: 2 additions & 2 deletions HedgeLib/include/hedgelib/io/hl_bina.h
Original file line number Diff line number Diff line change
Expand Up @@ -1011,14 +1011,14 @@ HL_API endian_flag fix_container32(void* rawData, std::size_t dataSize);

inline endian_flag fix_container32(blob& rawData)
{
fix_container32(rawData.data(), rawData.size());
return fix_container32(rawData.data(), rawData.size());
}

HL_API endian_flag fix_container64(void* rawData, std::size_t dataSize);

inline endian_flag fix_container64(blob& rawData)
{
fix_container64(rawData.data(), rawData.size());
return fix_container64(rawData.data(), rawData.size());
}

template<typename T = void>
Expand Down
8 changes: 4 additions & 4 deletions HedgeLib/src/hl_scene.cpp
Copy link
Owner

@Radfordhound Radfordhound Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These types are like this because they changed FbxStreams in FBX SDK version 2020.3.1 to add support for larger files (see commit ca9b1ef).

Can this SDK version, or any newer version, be used with MinGW?

If so, I would undo the changes to this file and just use that SDK version when compiling.

If not, then I'd say it'd be better to actually use typedefs based on the FBX SDK version being used?

Perhaps something like this in the in_fbx_stream_wrapper class?

#if FBXSDK_VERSION_MAJOR > 2020 || \
    (FBXSDK_VERSION_MAJOR == 2020 && FBXSDK_VERSION_MINOR > 3 || \
    (FBXSDK_VERSION_MINOR == 3 && FBXSDK_VERSION_POINT >= 1))
using out_size_t = size_t;
using in_size_t = FbxUInt64;
using pos_t = FbxInt64;
#else
using out_size_t = int;
using in_size_t = int;
using pos_t = long;
#endif

Then obviously change the definitions to use those typedefs:

out_size_t Write(const void* pData, in_size_t pSize) override
out_size_t Read(const void* pData, in_size_t pSize) override
pos_t GetPosition() const override
void SetPosition(pos_t pPosition) override

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have just checked against SDK 2020.3.1 vs2019 and it compiles fine with the original hl_scene.cpp, so yeah, I can agree my changes are redundant.
We can sure discard the changes here.

Original file line number Diff line number Diff line change
Expand Up @@ -481,12 +481,12 @@ class in_fbx_stream_wrapper : public FbxStream
return true;
}

size_t Write(const void* pData, FbxUInt64 pSize) override
int Write(const void* pData, int pSize) override
{
return (!isOpen) ? 0 : static_cast<int>(m_stream->write(pSize, pData));
}

size_t Read(void* pData, FbxUInt64 pSize) const override
int Read(void* pData, int pSize) const override
{
return (!isOpen) ? 0 : static_cast<int>(m_stream->read(pSize, pData));
}
Expand All @@ -508,12 +508,12 @@ class in_fbx_stream_wrapper : public FbxStream
m_stream->seek(in_fbx_get_seek_mode(pSeekPos), pOffset);
}

FbxInt64 GetPosition() const override
long GetPosition() const override
{
return (isOpen) ? m_stream->tell() : 0;
}

void SetPosition(FbxInt64 pPosition) override
void SetPosition(long pPosition) override
{
if (isOpen)
{
Expand Down
2 changes: 1 addition & 1 deletion HedgeLib/src/sets/hl_hson.cpp
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a mistake? I'm trying to use the overload of std::string::assign which takes a begin and end iterator, where the types of both curNameSep + 1 and nextNameSep are const char*. Does this not compile in MinGW?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for not mentioning this one in the PR, must have slipped my mind.
Yes, it does not compile under MinGW, as auto in this case does not make it const char* as you think, but rather char* const&, which is weird as GCC and Clang on Linux have no problem here.
Didn't think about it before, but just hard typing it to be const char* instead of const auto resolves the issue as well.

Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ static const parameter* in_get_parameter(
const auto nextNameSep = std::strchr(curNameSep + 1, '/');
if (nextNameSep)
{
curName.assign(curNameSep + 1, nextNameSep);
curName.assign(curNameSep + 1, nextNameSep[0]);
}
else
{
Expand Down
10 changes: 10 additions & 0 deletions HedgeTools/HedgeArcPack/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,11 @@ static void print_usage(std::FILE* stream)
hl::console::write(get_text(text_id::help1), stream);

// Print types.
#if defined(__MINGW32__) && !defined(HL_WIN32_FORCE_ANSI)
print_types(HL_NTEXT("\t\t%ls"), stream);
#else
print_types(HL_NTEXT("\t\t%s"), stream);
#endif

// Print help2.
hl::console::write(get_text(text_id::help2), stream);
Expand Down Expand Up @@ -455,7 +459,13 @@ static arc_type prompt_for_arc_type()
{
// Ask user for type and print all valid type options.
hl::console::write(get_text(text_id::type1), stderr);

#if defined(__MINGW32__) && !defined(HL_WIN32_FORCE_ANSI)
print_types(HL_NTEXT(" %ls"), stderr);
#else
print_types(HL_NTEXT(" %s"), stderr);
#endif

hl::console::write(get_text(text_id::type2), stderr);

// Get type from user input and return it.
Expand Down
42 changes: 42 additions & 0 deletions HedgeTools/HedgeSet/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,23 @@ static void print_usage(const hl::nchar* templateDir, std::FILE* s)
hl::nfputs(HL_NTEXT(" -game=VALUE Specifies which template to use for conversion.\n"), s);
hl::nfputs(HL_NTEXT(" Valid options are:\n\n"), s);

#if defined(__MINGW32__) && !defined(HL_WIN32_FORCE_ANSI)
print_valid_game_types(templateDir, HL_NTEXT(" %ls"), s);
#else
print_valid_game_types(templateDir, HL_NTEXT(" %s"), s);
#endif

hl::nfputs(HL_NTEXT("\n"), s);

hl::nfputs(HL_NTEXT(" -platform=VALUE Specifies which platform to use for conversion.\n"), s);
hl::nfputs(HL_NTEXT(" Valid options are:\n\n"), s);

#if defined(__MINGW32__) && !defined(HL_WIN32_FORCE_ANSI)
print_valid_platform_types(HL_NTEXT(" %ls"), s);
#else
print_valid_platform_types(HL_NTEXT(" %s"), s);
#endif

}

static hl::nstring prompt_for_game_type(const hl::nchar* templateDir)
Expand All @@ -118,7 +129,11 @@ static hl::nstring prompt_for_game_type(const hl::nchar* templateDir)
hl::nfputs(HL_NTEXT("Game type could not be auto-determined.\n"
"Please enter one of the following options:\n\n"), stderr);

#if defined(__MINGW32__) && !defined(HL_WIN32_FORCE_ANSI)
print_valid_game_types(templateDir, HL_NTEXT(" %ls"), stderr);
#else
print_valid_game_types(templateDir, HL_NTEXT(" %s"), stderr);
#endif

hl::nfprintf(stderr, HL_NTEXT("Game type: "));

Expand All @@ -132,7 +147,11 @@ static platform_type prompt_for_platform_type()
hl::nfputs(HL_NTEXT("Platform type could not be auto-determined.\n"
"Please enter one of the following options:\n\n"), stderr);

#if defined(__MINGW32__) && !defined(HL_WIN32_FORCE_ANSI)
print_valid_platform_types(HL_NTEXT(" %ls"), stderr);
#else
print_valid_platform_types(HL_NTEXT(" %s"), stderr);
#endif

hl::nfprintf(stderr, HL_NTEXT("Platform type: "));

Expand All @@ -145,7 +164,12 @@ static void convert_gedit_v3_to_hson(const hl::set_object_type_database& objType
const hl::nchar* input, const hl::nchar* output, platform_type platform)
{
// Load .gedit file.
#if defined(__MINGW32__) && !defined(HL_WIN32_FORCE_ANSI)
hl::nprintf(HL_NTEXT("Loading set data from \"%ls\"...\n"), input);
#else
hl::nprintf(HL_NTEXT("Loading set data from \"%s\"...\n"), input);
#endif

hl::blob blob(input);

// Fix BINA data.
Expand Down Expand Up @@ -182,7 +206,12 @@ static void convert_hson_to_gedit_v3(const hl::set_object_type_database& objType
const hl::nchar* input, const hl::nchar* output, platform_type platform)
{
// Load HSON data.
#if defined(__MINGW32__) && !defined(HL_WIN32_FORCE_ANSI)
hl::nprintf(HL_NTEXT("Loading HSON data from \"%ls\"...\n"), input);
#else
hl::nprintf(HL_NTEXT("Loading HSON data from \"%s\"...\n"), input);
#endif

hl::hson::project hsonProject(input);

// Save gedit data to file.
Expand Down Expand Up @@ -243,7 +272,11 @@ int HL_NMAIN(int argc, hl::nchar* argv[])
{
hl::nfprintf(stderr,
HL_NTEXT("ERROR: The templates directory was "
#if defined(__MINGW32__) && !defined(HL_WIN32_FORCE_ANSI)
"not found at the expected path (\"%ls\")."),
#else
"not found at the expected path (\"%s\")."),
#endif
templateDir);

hl::console::pause_if_necessary(current_language);
Expand Down Expand Up @@ -314,7 +347,12 @@ int HL_NMAIN(int argc, hl::nchar* argv[])
}

// Load templates for the given game.
#if defined(__MINGW32__) && !defined(HL_WIN32_FORCE_ANSI)
hl::nprintf(HL_NTEXT("Loading templates for %ls...\n"), game);
#else
hl::nprintf(HL_NTEXT("Loading templates for %s...\n"), game);
#endif

const hl::set_object_type_database objTypeDB(
hl::path::combine(templateDir, game) +
HL_NTEXT(".json"));
Expand All @@ -341,7 +379,11 @@ int HL_NMAIN(int argc, hl::nchar* argv[])
{
hl::nfprintf(stderr, HL_NTEXT(
"WARNING: Input file type is of an unknown extension. "
#if defined(__MINGW32__) && !defined(HL_WIN32_FORCE_ANSI)
"Proceeding as if input file is a %ls file.\n"), gameExt);
#else
"Proceeding as if input file is a %s file.\n"), gameExt);
#endif
}

if (!output)
Expand Down
7 changes: 6 additions & 1 deletion cmake/modules/FindFbx.cmake
Copy link
Owner

@Radfordhound Radfordhound Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it work with other versions? If so, this can be removed.

If you don't want to check it that's fine, but honestly in that case I would also just remove this for now and just assume it works with any vs20XX version until proven otherwise.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should work with any other version, but problem here does not lay in the FBX SDK itself, but detection of compilers.
Currently, the script checks for CMAKE_CXX_COMPILER_ID that's equal to MSVC, which isn't true for MinGW, as its ID is GNU.
Furthermore, it will fail again, as the latest version of GCC toolchain is 14.2.0 and not taken into account while checking MSVC versions.
FBX_INCLUDE_DIRS is being set just fine, but without the FBX_CP_PATH, it goes straight to here and returns.

message("A Fbx installation was found, but couldn't be matched with current compiler settings.")

Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ function(FindFbxLibrariesGeneric _FBX_ROOT_DIR _OUT_FBX_LIBRARIES _OUT_FBX_LIBRA
elseif(APPLE)
set(FBX_CP_PATH "*")
else()
set(FBX_CP_PATH "*")
if(MINGW)
# Idk, installed 2020.2.1 vs2019
set(FBX_CP_PATH "vs2019")
else()
set(FBX_CP_PATH "*")
endif()
endif()

# Detects current processor type.
Expand Down
7 changes: 7 additions & 0 deletions cmake/modules/FindLZ4.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,16 @@ find_path(LZ4_INCLUDE_DIR
NAMES lz4.h
DOC "lz4 include directory")
mark_as_advanced(LZ4_INCLUDE_DIR)
# MinGW additions. Under Msys2 we can just specify the static LZ4 library directly
if(MINGW)
find_library(LZ4_LIBRARY
NAMES liblz4.a liblz4
DOC "lz4 library")
else()
find_library(LZ4_LIBRARY
NAMES lz4 liblz4
DOC "lz4 library")
endif()
mark_as_advanced(LZ4_LIBRARY)

if (LZ4_INCLUDE_DIR)
Expand Down