From 29430a8a6cc9af73537438e0ba377ccd9498c616 Mon Sep 17 00:00:00 2001 From: falsycat Date: Fri, 27 May 2022 06:08:31 -0700 Subject: [PATCH] fix issues on MSVC --- CMakeLists.txt | 4 +++- common/type_info.hh | 6 ++---- common/yas.hh | 1 + file/system_logger.cc | 1 + main.cc | 2 +- nf7.hh | 15 ++++++--------- thirdparty/CMakeLists.txt | 6 +++--- 7 files changed, 17 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d498cd8..0fe02aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,9 +17,11 @@ set(NF7_CXX_FLAGS $<$,$>: -Wno-overloaded-virtual> $<$: - /W4 /WX> + /W4 /WX /Zc:__cplusplus /external:anglebrackets /external:W0> ) +set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) + add_subdirectory(thirdparty EXCLUDE_FROM_ALL) add_subdirectory(tool) diff --git a/common/type_info.hh b/common/type_info.hh index 87ff3ea..d258907 100644 --- a/common/type_info.hh +++ b/common/type_info.hh @@ -8,8 +8,6 @@ namespace nf7 { template class GenericTypeInfo : public File::TypeInfo { public: - static constexpr bool kHasFactory = std::is_constructible::value; - GenericTypeInfo(const std::string& name, std::unordered_set&& v) noexcept : TypeInfo(name, AddFlags(std::move(v))) { } @@ -21,7 +19,7 @@ class GenericTypeInfo : public File::TypeInfo { throw DeserializeException(std::string(name())+" deserialization failed"); } std::unique_ptr Create(Env& env) const noexcept override { - if constexpr (kHasFactory) { + if constexpr (std::is_constructible::value) { return std::make_unique(env); } else { return nullptr; @@ -31,7 +29,7 @@ class GenericTypeInfo : public File::TypeInfo { private: static std::unordered_set AddFlags( std::unordered_set&& flags) noexcept { - if (kHasFactory) flags.insert("File_Factory"); + if (std::is_constructible::value) flags.insert("File_Factory"); return flags; } }; diff --git a/common/yas.hh b/common/yas.hh index 5aaa76e..ccf8840 100644 --- a/common/yas.hh +++ b/common/yas.hh @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include diff --git a/file/system_logger.cc b/file/system_logger.cc index a392d24..fd61e39 100644 --- a/file/system_logger.cc +++ b/file/system_logger.cc @@ -136,6 +136,7 @@ class Logger final : public File, return "ERRR"; default: assert(false); + return "X("; } } static std::string GetLocationString(const std::source_location loc) noexcept { diff --git a/main.cc b/main.cc index 0324498..9202df4 100644 --- a/main.cc +++ b/main.cc @@ -46,7 +46,7 @@ class Env final : public nf7::Env { // deserialize try { if (!std::filesystem::exists(kFileName)) { - std::ofstream of(kFileName); + std::ofstream of(kFileName, std::ios::binary); if (!of) throw Exception("failed to open native file: "s+kFileName); of.write(kDefaultRoot, sizeof(kDefaultRoot)); of.flush(); diff --git a/nf7.hh b/nf7.hh index 6c3e177..b87ee6a 100644 --- a/nf7.hh +++ b/nf7.hh @@ -28,29 +28,26 @@ class Env; using Serializer = yas::binary_oarchive; using Deserializer = yas::binary_iarchive; -class Exception { +class Exception : public std::nested_exception { public: Exception() = delete; - Exception(std::string_view msg, - std::exception_ptr reason = std::current_exception(), - std::source_location loc = std::source_location::current()) noexcept : - msg_(msg), reason_(reason), srcloc_(loc) { + Exception(std::string_view msg, std::source_location loc = std::source_location::current()) noexcept : + nested_exception(), msg_(msg), srcloc_(loc) { } virtual ~Exception() = default; - Exception(const Exception&) = delete; - Exception(Exception&&) = delete; + Exception(const Exception&) = default; + Exception(Exception&&) = default; Exception& operator=(const Exception&) = delete; Exception& operator=(Exception&&) = delete; virtual void UpdatePanic() const noexcept; const std::string& msg() const noexcept { return msg_; } - const std::exception_ptr reason() const noexcept { return reason_; } const std::source_location& srcloc() const noexcept { return srcloc_; } + std::exception_ptr reason() const noexcept { return nested_ptr(); } private: const std::string msg_; - const std::exception_ptr reason_; const std::source_location srcloc_; }; class DeserializeException : public Exception { diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index b591885..7c13d56 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -1,7 +1,7 @@ include(FetchContent) -if (KINGTAKER_STATIC) +if (NF7_STATIC) set(BUILD_SHARED_LIBS OFF) else() set(BUILD_SHARED_LIBS ON) @@ -18,7 +18,7 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(glew) -if (KINGTAKER_STATIC) +if (NF7_STATIC) add_library(glew ALIAS libglew_static) else() add_library(glew ALIAS libglew_shared) @@ -52,7 +52,7 @@ FetchContent_Declare( ) FetchContent_Populate(imgui) -add_library(imgui) +add_library(imgui STATIC) target_sources(imgui PRIVATE "${imgui_SOURCE_DIR}/imgui.cpp"