Jelajahi Sumber

lib/CGameInterface.cpp: add MinGW workaround

MinGW returns all dynamic library functions as FARPROC, which need
to be cast to actual signatures, and this casts emits
-Wcast-function-type.
So, silence it for GetProcAddress.
Konstantin 2 tahun lalu
induk
melakukan
f0cb8b63c7
2 mengubah file dengan 8 tambahan dan 0 penghapusan
  1. 1 0
      CMakeLists.txt
  2. 7 0
      lib/CGameInterface.cpp

+ 1 - 0
CMakeLists.txt

@@ -297,6 +297,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR NOT WIN32)
 	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-varargs")            # emitted in fuzzylite headers, disabled
 
 	if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
+		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-pragmas") # emitted only by ancient gcc 5.5 in MXE build, remove after upgrade
 		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas") # emitted only by ancient gcc 5.5 in MXE build, remove after upgrade
 		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable") # emitted only by ancient gcc 5.5 in MXE build, remove after upgrade
 		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-maybe-uninitialized") # emitted only by ancient gcc 5.5 in MXE build, remove after upgrade

+ 7 - 0
lib/CGameInterface.cpp

@@ -49,12 +49,19 @@ std::shared_ptr<rett> createAny(const boost::filesystem::path & libpath, const s
 	TGetNameFun getName = nullptr;
 
 #ifdef VCMI_WINDOWS
+#ifdef __MINGW32__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-function-type"
+#endif
 	HMODULE dll = LoadLibraryW(libpath.c_str());
 	if (dll)
 	{
 		getName = (TGetNameFun)GetProcAddress(dll, "GetAiName");
 		getAI = (TGetAIFun)GetProcAddress(dll, methodName.c_str());
 	}
+#ifdef __MINGW32__
+#pragma GCC diagnostic pop
+#endif
 #else // !VCMI_WINDOWS
 	void *dll = dlopen(libpath.string().c_str(), RTLD_LOCAL | RTLD_LAZY);
 	if (dll)