Skip to content

Commit

Permalink
soh build fixes (HarbourMasters#14)
Browse files Browse the repository at this point in the history
* changes needed to run `ExtractAssets`

* soh build stuff

* Make some things public

* dcvz changes

* More fixes

* fix pulseaudio

* windows static lib stuff

* fix soh build on windows

* Don’t require Threads for Wii U

* Wii U specific changes to upstream StormLib

* Fix up storm linking

* Add Wii U additions to spdlog

* More Wii U updates to libultraship

* Wii U specific import fixes

* LUS Wii U fixes

* STBI_NO_THREAD_LOCALS for Wii U

* Disable threads for Wii U

* Fixes OTR loading (tested in SoH)

Previously it was failing with a file not found error on SFileOpenArchive,
for some reason removing `UNICODE` and `_UNICODE` from the compile definitions
of libultraship fixes it. It also fixes the issue of OTRExporter outputting
an OTR with only the first character of the filename present. (Said OTR was
still valid though, despite the odd name. Fixed by this regardless).

* Re-adds missing Debug/Release cmake config and fixes Typos

This re-enables debugging libultraship files on Windows. Also fixes some
typos that previously weren't being compiled due to the missing
Debug/Release configuration.

* Consolidates compiler and linker flags in cmake.

Several compiler options were duplicated across different systems
unnecessarily. For example Windows "x64" and "Win32" were very nearly
identical already, and the couple of differences didn't make much sense.
We were passing /std:c++latest, but only to x64 Release. I just removed
that one altogether since we already set `PROPERTY CXX_STANDARD 20`
at the top of the file. We were also passing `/W3` regardless of configuration
on "x64", but on "Win32" we were passing `/W2` to Debug and `/W3` to Release.
If there's a reason for that let me know and it can be re-introduced.

* Embed STB into LUS

* Fixes Switch builds. (#4)

* Restricts the stormlib compile definition change to switch (#5)

* make tidy happy?

* actually make tidy happy

* checkout v3?

* remove commented out lines from cmakelists

* fontData not font_data

* suppress error

* add a space

Co-authored-by: briaguya <briaguya@alice>
Co-authored-by: David Chavez <david@dcvz.io>
Co-authored-by: Christopher Leggett <chris@leggett.dev>
Co-authored-by: David Chavez <davi@dcvz.io>
Co-authored-by: briaguya <briaguya>
  • Loading branch information
5 people authored Nov 13, 2022
1 parent c75c6b3 commit 9462f8f
Show file tree
Hide file tree
Showing 27 changed files with 288 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tidy-format-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y libsdl2-dev libpng-dev libglew-dev ninja-build clang-tidy clang-format-12
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 2
- name: ccache
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
enable_language(OBJCXX)
endif()

if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()

include(cmake/Utils.cmake)

if (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND USE_AUTO_VCPKG)
Expand Down
65 changes: 65 additions & 0 deletions cmake/Default.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
################################################################################
# Command for variable_watch. This command issues error message, if a variable
# is changed. If variable PROPERTY_READER_GUARD_DISABLED is TRUE nothing happens
# variable_watch(<variable> property_reader_guard)
################################################################################
function(property_reader_guard VARIABLE ACCESS VALUE CURRENT_LIST_FILE STACK)
if("${PROPERTY_READER_GUARD_DISABLED}")
return()
endif()

if("${ACCESS}" STREQUAL "MODIFIED_ACCESS")
message(FATAL_ERROR
" Variable ${VARIABLE} is not supposed to be changed.\n"
" It is used only for reading target property ${VARIABLE}.\n"
" Use\n"
" set_target_properties(\"<target>\" PROPERTIES \"${VARIABLE}\" \"<value>\")\n"
" or\n"
" set_target_properties(\"<target>\" PROPERTIES \"${VARIABLE}_<CONFIG>\" \"<value>\")\n"
" instead.\n")
endif()
endfunction()

################################################################################
# Create variable <name> with generator expression that expands to value of
# target property <name>_<CONFIG>. If property is empty or not set then property
# <name> is used instead. Variable <name> has watcher property_reader_guard that
# doesn't allow to edit it.
# create_property_reader(<name>)
# Input:
# name - Name of watched property and output variable
################################################################################
function(create_property_reader NAME)
set(PROPERTY_READER_GUARD_DISABLED TRUE)
set(CONFIG_VALUE "$<TARGET_GENEX_EVAL:${PROPS_TARGET},$<TARGET_PROPERTY:${PROPS_TARGET},${NAME}_$<UPPER_CASE:$<CONFIG>>>>")
set(IS_CONFIG_VALUE_EMPTY "$<STREQUAL:${CONFIG_VALUE},>")
set(GENERAL_VALUE "$<TARGET_GENEX_EVAL:${PROPS_TARGET},$<TARGET_PROPERTY:${PROPS_TARGET},${NAME}>>")
set("${NAME}" "$<IF:${IS_CONFIG_VALUE_EMPTY},${GENERAL_VALUE},${CONFIG_VALUE}>" PARENT_SCOPE)
variable_watch("${NAME}" property_reader_guard)
endfunction()

################################################################################
# Set property $<name>_${PROPS_CONFIG_U} of ${PROPS_TARGET} to <value>
# set_config_specific_property(<name> <value>)
# Input:
# name - Prefix of property name
# value - New value
################################################################################
function(set_config_specific_property NAME VALUE)
set_target_properties("${PROPS_TARGET}" PROPERTIES "${NAME}_${PROPS_CONFIG_U}" "${VALUE}")
endfunction()

################################################################################

create_property_reader("TARGET_NAME")
create_property_reader("OUTPUT_DIRECTORY")

set_config_specific_property("TARGET_NAME" "${PROPS_TARGET}")
set_config_specific_property("OUTPUT_NAME" "${TARGET_NAME}")
set_config_specific_property("ARCHIVE_OUTPUT_NAME" "${TARGET_NAME}")
set_config_specific_property("LIBRARY_OUTPUT_NAME" "${TARGET_NAME}")
set_config_specific_property("RUNTIME_OUTPUT_NAME" "${TARGET_NAME}")

set_config_specific_property("ARCHIVE_OUTPUT_DIRECTORY" "${OUTPUT_DIRECTORY}")
set_config_specific_property("LIBRARY_OUTPUT_DIRECTORY" "${OUTPUT_DIRECTORY}")
set_config_specific_property("RUNTIME_OUTPUT_DIRECTORY" "${OUTPUT_DIRECTORY}")
12 changes: 12 additions & 0 deletions cmake/DefaultCXX.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
include("${CMAKE_CURRENT_LIST_DIR}/Default.cmake")

set_config_specific_property("OUTPUT_DIRECTORY" "${CMAKE_SOURCE_DIR}$<$<NOT:$<STREQUAL:${CMAKE_VS_PLATFORM_NAME},Win32>>:/${CMAKE_VS_PLATFORM_NAME}>/${PROPS_CONFIG}")

if(MSVC)
create_property_reader("DEFAULT_CXX_EXCEPTION_HANDLING")
create_property_reader("DEFAULT_CXX_DEBUG_INFORMATION_FORMAT")

# set_target_properties("${PROPS_TARGET}" PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
set_config_specific_property("DEFAULT_CXX_EXCEPTION_HANDLING" "/EHsc")
set_config_specific_property("DEFAULT_CXX_DEBUG_INFORMATION_FORMAT" "/Zi")
endif()
26 changes: 9 additions & 17 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ target_include_directories(DrLibs INTERFACE ${DRLIBS_DIR})

set(STORMLIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/StormLib)
add_subdirectory(${STORMLIB_DIR})
if (CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")
target_compile_definitions(storm PRIVATE -D_POSIX_C_SOURCE=200809L)
endif()

#=================== ImGui ===================

Expand All @@ -33,6 +36,10 @@ target_sources(ImGui
${IMGUI_DIR}/imgui.cpp
)

if (CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")
target_include_directories(ImGui PRIVATE ${DEVKITPRO}/portlibs/switch/include/)
endif()

if (NOT CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
target_sources(ImGui
PRIVATE
Expand All @@ -51,13 +58,12 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "CafeOS")

target_sources(ImGui
PRIVATE
${IMGUI_DIR}/backends/imgui_impl_wiiu.cpp
${IMGUI_DIR}/backends/imgui_impl_gx2.cpp
${IMGUI_DIR}/backends/wiiu/imgui_impl_wiiu.cpp
${IMGUI_DIR}/backends/wiiu/imgui_impl_gx2.cpp
)
endif()

target_include_directories(ImGui PUBLIC ${IMGUI_DIR} ${IMGUI_DIR}/backends PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_libraries(ImGui PUBLIC storm)

if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_libraries(ImGui PUBLIC SDL2::SDL2 SDL2::SDL2main)
Expand Down Expand Up @@ -109,15 +115,6 @@ target_include_directories(Mercury PUBLIC ${MERCURY_DIR} ${ZAPDUTILS_DIR})

target_link_libraries(Mercury PUBLIC ZAPDUtils nlohmann_json::nlohmann_json)

#=================== STB ===================

set(STB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/stb)
add_library(stb STATIC)

target_sources(stb PRIVATE ${STB_DIR}/stb_impl.c)

target_include_directories(stb PUBLIC ${STB_DIR})

#=================== StrHash64 ===================

set(STRHASH64_DIR ${CMAKE_CURRENT_SOURCE_DIR}/StrHash64)
Expand All @@ -126,8 +123,3 @@ add_library(StrHash64 STATIC)
target_sources(StrHash64 PRIVATE ${STRHASH64_DIR}/StrHash64.cpp)

target_include_directories(StrHash64 PUBLIC ${STRHASH64_DIR})

#=================== spdlog ===================

set(SPDLOG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/spdlog)
add_subdirectory(${SPDLOG_DIR})
5 changes: 5 additions & 0 deletions extern/StormLib/src/FileStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@
// Local functions - platform-specific functions

#ifndef STORMLIB_WINDOWS

#ifndef STORMLIB_WIIU
static thread_local DWORD dwLastError = ERROR_SUCCESS;
#else
static DWORD dwLastError = ERROR_SUCCESS;
#endif

DWORD GetLastError()
{
Expand Down
28 changes: 28 additions & 0 deletions extern/StormLib/src/StormPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,34 @@

#endif

//-----------------------------------------------------------------------------
// Defines for Wii U platform

#if !defined(STORMLIB_PLATFORM_DEFINED) && defined(__WIIU__)

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
#include <assert.h>
#include <errno.h>
#include <malloc.h>

#undef STORMLIB_LITTLE_ENDIAN // Wii U is always big endian

#define STORMLIB_MAC // Use Mac compatible code
#define STORMLIB_WIIU
#define STORMLIB_PLATFORM_DEFINED

#endif

//-----------------------------------------------------------------------------
// Assumption: If the platform is not defined, assume a Linux-like platform

Expand Down
2 changes: 2 additions & 0 deletions extern/ZAPDUtils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ set(PROJECT_NAME ZAPDUtils)
################################################################################
set(Source_Files__Utils
"Utils/StringHelper.cpp"
"Utils/MemoryStream.cpp"
"Utils/BinaryWriter.cpp"
)
source_group("Source Files\\Utils" FILES ${Source_Files__Utils})

Expand Down
2 changes: 1 addition & 1 deletion extern/spdlog/include/spdlog/details/os-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm)
return offset;
#else

# if defined(sun) || defined(__sun) || defined(_AIX) || (!defined(_BSD_SOURCE) && !defined(_GNU_SOURCE))
# if defined(sun) || defined(__sun) || defined(_AIX) || (!defined(_BSD_SOURCE) && !defined(_GNU_SOURCE)) || defined(__WIIU__)
// 'tm_gmtoff' field is BSD extension and it's missing on SunOS/Solaris
struct helper
{
Expand Down
97 changes: 86 additions & 11 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ add_library(libultraship STATIC)
set_property(TARGET libultraship PROPERTY CXX_STANDARD 20)
set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../include)

if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
use_props(${PROJECT_NAME} "${CMAKE_CONFIGURATION_TYPES}" "${DEFAULT_CXX_PROPS}")
endif()

#=================== Audio ===================

set(Source_Files__Audio
Expand Down Expand Up @@ -114,7 +118,6 @@ source_group("Log\\SPDLog" FILES ${Source_Files__Log__SPDLog})

target_sources(libultraship PRIVATE ${Source_Files__Log} ${Source_Files__Log__SPDLog})


#=================== Menu ===================

set(Source_Files__Menu
Expand Down Expand Up @@ -190,6 +193,8 @@ set(Source_Files__Resource
source_group("Resource" FILES ${Source_Files__Resource})

set(Source_Files__Resource__Factory
${CMAKE_CURRENT_SOURCE_DIR}/resource/factory/SoH/AnimationFactory.h
${CMAKE_CURRENT_SOURCE_DIR}/resource/factory/SoH/AnimationFactory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/resource/factory/SoH/ArrayFactory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/resource/factory/SoH/ArrayFactory.h
${CMAKE_CURRENT_SOURCE_DIR}/resource/factory/SoH/AudioFactory.cpp
Expand Down Expand Up @@ -242,6 +247,8 @@ set(Source_Files__Resource__Types
${CMAKE_CURRENT_SOURCE_DIR}/resource/types/Cutscene.h
${CMAKE_CURRENT_SOURCE_DIR}/resource/types/DisplayList.cpp
${CMAKE_CURRENT_SOURCE_DIR}/resource/types/DisplayList.h
${CMAKE_CURRENT_SOURCE_DIR}/resource/types/GameOverlay.cpp
${CMAKE_CURRENT_SOURCE_DIR}/resource/types/GameOverlay.h
${CMAKE_CURRENT_SOURCE_DIR}/resource/types/Material.cpp
${CMAKE_CURRENT_SOURCE_DIR}/resource/types/Material.h
${CMAKE_CURRENT_SOURCE_DIR}/resource/types/Matrix.cpp
Expand Down Expand Up @@ -271,7 +278,6 @@ source_group("Resource\\Types" FILES ${Source_Files__Resource__Types})
target_sources(libultraship PRIVATE ${Source_Files__Resource} ${Source_Files__Resource__Factory} ${Source_Files__Resource__Types})

#=================== Graphic ===================
# TODO: Make this a lib but currently it uses files from src

set(Source_Files__Graphic
${CMAKE_CURRENT_SOURCE_DIR}/graphic/Fast3D/gfx_cc.h
Expand All @@ -291,6 +297,8 @@ endif()

if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
list(APPEND Source_Files__Graphic
${CMAKE_CURRENT_SOURCE_DIR}/graphic/Fast3D/gfx_dxgi.h
${CMAKE_CURRENT_SOURCE_DIR}/graphic/Fast3D/gfx_dxgi.cpp
${CMAKE_CURRENT_SOURCE_DIR}/graphic/Fast3D/gfx_direct3d11.h
${CMAKE_CURRENT_SOURCE_DIR}/graphic/Fast3D/gfx_direct3d11.cpp
${CMAKE_CURRENT_SOURCE_DIR}/graphic/Fast3D/gfx_direct3d12.h
Expand All @@ -317,12 +325,23 @@ endif()
source_group("Graphic" FILES ${Source_Files__Graphic})
target_sources(libultraship PRIVATE ${Source_Files__Graphic})

#=================== STB ===================

set(Source_Files__Lib__stb
"${CMAKE_CURRENT_SOURCE_DIR}/../extern/stb/stb_image.h"
"${CMAKE_CURRENT_SOURCE_DIR}/../extern/stb/stb_image_write.h"
"${CMAKE_CURRENT_SOURCE_DIR}/../extern/stb/stb_impl.c"
)
source_group("Extern\\stb" FILES ${Source_Files__Lib__stb})
target_sources(libultraship PRIVATE ${Source_Files__Lib__stb})


#=================== Packages & Includes ===================

target_include_directories(libultraship
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../extern
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/graphic/Fast3D/U64/PR
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../extern/spdlog/include ${CMAKE_CURRENT_SOURCE_DIR}/../extern/stb
)

if (CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
Expand All @@ -334,7 +353,8 @@ endif()
#=================== Linking ===================

target_link_libraries(libultraship
PRIVATE ImGui spdlog ZAPDUtils Mercury tinyxml2 StrHash64
PRIVATE ZAPDUtils tinyxml2 StrHash64
PUBLIC ImGui Mercury storm
)

if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")
Expand All @@ -351,19 +371,74 @@ endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
find_package(X11)
find_package(PulseAudio)
target_link_libraries(libultraship PRIVATE ${X11_LIBRARIES} ${PULSEAUDIO_LIBRARIES})
target_link_libraries(libultraship PRIVATE ${X11_LIBRARIES} ${PULSEAUDIO_LIBRARY})
endif()

#=================== Compile Options & Defs ===================

if (NOT CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
target_compile_definitions(libultraship PRIVATE ENABLE_OPENGL)
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_compile_definitions(${PROJECT_NAME} PRIVATE
WIN32
_CONSOLE
_CRT_SECURE_NO_WARNINGS
ENABLE_DX11
)
endif()

if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
if (NOT CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
target_compile_definitions(libultraship PRIVATE
ENABLE_DX11
"UNICODE;"
"_UNICODE"
ENABLE_OPENGL
$<$<CONFIG:Debug>:_DEBUG>
$<$<NOT:$<CONFIG:Debug>>:NDEBUG>
SPDLOG_ACTIVE_LEVEL=0
)
else ()
target_compile_definitions(libultraship PRIVATE
$<$<CONFIG:Debug>:_DEBUG>
$<$<NOT:$<CONFIG:Debug>>:NDEBUG>
SPDLOG_NO_THREAD_ID
SPDLOG_NO_TLS
STBI_NO_THREAD_LOCALS
SPDLOG_ACTIVE_LEVEL=3
)
endif()

if(MSVC)
target_compile_options(libultraship PRIVATE
$<$<CONFIG:Debug>:
/Od;
/Oi-
>
$<$<CONFIG:Release>:
/Oi;
/Gy
>
/permissive-;
/MP;
/sdl;
/W3;
${DEFAULT_CXX_DEBUG_INFORMATION_FORMAT};
${DEFAULT_CXX_EXCEPTION_HANDLING};
)
target_link_options(libultraship PRIVATE
$<$<CONFIG:Release>:
/OPT:REF;
/OPT:ICF
>
/SUBSYSTEM:CONSOLE
)
endif()

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
target_compile_options(libultraship PRIVATE
-Wall
-Wextra
-Wno-error
-Wno-unused-variable
-Wno-unused-parameter
-Wno-unused-function
-Wno-parentheses
-Wno-narrowing
-Wno-missing-field-initializers
)
endif()
Loading

0 comments on commit 9462f8f

Please sign in to comment.