From 8ef1c6e30a88de2bf6dae2f332d87945d490d0d9 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Tue, 27 Aug 2024 20:48:27 +0800 Subject: [PATCH] fix: fix linux build issue --- BMap/BMap.cpp | 2 ++ CMakeLists.txt | 2 +- LibCmo/CK2/CKGlobals.hpp | 2 +- LibCmo/CMakeLists.txt | 9 +++++---- LibCmo/VTEncoding.cpp | 17 +++++++++-------- LibCmo/VTUtils.hpp | 6 +++--- Unvirt/CmdHelper.hpp | 2 +- Unvirt/UnvirtContext.cpp | 2 +- 8 files changed, 23 insertions(+), 19 deletions(-) diff --git a/BMap/BMap.cpp b/BMap/BMap.cpp index 57764b1..c5a2926 100644 --- a/BMap/BMap.cpp +++ b/BMap/BMap.cpp @@ -306,6 +306,8 @@ namespace BMap { case LibCmo::CK2::CK_CLASSID::CKCID_TEXTURE: m_ObjTextures.emplace_back(fileobj.CreatedObjectId); break; + default: + break; // skip unknow objects } } diff --git a/CMakeLists.txt b/CMakeLists.txt index a6fa877..88e30e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,7 +63,7 @@ write_basic_package_version_file( COMPATIBILITY SameMinorVersion ) configure_package_config_file( - ${CMAKE_CURRENT_LIST_DIR}/cmake/LibCmoConfig.cmake.in + ${CMAKE_CURRENT_LIST_DIR}/CMake/LibCmoConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/LibCmoConfig.cmake" INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/LibCmo ) diff --git a/LibCmo/CK2/CKGlobals.hpp b/LibCmo/CK2/CKGlobals.hpp index a9df972..82f92c2 100644 --- a/LibCmo/CK2/CKGlobals.hpp +++ b/LibCmo/CK2/CKGlobals.hpp @@ -230,7 +230,7 @@ namespace LibCmo::CK2 { * @return True if it need to be notified, otherwise false. * If the class id of checking is invalid, this function always return false. */ - bool CKIsNeedNotify(CK_CLASSID listener, CK_CLASSID deletedObjCid); /** + bool CKIsNeedNotify(CK_CLASSID listener, CK_CLASSID deletedObjCid); /** * @brief Get all class ids need to be notified when objects whose class id included in \c delObjCids are deleting. * @param[in] delObjCids The bit array representing class ids which need to be queried. diff --git a/LibCmo/CMakeLists.txt b/LibCmo/CMakeLists.txt index a078e56..d3a450e 100644 --- a/LibCmo/CMakeLists.txt +++ b/LibCmo/CMakeLists.txt @@ -81,7 +81,7 @@ FILES # X Container XContainer/XTypes.hpp ) -# Setup include infomation +# Setup include and linked library infomation target_include_directories(LibCmo PUBLIC "$" @@ -90,16 +90,17 @@ PRIVATE YYCC::YYCCommonplace ZLIB::ZLIB stb::stb-image - $<$>:Iconv::Iconv> ) -# Setup linked library infomation target_link_libraries(LibCmo PRIVATE YYCC::YYCCommonplace ZLIB::ZLIB stb::stb-image - $<$>:Iconv::Iconv> ) +if (NOT WIN32) + target_include_directories(LibCmo PRIVATE Iconv::Iconv) + target_link_libraries(LibCmo PRIVATE Iconv::Iconv) +endif () # Setup C++ standard set_target_properties(LibCmo PROPERTIES diff --git a/LibCmo/VTEncoding.cpp b/LibCmo/VTEncoding.cpp index 924b296..3da1061 100644 --- a/LibCmo/VTEncoding.cpp +++ b/LibCmo/VTEncoding.cpp @@ -415,20 +415,21 @@ namespace LibCmo::EncodingHelper { static const iconv_t c_InvalidIconvType = reinterpret_cast(-1); struct IconvEncodingToken { - IconvEncodingToken(const std::u8string_view& universal_code, const std::string_view& iconv_code) : + IconvEncodingToken(const std::u8string_view& universal_code, const std::string_view& _iconv_code) : m_Name(universal_code), m_FromUTF8(c_InvalidIconvType), m_ToUTF8(c_InvalidIconvType) { // if iconv code is empty, do nothing + std::string iconv_code(_iconv_code); if (iconv_code.empty()) return; // setup iconv_t - this->m_FromUTF8 = iconv_open(code.c_str(), "UTF-8"); - this->m_ToUTF8 = iconv_open("UTF-8", code.c_str()); + this->m_FromUTF8 = iconv_open(iconv_code.c_str(), "UTF-8"); + this->m_ToUTF8 = iconv_open("UTF-8", iconv_code.c_str()); } ~IconvEncodingToken() { if (this->m_FromUTF8 != c_InvalidIconvType) - iconv_close(token_cast->m_FromUTF8); + iconv_close(this->m_FromUTF8); if (this->m_ToUTF8 != c_InvalidIconvType) - iconv_close(token_cast->m_ToUTF8); + iconv_close(this->m_ToUTF8); } std::u8string m_Name; @@ -526,7 +527,7 @@ namespace LibCmo::EncodingHelper { // check whether token has been initialized correctly if (token->m_FromUTF8 == c_InvalidIconvType || token->m_ToUTF8 == c_InvalidIconvType) { // failed. free resource and return - delete token_cast; + delete token; return INVALID_ENCODING_TOKEN; } // okey, return @@ -588,7 +589,7 @@ namespace LibCmo::EncodingHelper { return YYCC::EncodingHelper::UTF8ToChar(src, dst, token_cast->m_CodePage); #else IconvEncodingToken* token_cast = static_cast(token); - return DoIconv(token_cast->FromUTF8, YYCC::EncodingHelper::ToOrdinaryView(src), dst); + return DoIconv(token_cast->m_FromUTF8, YYCC::EncodingHelper::ToOrdinaryView(src), dst); #endif } bool ToOrdinary(const char8_t* src, std::string& dst, EncodingToken token) { @@ -616,7 +617,7 @@ namespace LibCmo::EncodingHelper { #else IconvEncodingToken* token_cast = static_cast(token); std::string dst_cache; - bool ret = DoIconv(token_cast->ToUTF8, src, dst_cache); + bool ret = DoIconv(token_cast->m_ToUTF8, src, dst_cache); if (ret) dst = YYCC::EncodingHelper::ToUTF8(dst_cache); return ret; #endif diff --git a/LibCmo/VTUtils.hpp b/LibCmo/VTUtils.hpp index 37f53c5..f8cef0b 100644 --- a/LibCmo/VTUtils.hpp +++ b/LibCmo/VTUtils.hpp @@ -31,7 +31,7 @@ namespace LibCmo { UnreachableException(const char* msg) : message(msg ? msg : "") {} UnreachableException(const UnreachableException& rhs) : message(rhs.message) {} virtual ~UnreachableException() {} - [[nodiscard]] virtual const char* what() const override { return message.c_str(); } + [[nodiscard]] virtual const char* what() const noexcept override { return message.c_str(); } private: std::string message; }; @@ -47,7 +47,7 @@ namespace LibCmo { LogicException(const char* msg) : message(msg ? msg : "") {} LogicException(const LogicException& rhs) : message(rhs.message) {} virtual ~LogicException() {} - [[nodiscard]] virtual const char* what() const override { return message.c_str(); } + [[nodiscard]] virtual const char* what() const noexcept override { return message.c_str(); } private: std::string message; }; @@ -62,7 +62,7 @@ namespace LibCmo { RuntimeException(const char* msg) : message(msg ? msg : "") {} RuntimeException(const RuntimeException& rhs) : message(rhs.message) {} virtual ~RuntimeException() {} - [[nodiscard]] virtual const char* what() const override { return message.c_str(); } + [[nodiscard]] virtual const char* what() const noexcept override { return message.c_str(); } private: std::string message; }; diff --git a/Unvirt/CmdHelper.hpp b/Unvirt/CmdHelper.hpp index f68845a..356b766 100644 --- a/Unvirt/CmdHelper.hpp +++ b/Unvirt/CmdHelper.hpp @@ -389,7 +389,7 @@ namespace Unvirt::CmdHelper { }; class RootNode : public AbstractNode { - friend class CommandParser; + friend class ::Unvirt::CmdHelper::CommandParser; public: RootNode(); virtual ~RootNode(); diff --git a/Unvirt/UnvirtContext.cpp b/Unvirt/UnvirtContext.cpp index f42edd1..f143636 100644 --- a/Unvirt/UnvirtContext.cpp +++ b/Unvirt/UnvirtContext.cpp @@ -281,7 +281,7 @@ namespace Unvirt::Context { YYCC::ConsoleHelper::EnableColorfulConsole(); // Show banner - YYCC::ConsoleHelper::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"Unvirt 0.2.0") " build at " __DATE__ " " __TIME__); + YYCC::ConsoleHelper::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"Unvirt 0.2.0") " built at " __DATE__ " " __TIME__); YYCC::ConsoleHelper::WriteLine(u8"Type 'help' for more infomation. Type 'exit' to quit."); // start process loop