iOrange / sh2tex

Silent Hill 2 Textures Explorer
MIT License
14 stars 3 forks source link

Build issues #6

Open laura-a-n-n opened 3 months ago

laura-a-n-n commented 3 months ago

Hi! I tried to build the project on my machine so I could play around and inspect how the code works. I ran into a few issues, but I eventually resolved them I think. I'm logging my findings here in case it might be useful for anyone. I'm really not experienced with CMake/Make so hopefully I'm getting all this right.

Errors in the C++ files

Before I go into details, I'll start by saying that there was only one class of errors that required any attention in the actual source. They were all some variation of the following:

❯ make
[  0%] Built target sh2tex_autogen_timestamp_deps
[  8%] Automatic MOC and UIC for target sh2tex
[  8%] Built target sh2tex_autogen
[ 16%] Building CXX object CMakeFiles/sh2tex.dir/sh2tex_autogen/mocs_compilation.cpp.o
[ 25%] Building CXX object CMakeFiles/sh2tex.dir/src/main.cpp.o
[redacted]/sh2tex/src/main.cpp:17:13: error: no matching function for call to 'WStrEqualsCaseInsensitive'
        if (WStrEqualsCaseInsensitive(filePath.extension(), L".tex")  ||
            ^~~~~~~~~~~~~~~~~~~~~~~~~
[redacted]/sh2tex/src/ui/../mycommon.h:75:13: note: candidate function not viable: 
    no known conversion from 'path' to 'const WideString' (aka 'const basic_string<wchar_t>') for 1st argument
inline bool WStrEqualsCaseInsensitive(const WideString& str1, const WideString& str2) {

This seemed easy enough to fix, but it seemed like a version/compatibility issue, since clearly this code seems to have compiled successfully for the author.

Solution: appending .wstring() to the first argument of all relevant calls to WStrEqualsCaseInsensitive.

Here are some version details for the macOS machine where I eventually built successfully, after applying the above fix.

❯ gcc --version
Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: arm64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
❯ cmake --version
cmake version 3.29.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).
❯ make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-apple-darwin11.3.0

Qt version: 6.7.0_1. I was not able to compile successfully with qt@5 (see below).

Build errors

I tried building on both a Windows 10 machine and a macOS M2 (Ventura 13.6). On Windows 10, I had problems with earlier version of CMake, but updating to a later version (3.30) helped. At that point, I got the exact same error on Windows as I was getting on Mac. The error went like this:

❯ cmake ..
-- The CXX compiler identification is AppleClang 15.0.0.15000040
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:12 (find_package):
  Could not find a package configuration file provided by "QT" with any of
  the following names:

    Qt6Config.cmake
    qt6-config.cmake
    Qt5Config.cmake
    qt5-config.cmake

  Add the installation prefix of "QT" to CMAKE_PREFIX_PATH or set "QT_DIR" to
  a directory containing one of the above files.  If "QT" provides a separate
  development package or SDK, be sure it has been installed.

There's plenty of documentation on this online, luckily. On both qt@5 and qt@6, the solution involved adding something like this to CMakeLists.txt:

set(QT_DIR /opt/homebrew/Cellar/qt/6.7.0_1/lib/cmake/Qt6) # path to Qt6Config.cmake

That seemed like a typical build issue, but I really don't know enough to say if it is or not.

After applying the code fix mentioned above, I started getting just one error from make:

[redacted]/sh2tex/build/sh2tex_autogen/include/./ui_mainwindow.h:27:10: fatal error: 'imagepanel.h' file not found
#include "imagepanel.h"

The fix was to add this line in the appropriate place to CMakeLists.txt:

target_include_directories(sh2tex PRIVATE src/ui)

However, I could not get this to work with qt@5. Until I upgraded to qt 6, it threw a bunch of silly type errors about candidate functions not being viable for certain calls.

After upgrading to Qt 6 and patching all instances of the WStrEqualsCaseInsensitive bug, I was able to build successfully.

Hopefully this is helpful to someone, somehow. Let me know if you'd like any more information from me. Thanks!