Extract extern CMakeLists.txt; add nativefiledialog

This commit is contained in:
Luke Street 2022-02-23 00:28:21 -05:00
parent b2b03f1ace
commit 107ca74702
8 changed files with 160 additions and 104 deletions

3
.gitmodules vendored
View File

@ -63,3 +63,6 @@
[submodule "extern/dawn"]
path = extern/dawn
url = https://github.com/encounter/dawn-cmake.git
[submodule "extern/nativefiledialog"]
path = extern/nativefiledialog
url = https://github.com/mlabbe/nativefiledialog.git

View File

@ -113,9 +113,6 @@ endif()
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Force shared libs off" FORCE)
set(BUILD_STATIC_LIBS ON CACHE BOOL "Force static libs on" FORCE)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/extern/sanitizers-cmake/cmake")
find_package(Sanitizers)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL AMD64)
set(METAFORCE_VECTOR_ISA "sse41" CACHE STRING "Vector ISA to build for (sse2, sse3, sse41, avx, avx2)")
endif ()
@ -344,71 +341,15 @@ if(USE_LD_GOLD)
endif()
endif()
# Add discord-rpc here
if(NOT GEKKO AND NOT NX)
set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/discord-rpc)
if (NOT CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR ${CMAKE_BINARY_DIR}/fake-prefix)
endif()
add_subdirectory(extern/discord-rpc/src EXCLUDE_FROM_ALL)
target_include_directories(discord-rpc PRIVATE extern/rapidjson/include PUBLIC extern/discord-rpc/include)
if (APPLE)
# remove their nasty hack
get_target_property(DISCORD_LINK_LIBRARIES discord-rpc INTERFACE_LINK_LIBRARIES)
list(REMOVE_ITEM DISCORD_LINK_LIBRARIES "-framework AppKit, -mmacosx-version-min=10.10")
set_target_properties(discord-rpc PROPERTIES INTERFACE_LINK_LIBRARIES "${DISCORD_LINK_LIBRARIES}")
endif ()
if (UNIX)
# remove another nasty hack
get_target_property(DISCORD_COMPILE_OPTIONS discord-rpc COMPILE_OPTIONS)
list(REMOVE_ITEM DISCORD_COMPILE_OPTIONS "-g")
set_target_properties(discord-rpc PROPERTIES COMPILE_OPTIONS "${DISCORD_COMPILE_OPTIONS}")
endif ()
endif()
if (NOT WIN32)
find_package(ZLIB REQUIRED)
set(ZLIB_LIBRARIES ZLIB::ZLIB CACHE STRING "zlib libraries" FORCE)
endif()
option(BUILD_ATHENA "Build Athena libraries from source" ON)
if (WIN32 OR APPLE)
# Default to binary atdna on Windows & macOS
option(BUILD_ATDNA "Build atdna utility from source (requires LLVM)" OFF)
else ()
option(BUILD_ATDNA "Build atdna utility from source (requires LLVM)" ON)
endif ()
# TODO migrate bintoc
include(hecl/ApplicationTools.cmake)
if (NOT BUILD_ATDNA)
set(ATHENA_BASE_URL "https://github.com/libAthena/athena/releases/download/latest")
if (WIN32)
set(ATHENA_EXT 7z)
else()
set(ATHENA_EXT tar.gz)
endif()
include(FetchContent)
FetchContent_Declare(athena-host
URL "${ATHENA_BASE_URL}/athena-${PLATFORM_NAME}-${ATHENA_HOST_ARCH}.${ATHENA_EXT}")
message(STATUS "Fetching atdna host binary")
FetchContent_Populate(athena-host)
include(${athena-host_SOURCE_DIR}/lib/cmake/atdna/atdnaConfig.cmake)
endif ()
if (BUILD_ATHENA OR BUILD_ATDNA)
add_subdirectory(extern/athena EXCLUDE_FROM_ALL)
else()
if (ATHENA_ARCH STREQUAL ATHENA_HOST_ARCH)
set(athena_SOURCE_DIR "${athena-host_SOURCE_DIR}")
else()
FetchContent_Declare(athena
URL "${ATHENA_BASE_URL}/athena-${PLATFORM_NAME}-${ATHENA_ARCH}.tar.gz")
FetchContent_Populate(athena)
endif()
include(${athena_SOURCE_DIR}/lib/cmake/athena/AthenaConfig.cmake)
include(${athena_SOURCE_DIR}/lib/cmake/lzokay/lzokayConfig.cmake)
add_library(lzokay ALIAS lzokay::lzokay)
include(extern/athena/atdna/atdnaHelpers.cmake)
endif()
add_subdirectory(extern)
set(DATA_SPEC_LIBS RetroDataSpec AssetNameMap)
set(HECL_DATASPEC_DECLS
@ -438,17 +379,8 @@ set(HECL_DATASPEC_PUSHES
hecl::Database::DATA_SPEC_REGISTRY.push_back(&DataSpec::SpecEntMP3PC);
hecl::Database::DATA_SPEC_REGISTRY.push_back(&DataSpec::SpecEntMP3ORIG);")
add_subdirectory(extern/nod EXCLUDE_FROM_ALL)
add_subdirectory(extern/boo EXCLUDE_FROM_ALL)
include(hecl/ApplicationTools.cmake)
add_subdirectory(extern/xxhash EXCLUDE_FROM_ALL)
add_subdirectory(imgui)
add_subdirectory(extern/libSquish EXCLUDE_FROM_ALL)
add_subdirectory(extern/libpng EXCLUDE_FROM_ALL)
add_subdirectory(extern/libjpeg-turbo EXCLUDE_FROM_ALL)
add_subdirectory(hecl EXCLUDE_FROM_ALL)
add_subdirectory(extern/zeus EXCLUDE_FROM_ALL)
target_include_directories(hecl-full PRIVATE ${CMAKE_SOURCE_DIR})
target_include_directories(hecl-light PRIVATE ${CMAKE_SOURCE_DIR})
target_link_libraries(hecl-full PRIVATE zeus nod)
@ -462,16 +394,11 @@ if(NOT TARGET atdna)
endif()
endif()
add_subdirectory(extern/amuse EXCLUDE_FROM_ALL)
if (NOT CMAKE_CROSSCOMPILING)
add_subdirectory(assetnameparser EXCLUDE_FROM_ALL)
endif ()
add_compile_definitions(URDE_ZIP_INPUT_STREAM=1) # Enable CZipInputStream now that zlib header is known
add_subdirectory(DataSpec EXCLUDE_FROM_ALL)
add_subdirectory(extern/kabufuda EXCLUDE_FROM_ALL)
add_subdirectory(extern/jbus EXCLUDE_FROM_ALL)
set(JBUS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/jbus/include)
add_subdirectory(NESEmulator EXCLUDE_FROM_ALL)
add_subdirectory(aurora)

View File

@ -269,8 +269,8 @@ private:
using delta_clock = std::chrono::high_resolution_clock;
std::chrono::time_point<delta_clock> m_prevFrameTime;
std::vector<u32> m_defferredControllers; // used to capture controllers added before CInputGenerator
// is built, i.e during initialization
std::vector<u32> m_deferredControllers; // used to capture controllers added before CInputGenerator
// is built, i.e during initialization
public:
Application(FileStoreManager& fileMgr, CVarManager& cvarMgr, CVarCommons& cvarCmns)
@ -312,11 +312,11 @@ public:
bool onAppIdle(float realDt) noexcept override {
if (auto* input = g_InputGenerator) {
if (!m_defferredControllers.empty()) {
for (const auto which : m_defferredControllers) {
if (!m_deferredControllers.empty()) {
for (const auto which : m_deferredControllers) {
input->controllerAdded(which);
}
m_defferredControllers.clear();
m_deferredControllers.clear();
}
}
@ -324,14 +324,11 @@ public:
if (CDvdFile::Initialize(m_deferredProject)) {
m_projectInitialized = true;
} else {
Log.report(logvisor::Error, FMT_STRING("Project doesn't exist at '{}'"), m_deferredProject);
m_errorString = fmt::format(FMT_STRING("Project not found at '{}'"), m_deferredProject);
Log.report(logvisor::Error, FMT_STRING("Failed to open disc image '{}'"), m_deferredProject);
m_errorString = fmt::format(FMT_STRING("Failed to open disc image '{}'"), m_deferredProject);
m_deferredProject.clear();
}
}
if (!m_projectInitialized && m_errorString.empty()) {
m_errorString = "Project directory not specified"s;
}
const auto targetFrameTime = getTargetFrameTime();
bool skipRetrace = false;
@ -388,7 +385,10 @@ public:
}
m_imGuiConsole.PostUpdate();
} else {
m_imGuiConsole.ShowAboutWindow(false, m_errorString);
auto result = m_imGuiConsole.ShowAboutWindow(false, m_errorString, true);
if (result) {
m_deferredProject = std::move(*result);
}
}
if (m_quitRequested) {
@ -448,7 +448,7 @@ public:
if (auto* input = g_InputGenerator) {
input->controllerAdded(which);
} else {
m_defferredControllers.emplace_back(which);
m_deferredControllers.emplace_back(which);
}
}

View File

@ -39,15 +39,6 @@ add_subdirectory(MP1)
add_subdirectory(MP2)
add_subdirectory(MP3)
#if (APPLE)
# set_source_files_properties(MP1/CFrontEndUITouchBarMac.mm
# MP1/CSaveGameScreenTouchBarMac.mm
# CGameOptionsTouchBarMac.mm
# PROPERTIES COMPILE_FLAGS -fobjc-arc)
# bintoc(startButton.cpp Resources/startButton@2x.png START_BUTTON_2X)
# list(APPEND PLAT_SRCS startButton.cpp CGameOptionsTouchBarMac.mm)
#endif ()
set(CAST_TO_SOURCES
MkCastTo.py
TCastTo.hpp TCastTo.cpp)
@ -228,10 +219,14 @@ elseif (UNIX)
set(PLAT_LIBS rt)
endif ()
add_executable(metaforce CMain.cpp ${PLAT_SRCS} ImGuiConsole.hpp ImGuiConsole.cpp ImGuiEntitySupport.hpp ImGuiEntitySupport.cpp ../Graphics/lib.cpp) # ImGuiPlayerLoadouts.hpp
# target_atdna(metaforce atdna_ImGuiPlayerLoadouts.cpp ImGuiPlayerLoadouts.hpp)
add_executable(metaforce CMain.cpp ${PLAT_SRCS}
ImGuiConsole.hpp ImGuiConsole.cpp
ImGuiEntitySupport.hpp ImGuiEntitySupport.cpp)
# RUNTIME_LIBRARIES repeated here for link ordering
target_link_libraries(metaforce PUBLIC RuntimeCommon RuntimeCommonB ${RUNTIME_LIBRARIES} ${PLAT_LIBS})
if (TARGET nativefiledialog)
target_link_libraries(metaforce PRIVATE nativefiledialog)
endif()
target_compile_definitions(metaforce PUBLIC "-DMETAFORCE_TARGET_BYTE_ORDER=__BYTE_ORDER__")
if (COMMAND add_sanitizers)

View File

@ -4,11 +4,14 @@
#include "MP1/MP1.hpp"
#include "Runtime/CStateManager.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/World/CPlayer.hpp"
#include "Runtime/ImGuiEntitySupport.hpp"
#include "Runtime/World/CPlayer.hpp"
#include "ImGuiEngine.hpp"
#include "magic_enum.hpp"
#ifdef NATIVEFILEDIALOG_SUPPORTED
#include "nfd.h"
#endif
#include <cstdarg>
@ -27,6 +30,7 @@ extern std::atomic_uint32_t createdPipelines;
#include "TCastTo.hpp" // Generated file, do not modify include path
namespace metaforce {
static logvisor::Module Log{"Console"};
std::array<ImGuiEntityEntry, kMaxEntities> ImGuiConsole::entities;
std::set<TUniqueId> ImGuiConsole::inspectingEntities;
@ -44,6 +48,14 @@ void ImGuiTextCenter(std::string_view text) {
ImGuiStringViewText(text);
}
bool ImGuiButtonCenter(std::string_view text) {
ImGui::NewLine();
float fontSize = ImGui::CalcTextSize(text.data(), text.data() + text.size()).x;
fontSize += ImGui::GetStyle().FramePadding.x;
ImGui::SameLine(ImGui::GetWindowSize().x / 2 - fontSize + fontSize / 2);
return ImGui::Button(text.data());
}
static std::unordered_map<CAssetId, std::unique_ptr<CDummyWorld>> dummyWorlds;
static std::unordered_map<CAssetId, TCachedToken<CStringTable>> stringTables;
@ -601,7 +613,9 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
ImGui::End();
}
void ImGuiConsole::ShowAboutWindow(bool canClose, std::string_view errorString) {
std::optional<std::string> ImGuiConsole::ShowAboutWindow(bool canClose, std::string_view errorString, bool preLaunch) {
std::optional<std::string> result{};
// Center window
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
ImGui::SetNextWindowPos(center, canClose ? ImGuiCond_Appearing : ImGuiCond_Always, ImVec2(0.5f, 0.5f));
@ -628,6 +642,21 @@ void ImGuiConsole::ShowAboutWindow(bool canClose, std::string_view errorString)
ImGuiTextCenter(METAFORCE_WC_DESCRIBE);
const ImVec2& padding = ImGui::GetStyle().WindowPadding;
ImGui::Dummy(padding);
if (preLaunch) {
#ifdef NATIVEFILEDIALOG_SUPPORTED
if (ImGuiButtonCenter("Select Game Disc")) {
nfdchar_t* outPath = nullptr;
nfdresult_t nfdResult = NFD_OpenDialog(nullptr, nullptr, &outPath);
if (nfdResult == NFD_OKAY) {
result = outPath;
free(outPath);
} else if (nfdResult != NFD_CANCEL) {
Log.report(logvisor::Error, FMT_STRING("nativefiledialog error: {}"), NFD_GetError());
}
}
ImGui::Dummy(padding);
#endif
}
if (!errorString.empty()) {
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{0.77f, 0.12f, 0.23f, 1.f});
ImGuiTextCenter(errorString);
@ -708,6 +737,7 @@ void ImGuiConsole::ShowAboutWindow(bool canClose, std::string_view errorString)
}
ImGui::End();
ImGui::PopStyleColor(2);
return result;
}
void ImGuiConsole::ShowDebugOverlay() {

View File

@ -39,12 +39,12 @@ public:
static std::array<ImGuiEntityEntry, kMaxEntities> entities;
static ImGuiPlayerLoadouts loadouts;
ImGuiConsole(CVarManager& cvarMgr, CVarCommons& cvarCommons)
: m_cvarMgr(cvarMgr), m_cvarCommons(cvarCommons) {}
ImGuiConsole(CVarManager& cvarMgr, CVarCommons& cvarCommons) : m_cvarMgr(cvarMgr), m_cvarCommons(cvarCommons) {}
void PreUpdate();
void PostUpdate();
void Shutdown();
void ShowAboutWindow(bool canClose, std::string_view errorString = ""sv);
std::optional<std::string> ShowAboutWindow(bool canClose, std::string_view errorString = ""sv,
bool preLaunch = false);
static void BeginEntityRow(const ImGuiEntityEntry& entry);
static void EndEntityRow(const ImGuiEntityEntry& entry);

100
extern/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,100 @@
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/extern/sanitizers-cmake/cmake")
find_package(Sanitizers)
add_subdirectory(boo EXCLUDE_FROM_ALL)
option(BUILD_ATHENA "Build Athena libraries from source" ON)
if (WIN32 OR APPLE)
# Default to binary atdna on Windows & macOS
option(BUILD_ATDNA "Build atdna utility from source (requires LLVM)" OFF)
else ()
option(BUILD_ATDNA "Build atdna utility from source (requires LLVM)" ON)
endif ()
if (NOT BUILD_ATDNA)
set(ATHENA_BASE_URL "https://github.com/libAthena/athena/releases/download/latest")
if (WIN32)
set(ATHENA_EXT 7z)
else ()
set(ATHENA_EXT tar.gz)
endif ()
include(FetchContent)
FetchContent_Declare(athena-host
URL "${ATHENA_BASE_URL}/athena-${PLATFORM_NAME}-${ATHENA_HOST_ARCH}.${ATHENA_EXT}")
message(STATUS "Fetching atdna host binary")
FetchContent_Populate(athena-host)
include(${athena-host_SOURCE_DIR}/lib/cmake/atdna/atdnaConfig.cmake)
endif ()
if (BUILD_ATHENA OR BUILD_ATDNA)
add_subdirectory(athena EXCLUDE_FROM_ALL)
else ()
if (ATHENA_ARCH STREQUAL ATHENA_HOST_ARCH)
set(athena_SOURCE_DIR "${athena-host_SOURCE_DIR}")
else ()
FetchContent_Declare(athena
URL "${ATHENA_BASE_URL}/athena-${PLATFORM_NAME}-${ATHENA_ARCH}.tar.gz")
FetchContent_Populate(athena)
endif ()
include(${athena_SOURCE_DIR}/lib/cmake/athena/AthenaConfig.cmake)
include(${athena_SOURCE_DIR}/lib/cmake/lzokay/lzokayConfig.cmake)
add_library(lzokay ALIAS lzokay::lzokay)
include(athena/atdna/atdnaHelpers.cmake)
endif ()
# amuse must come after athena/atdna
add_subdirectory(amuse EXCLUDE_FROM_ALL)
if (NOT GEKKO AND NOT NX)
set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/discord-rpc)
if (NOT CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR ${CMAKE_BINARY_DIR}/fake-prefix)
endif ()
add_subdirectory(discord-rpc/src EXCLUDE_FROM_ALL)
target_include_directories(discord-rpc PRIVATE rapidjson/include PUBLIC discord-rpc/include)
if (APPLE)
# remove their nasty hack
get_target_property(DISCORD_LINK_LIBRARIES discord-rpc INTERFACE_LINK_LIBRARIES)
list(REMOVE_ITEM DISCORD_LINK_LIBRARIES "-framework AppKit, -mmacosx-version-min=10.10")
set_target_properties(discord-rpc PROPERTIES INTERFACE_LINK_LIBRARIES "${DISCORD_LINK_LIBRARIES}")
endif ()
if (UNIX)
# remove another nasty hack
get_target_property(DISCORD_COMPILE_OPTIONS discord-rpc COMPILE_OPTIONS)
list(REMOVE_ITEM DISCORD_COMPILE_OPTIONS "-g")
set_target_properties(discord-rpc PROPERTIES COMPILE_OPTIONS "${DISCORD_COMPILE_OPTIONS}")
endif ()
endif ()
add_subdirectory(jbus EXCLUDE_FROM_ALL)
add_subdirectory(kabufuda EXCLUDE_FROM_ALL)
add_subdirectory(libpng EXCLUDE_FROM_ALL)
add_subdirectory(libSquish EXCLUDE_FROM_ALL)
add_library(nativefiledialog STATIC EXCLUDE_FROM_ALL nativefiledialog/src/nfd_common.c)
target_include_directories(nativefiledialog PUBLIC nativefiledialog/src/include)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_sources(nativefiledialog PRIVATE nativefiledialog/src/nfd_gtk.c)
target_compile_definitions(nativefiledialog INTERFACE NATIVEFILEDIALOG_SUPPORTED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
target_link_libraries(nativefiledialog PRIVATE ${GTK3_LIBRARIES})
target_compile_options(nativefiledialog PRIVATE ${GTK3_CFLAGS_OTHER})
target_include_directories(nativefiledialog PRIVATE ${GTK3_INCLUDE_DIRS})
target_link_directories(nativefiledialog PRIVATE ${GTK3_LIBRARY_DIRS})
elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
target_sources(nativefiledialog PRIVATE nativefiledialog/src/nfd_cocoa.m)
target_compile_definitions(nativefiledialog INTERFACE NATIVEFILEDIALOG_SUPPORTED)
# TODO link flags
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_sources(nativefiledialog PRIVATE nativefiledialog/src/nfd_win.cpp)
target_compile_definitions(nativefiledialog INTERFACE NATIVEFILEDIALOG_SUPPORTED)
else ()
message(WARNING "nativefiledialog unsupported for ${CMAKE_SYSTEM_NAME}")
endif ()
add_subdirectory(nod EXCLUDE_FROM_ALL)
add_subdirectory(libjpeg-turbo EXCLUDE_FROM_ALL)
add_subdirectory(xxhash EXCLUDE_FROM_ALL)
add_subdirectory(zeus EXCLUDE_FROM_ALL)

1
extern/nativefiledialog vendored Submodule

@ -0,0 +1 @@
Subproject commit 67345b80ebb429ecc2aeda94c478b3bcc5f7888e