Fix macOS/Linux issues

- Fixes png lib becoming undefined on macOS
- Auto-detect macports png/Qt paths
- Fixes typos
- Workaround for AppleClang/fmt bug
This commit is contained in:
Luke Street 2021-06-30 16:27:53 -04:00
parent 9ca1a38171
commit 78f8716150
17 changed files with 66 additions and 101 deletions

View File

@ -525,13 +525,16 @@ add_subdirectory(visigen)
add_dependencies(hecl visigen)
if (NOT WINDOWS_STORE AND NOT NX)
if(APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
if (APPLE AND EXISTS /opt/local/libexec/qt5)
# macports qt5 (build with +universal)
set(Qt5Widgets_DIR /opt/local/libexec/qt5)
elseif (APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
set(QT_HOMEBREW_PATH /usr/local/opt/qt)
elseif(APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL arm64)
elseif (APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL arm64)
set(QT_HOMEBREW_PATH /opt/homebrew/opt/qt)
else()
else ()
set(QT_HOMEBREW_PATH "")
endif()
endif ()
find_package(Qt6Widgets QUIET PATHS ${QT_HOMEBREW_PATH})
find_package(Qt5Widgets QUIET PATHS ${QT_HOMEBREW_PATH})

View File

@ -230,15 +230,7 @@
"cacheVariables": {
"CMAKE_C_COMPILER_LAUNCHER": "buildcache",
"CMAKE_CXX_COMPILER_LAUNCHER": "buildcache",
"CMAKE_OSX_ARCHITECTURES": "arm64;x86_64",
"Qt5Widgets_DIR": {
"type": "FILEPATH",
"value": "/opt/local/libexec/qt5/lib/cmake/Qt5Widgets"
},
"PNG_DIR": {
"type": "FILEPATH",
"value": "/opt/local/lib"
}
"CMAKE_OSX_ARCHITECTURES": "arm64;x86_64"
}
},
{

View File

@ -73,8 +73,7 @@ add_library(AssetNameMapNull
AssetNameMapNull.cpp)
get_target_property(HECL_INCLUDES hecl-full INCLUDE_DIRECTORIES)
target_include_directories(RetroDataSpec PUBLIC ${PNG_INCLUDE_DIR}
${HECL_INCLUDES} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR})
target_include_directories(RetroDataSpec PUBLIC ${HECL_INCLUDES} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR})
target_link_libraries(RetroDataSpec PUBLIC amuse zeus nod squish ${PNG_LIBRARIES} ${ZLIB_LIBRARIES} lzokay logvisor)
if (COMMAND add_sanitizers)
add_sanitizers(RetroDataSpec)

View File

@ -340,6 +340,11 @@ static const char* ToString(GX::TevRegID arg) {
}
}
// FIXME remove; bug with fmtlib 8.0.0 & AppleClang 12.0.5
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-local-typedef"
#endif
template <class MAT>
static void _DescribeTEV(const MAT& mat) {
for (uint32_t i = 0; i < mat.tevStageCount; ++i) {
@ -354,6 +359,9 @@ static void _DescribeTEV(const MAT& mat) {
bool hasLm = mat.flags.lightmap();
fmt::print(stderr, FMT_STRING("HasIndirect: {} HasLightmap: {}\n"), hasInd, hasLm);
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif
struct TexLink {
const char* shaderInput;

View File

@ -182,7 +182,7 @@ enum class FileLockType { None = 0, Read, Write };
#if _WIN32
using Sstat = struct ::_stat64;
#else
using SStat = struct stat;
using Sstat = struct stat;
#endif
struct FILEDeleter {

2
extern/amuse vendored

@ -1 +1 @@
Subproject commit 603e066eed46388506e0a1f63925030e56070626
Subproject commit 6b73240364ca5d8007f872d4bcf6b3d9dd1f7e02

2
extern/boo vendored

@ -1 +1 @@
Subproject commit 1eb2a46a4194fc50ded0e97ac5027a9e4f7b9382
Subproject commit ce26c0f862ee376491ce1ca5899ac317324b27fa

2
extern/kabufuda vendored

@ -1 +1 @@
Subproject commit 4cf61b7d5edd2f4ccab5ada1f7c987307f1cf1d9
Subproject commit 2252e6c3c391dc162ed1245a5d348c1f9a587a4b

View File

@ -1,19 +1,34 @@
if (APPLE)
if (NOT PNG_DIR)
# hint at macports libpng (build with +universal)
set(PNG_DIR /opt/local/lib)
endif ()
list(LENGTH CMAKE_OSX_ARCHITECTURES num_archs)
if (num_archs GREATER 1)
# disable default search paths so we don't use homebrew's non-universal libpng
set(PNG_SEARCH NO_DEFAULT_PATHS NO_CMAKE_FIND_ROOT_PATH NO_CMAKE_SYSTEM_PATH)
endif ()
# only consider static libs
find_library(PNG_LIB NAMES libpng.a PATHS ${PNG_DIR} NO_DEFAULT_PATHS NO_CMAKE_FIND_ROOT_PATH NO_CMAKE_SYSTEM_PATH)
find_library(PNG_LIB NAMES libpng.a HINTS ${PNG_DIR} ${PNG_SEARCH})
if (PNG_LIB)
set(PNG_LIBRARIES ${PNG_LIB} ${ZLIB_LIBRARIES} CACHE PATH "PNG libraries" FORCE)
find_path(PNG_INCLUDE_DIR png.h PATHS "${PNG_LIB}/../../include" NO_DEFAULT_PATHS NO_CMAKE_FIND_ROOT_PATH NO_CMAKE_SYSTEM_PATH)
set(PNG_INCLUDE_DIR ${PNG_INCLUDE_DIR} CACHE PATH "PNG include path" FORCE)
message(STATUS "Using libpng at ${PNG_LIB}, include: ${PNG_INCLUDE_DIR}")
endif()
elseif (NOT WIN32 AND NOT NX) # remove WIN32 when specter/freetype is gone
find_package(PNG REQUIRED)
set(PNG_LIBRARIES ${PNG_LIBRARIES} ${ZLIB_LIBRARIES} CACHE STRING "PNG libraries" FORCE)
set(PNG_INCLUDE_DIR ${PNG_INCLUDE_DIR} CACHE PATH "PNG include path" FORCE)
find_path(PNG_INCLUDE_DIR png.h HINTS "${PNG_LIB}/../../include" NO_DEFAULT_PATHS NO_CMAKE_FIND_ROOT_PATH NO_CMAKE_SYSTEM_PATH)
add_library(png STATIC IMPORTED GLOBAL)
set_target_properties(png PROPERTIES IMPORTED_LOCATION ${PNG_LIB})
target_include_directories(png INTERFACE ${PNG_INCLUDE_DIR})
target_link_libraries(png INTERFACE ${ZLIB_LIBRARIES})
set(PNG_LIBRARIES png CACHE PATH "PNG libraries" FORCE)
message(STATUS "Using static libpng at ${PNG_LIB}, include: ${PNG_INCLUDE_DIR}")
set(PNG_FOUND YES)
endif ()
else ()
find_package(PNG)
if (PNG_FOUND)
set_target_properties(PNG::PNG PROPERTIES IMPORTED_GLOBAL TRUE)
set(PNG_LIBRARIES PNG::PNG CACHE STRING "PNG libraries" FORCE)
endif ()
endif ()
if (WIN32 OR NX OR NOT PNG_LIBRARIES)
message(STATUS "Using HECL's built-in libpng")
if (NOT PNG_FOUND)
message(STATUS "Using built-in libpng")
if ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm(64)?" OR (APPLE AND "arm64" IN_LIST CMAKE_OSX_ARCHITECTURES))
list(APPEND INTRINSICS
arm/arm_init.c
@ -55,6 +70,6 @@ if (WIN32 OR NX OR NOT PNG_LIBRARIES)
target_compile_options(png PRIVATE -Wno-implicit-fallthrough)
endif ()
target_link_libraries(png PUBLIC ${ZLIB_LIBRARIES})
target_include_directories(png INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
set(PNG_LIBRARIES png CACHE PATH "PNG libraries" FORCE)
set(PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE PATH "PNG include path" FORCE)
endif ()

2
extern/nod vendored

@ -1 +1 @@
Subproject commit c1635245b881ed0004ff5e616896579ce1b19164
Subproject commit 0985c63958024d054517216fc2dc0f7c7970a8a3

View File

@ -116,7 +116,7 @@ static inline void ToUpper(std::string& str) {
#if _WIN32
using Sstat = struct ::_stat64;
#else
using SStat = struct stat;
using Sstat = struct stat;
#endif
constexpr size_t StrLen(const char* str) { return std::char_traits<char>::length(str); }
@ -313,28 +313,6 @@ inline unsigned long StrToUl(const char* str, char** endPtr, int base) {
return strtoul(str, endPtr, base);
}
inline bool CheckFreeSpace(const char* path, size_t reqSz) {
#if _WIN32
ULARGE_INTEGER freeBytes;
wchar_t buf[1024];
wchar_t* end;
const nowide::wstackstring wpath(path);
DWORD ret = GetFullPathNameW(wpath.get(), 1024, buf, &end);
if (!ret || ret > 1024)
LogModule.report(logvisor::Fatal, FMT_STRING("GetFullPathNameW {}"), path);
if (end)
end[0] = L'\0';
if (!GetDiskFreeSpaceExW(buf, &freeBytes, nullptr, nullptr))
LogModule.report(logvisor::Fatal, FMT_STRING("GetDiskFreeSpaceExW {}: {}"), path, GetLastError());
return reqSz < freeBytes.QuadPart;
#else
struct statvfs svfs;
if (statvfs(path, &svfs))
LogModule.report(logvisor::Fatal, FMT_STRING("statvfs {}: {}"), path, strerror(errno));
return reqSz < svfs.f_frsize * svfs.f_bavail;
#endif
}
inline bool PathRelative(const char* path) {
if (!path || !path[0])
return false;

View File

@ -426,7 +426,6 @@ Connection::Connection(int verbosityLevel) {
std::string writefds = fmt::format(FMT_STRING("{}"), m_readpipe[1]);
std::string vLevel = fmt::format(FMT_STRING("{}"), verbosityLevel);
/* Try user-specified blender first */
if (blenderBin) {
execlp(blenderBin->c_str(), blenderBin->c_str(), "--background", "-P", blenderShellPath.c_str(), "--",
readfds.c_str(), writefds.c_str(), vLevel.c_str(), blenderAddonPath.c_str(), nullptr);
@ -437,32 +436,6 @@ Connection::Connection(int verbosityLevel) {
}
}
/* Try steam */
steamBlender = hecl::FindCommonSteamApp("Blender");
if (steamBlender.size()) {
#ifdef __APPLE__
steamBlender += "/blender.app/Contents/MacOS/blender";
#else
steamBlender += "/blender";
#endif
execlp(steamBlender.c_str(), steamBlender.c_str(), "--background", "-P", blenderShellPath.c_str(), "--",
readfds.c_str(), writefds.c_str(), vLevel.c_str(), blenderAddonPath.c_str(), nullptr);
if (errno != ENOENT) {
errbuf = fmt::format(FMT_STRING("NOLAUNCH {}"), strerror(errno));
_writeStr(errbuf.c_str(), errbuf.size(), m_readpipe[1]);
exit(1);
}
}
/* Otherwise default blender */
execlp(DEFAULT_BLENDER_BIN, DEFAULT_BLENDER_BIN, "--background", "-P", blenderShellPath.c_str(), "--",
readfds.c_str(), writefds.c_str(), vLevel.c_str(), blenderAddonPath.c_str(), nullptr);
if (errno != ENOENT) {
errbuf = fmt::format(FMT_STRING("NOLAUNCH {}"), strerror(errno));
_writeStr(errbuf.c_str(), errbuf.size(), m_readpipe[1]);
exit(1);
}
/* Unable to find blender */
_writeStr("NOBLENDER", 9, m_readpipe[1]);
exit(1);
@ -490,15 +463,7 @@ Connection::Connection(int verbosityLevel) {
BlenderLog.report(logvisor::Fatal, FMT_STRING("Unable to launch blender: {}"), lineStr.c_str() + 9);
} else if (!lineStr.compare(0, 9, "NOBLENDER")) {
_closePipe();
#if _WIN32
BlenderLog.report(logvisor::Fatal, FMT_STRING("Unable to find blender at '{}'"), blenderBin.value());
#else
if (blenderBin)
BlenderLog.report(logvisor::Fatal, FMT_STRING("Unable to find blender at '{}' or '{}'"), blenderBin,
DEFAULT_BLENDER_BIN);
else
BlenderLog.report(logvisor::Fatal, FMT_STRING("Unable to find blender at '{}'"), DEFAULT_BLENDER_BIN);
#endif
BlenderLog.report(logvisor::Fatal, FMT_STRING("Unable to find blender"));
} else if (lineStr == "INVALIDBLENDERVER") {
_closePipe();
BlenderLog.report(logvisor::Fatal, FMT_STRING("Installed blender version must be >= {}.{}"),

View File

@ -74,7 +74,7 @@ std::optional<std::string> FindBlender(int& major, int& minor) {
}
#else
if (!RegFileExists(blenderBin)) {
if (!RegFileExists(blenderBin->c_str())) {
/* Try steam */
steamBlender = hecl::FindCommonSteamApp("Blender");
if (steamBlender.size()) {
@ -84,15 +84,15 @@ std::optional<std::string> FindBlender(int& major, int& minor) {
steamBlender += "/blender";
#endif
blenderBin = steamBlender.c_str();
if (!RegFileExists(blenderBin)) {
if (!RegFileExists(blenderBin->c_str())) {
blenderBin = DEFAULT_BLENDER_BIN;
if (!RegFileExists(blenderBin)) {
if (!RegFileExists(blenderBin->c_str())) {
blenderBin = nullptr;
}
}
} else {
blenderBin = DEFAULT_BLENDER_BIN;
if (!RegFileExists(blenderBin)) {
if (!RegFileExists(blenderBin->c_str())) {
blenderBin = nullptr;
}
}
@ -124,7 +124,7 @@ std::optional<std::string> FindBlender(int& major, int& minor) {
delete[] infoData;
}
#else
std::string command = std::string("\"") + blenderBin + "\" --version";
std::string command = std::string("\"") + blenderBin.value() + "\" --version";
FILE* fp = popen(command.c_str(), "r");
char versionBuf[256];
size_t rdSize = fread(versionBuf, 1, 255, fp);

View File

@ -28,7 +28,9 @@
#include <sys/wait.h>
#endif
#ifdef __cpp_lib_ranges
#include <ranges>
#endif
#include <logvisor/logvisor.hpp>
using namespace std::literals;
@ -37,7 +39,7 @@ namespace hecl {
unsigned VerbosityLevel = 0;
bool GuiMode = false;
logvisor::Module LogModule("hecl");
constexpr std::string_view Illegals = "<>?\""sv;
constexpr std::string_view Illegals = R"(<>?")";
void SanitizePath(std::string& path) {
if (path.empty())

View File

@ -4,7 +4,10 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
if (APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
if (APPLE AND EXISTS /opt/local/libexec/qt5)
# macports qt5 (build with +universal)
set(Qt5Widgets_DIR /opt/local/libexec/qt5)
elseif (APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
set(QT_HOMEBREW_PATH /usr/local/opt/qt)
elseif (APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL arm64)
set(QT_HOMEBREW_PATH /opt/homebrew/opt/qt)

View File

@ -110,7 +110,7 @@ static void AthenaExc(athena::error::Level level, const char* /*file*/, const ch
AthenaLog.vreport(logvisor::Level(level), fmt, args);
}
int main(int argc, const char** argv)
int main(int argc, char** argv)
{
if (argc > 1 && !strcmp(argv[1], "--dlpackage"))
{

View File

@ -74,7 +74,7 @@ static void UpdatePercent(float percent) {
/* Empty handler for SIGINT */
static void _sigint(int) {}
int main(int argc, const char** argv) {
int main(int argc, char** argv) {
if (argc > 1 && !strcmp(argv[1], "--dlpackage")) {
fmt::print(FMT_STRING("{}\n"), METAFORCE_DLPACKAGE);
return 100;