From f93c9277c62da934e3cb38255c03506b9fc58871 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Sun, 22 Jan 2023 15:45:43 +0300 Subject: [PATCH 01/13] lib/filesystem: rename CreateFile to createFile In MinGW, there is a define which replaces all CreateFile to CreateFileA or CreateFileW and breaks compilation. Fix it. --- lib/filesystem/CFilesystemLoader.cpp | 2 +- lib/filesystem/FileStream.cpp | 2 +- lib/filesystem/FileStream.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/filesystem/CFilesystemLoader.cpp b/lib/filesystem/CFilesystemLoader.cpp index 36908a89d..51506d60b 100644 --- a/lib/filesystem/CFilesystemLoader.cpp +++ b/lib/filesystem/CFilesystemLoader.cpp @@ -88,7 +88,7 @@ bool CFilesystemLoader::createResource(std::string filename, bool update) if (!update) { - if (!FileStream::CreateFile(baseDirectory / filename)) + if (!FileStream::createFile(baseDirectory / filename)) return false; } fileList[resID] = filename; diff --git a/lib/filesystem/FileStream.cpp b/lib/filesystem/FileStream.cpp index a85fcc913..8dfb1f3a7 100644 --- a/lib/filesystem/FileStream.cpp +++ b/lib/filesystem/FileStream.cpp @@ -236,7 +236,7 @@ zlib_filefunc64_def* FileStream::GetMinizipFilefunc() } /*static*/ -bool FileStream::CreateFile(const boost::filesystem::path& filename) +bool FileStream::createFile(const boost::filesystem::path& filename) { FILE* f = do_open(filename.c_str(), CHAR_LITERAL("wb")); bool result = (f != nullptr); diff --git a/lib/filesystem/FileStream.h b/lib/filesystem/FileStream.h index edad65a38..52ed96f60 100644 --- a/lib/filesystem/FileStream.h +++ b/lib/filesystem/FileStream.h @@ -59,7 +59,7 @@ public: explicit FileStream(const boost::filesystem::path& p, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) : boost::iostreams::stream(p, mode) {} - static bool CreateFile(const boost::filesystem::path& filename); + static bool createFile(const boost::filesystem::path& filename); static zlib_filefunc64_def* GetMinizipFilefunc(); }; From a7bd7232cef6214cffc5c20285c0c85c12e25e6d Mon Sep 17 00:00:00 2001 From: Konstantin Date: Sun, 22 Jan 2023 15:47:05 +0300 Subject: [PATCH 02/13] CGuiHandler: fix false positive dangling pointer Making this an auto variable fixes compilation with Werror. --- client/gui/CGuiHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/gui/CGuiHandler.cpp b/client/gui/CGuiHandler.cpp index be4abb5b3..7fa6d1985 100644 --- a/client/gui/CGuiHandler.cpp +++ b/client/gui/CGuiHandler.cpp @@ -192,7 +192,7 @@ void CGuiHandler::handleEvents() while(!SDLEventsQueue.empty()) { continueEventHandling = true; - SDL_Event ev = SDLEventsQueue.front(); + auto ev = SDLEventsQueue.front(); current = &ev; SDLEventsQueue.pop(); From 3ea4e8c249b0bfa8eec8583efa16b6ecd2318c46 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Sun, 22 Jan 2023 16:09:25 +0300 Subject: [PATCH 03/13] AI/CMakeLists.txt: disable some errors for FuzzyLite It generates false positives on MinGW due to Fuzzylite errorneous assuming than Windows=MSVC. --- AI/CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/AI/CMakeLists.txt b/AI/CMakeLists.txt index 8e97d6aff..b396529d2 100644 --- a/AI/CMakeLists.txt +++ b/AI/CMakeLists.txt @@ -12,6 +12,10 @@ if(TBB_FOUND AND MSVC) install_vcpkg_imported_tgt(TBB::tbb) endif() +#FuzzyLite uses MSVC pragmas in headers, so, we need to disable -Wunknown-pragmas +if(MINGW) + add_compile_options(-Wno-unknown-pragmas) +endif() if(NOT FORCE_BUNDLED_FL) find_package(fuzzylite) @@ -27,6 +31,10 @@ if(NOT fuzzylite_FOUND) set(FL_BUILD_BINARY OFF CACHE BOOL "") set(FL_BUILD_SHARED OFF CACHE BOOL "") set(FL_BUILD_TESTS OFF CACHE BOOL "") + #It is for compiling FuzzyLite, it will not compile without it on GCC + if("x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") + add_compile_options(-Wno-error=deprecated-declarations) + endif() add_subdirectory(FuzzyLite/fuzzylite EXCLUDE_FROM_ALL) add_library(fuzzylite::fuzzylite ALIAS fl-static) target_include_directories(fl-static PUBLIC ${CMAKE_HOME_DIRECTORY}/AI/FuzzyLite/fuzzylite) From cf56f7ccce97e4996dee0437e934f8dcd1e6e650 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Mon, 23 Jan 2023 02:58:41 +0300 Subject: [PATCH 04/13] vcmi: remove unused-but-set-variables --- client/battle/BattleInterface.cpp | 3 --- client/lobby/CBonusSelection.cpp | 2 -- client/mainmenu/CMainMenu.cpp | 5 ----- lib/rmg/CMapGenOptions.cpp | 4 +--- 4 files changed, 1 insertion(+), 13 deletions(-) diff --git a/client/battle/BattleInterface.cpp b/client/battle/BattleInterface.cpp index 06e84033a..14ade3839 100644 --- a/client/battle/BattleInterface.cpp +++ b/client/battle/BattleInterface.cpp @@ -207,11 +207,8 @@ void BattleInterface::stacksAreAttacked(std::vector attackedI std::array killedBySide = {0, 0}; - int targets = 0; for(const StackAttackedInfo & attackedInfo : attackedInfos) { - ++targets; - ui8 side = attackedInfo.defender->side; killedBySide.at(side) += attackedInfo.amountKilled; } diff --git a/client/lobby/CBonusSelection.cpp b/client/lobby/CBonusSelection.cpp index f562d95ae..7c843c15a 100644 --- a/client/lobby/CBonusSelection.cpp +++ b/client/lobby/CBonusSelection.cpp @@ -119,7 +119,6 @@ CBonusSelection::CBonusSelection() void CBonusSelection::loadPositionsOfGraphics() { const JsonNode config(ResourceID("config/campaign_regions.json")); - int idx = 0; for(const JsonNode & campaign : config["campaign_regions"].Vector()) { @@ -140,7 +139,6 @@ void CBonusSelection::loadPositionsOfGraphics() campDescriptions.push_back(sc); - idx++; } } diff --git a/client/mainmenu/CMainMenu.cpp b/client/mainmenu/CMainMenu.cpp index 814015686..094760366 100644 --- a/client/mainmenu/CMainMenu.cpp +++ b/client/mainmenu/CMainMenu.cpp @@ -439,11 +439,6 @@ CMultiPlayers::CMultiPlayers(const std::string & firstPlayer, ESelectionScreen S void CMultiPlayers::onChange(std::string newText) { - size_t namesCount = 0; - - for(auto & elem : inputNames) - if(!elem->getText().empty()) - namesCount++; } void CMultiPlayers::enterSelectionScreen() diff --git a/lib/rmg/CMapGenOptions.cpp b/lib/rmg/CMapGenOptions.cpp index 098511bfe..e2c700fb6 100644 --- a/lib/rmg/CMapGenOptions.cpp +++ b/lib/rmg/CMapGenOptions.cpp @@ -322,7 +322,7 @@ void CMapGenOptions::finalize(CRandomGenerator & rand) //setWidth(50); logGlobal->trace("Player config:"); - int humanPlayers = 0, cpuOnlyPlayers = 0, AIplayers = 0; + int cpuOnlyPlayers = 0; for (auto player : players) { std::string playerType; @@ -330,7 +330,6 @@ void CMapGenOptions::finalize(CRandomGenerator & rand) { case EPlayerType::AI: playerType = "AI"; - AIplayers++; break; case EPlayerType::COMP_ONLY: playerType = "computer only"; @@ -338,7 +337,6 @@ void CMapGenOptions::finalize(CRandomGenerator & rand) break; case EPlayerType::HUMAN: playerType = "human only"; - humanPlayers++; break; default: assert(false); From f0cb8b63c72be8b94c4b4b99dbb3e84ff6805b08 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Sun, 22 Jan 2023 21:05:52 +0300 Subject: [PATCH 05/13] 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. --- CMakeLists.txt | 1 + lib/CGameInterface.cpp | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f7ee25c7..8762f8c77 100644 --- a/CMakeLists.txt +++ b/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 diff --git a/lib/CGameInterface.cpp b/lib/CGameInterface.cpp index 6c49fa0ab..10a8394b0 100644 --- a/lib/CGameInterface.cpp +++ b/lib/CGameInterface.cpp @@ -49,12 +49,19 @@ std::shared_ptr 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) From a24ec53df23113b4c2096fb526d205cc2d6df620 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Mon, 23 Jan 2023 00:53:23 +0300 Subject: [PATCH 06/13] vcmi: enable Conan builds for cross-compiling Win This patch enables usage of Conan for cross-compiling Windows builds instead of MXE. --- CI/conan/base/cross-macro.j2 | 20 ++++++++++++++++++ CI/conan/base/cross-windows | 10 +++++++++ CI/conan/mingw32-linux.jinja | 15 ++++++++++++++ CI/conan/mingw64-linux.jinja | 13 ++++++++++++ CMakeLists.txt | 39 ++++++++++++++++++++++++++++++++---- CMakePresets.json | 24 ++++++++++++++++++++++ conanfile.py | 22 ++++++++++++++++++-- 7 files changed, 137 insertions(+), 6 deletions(-) create mode 100644 CI/conan/base/cross-macro.j2 create mode 100644 CI/conan/base/cross-windows create mode 100644 CI/conan/mingw32-linux.jinja create mode 100644 CI/conan/mingw64-linux.jinja diff --git a/CI/conan/base/cross-macro.j2 b/CI/conan/base/cross-macro.j2 new file mode 100644 index 000000000..a1829b5f6 --- /dev/null +++ b/CI/conan/base/cross-macro.j2 @@ -0,0 +1,20 @@ +{% macro generate_env(target_host) -%} +CONAN_CROSS_COMPILE={{ target_host }}- +CHOST={{ target_host }} +AR={{ target_host }}-ar +AS={{ target_host }}-as +CC={{ target_host }}-gcc +CXX={{ target_host }}-g++ +RANLIB={{ target_host }}-ranlib +STRIP={{ target_host }}-strip +{%- endmacro -%} + +{% macro generate_env_win32(target_host) -%} +CONAN_SYSTEM_LIBRARY_LOCATION=/usr/lib/gcc/{{ target_host }}/10-posix/ +RC={{ target_host }}-windres +{%- endmacro -%} + +{% macro generate_conf(target_host) -%} +tools.build:compiler_executables = {"c": "{{ target_host }}-gcc", "cpp": "{{ target_host }}-g++"} +tools.build:sysroot = /usr/{{ target_host }} +{%- endmacro -%} \ No newline at end of file diff --git a/CI/conan/base/cross-windows b/CI/conan/base/cross-windows new file mode 100644 index 000000000..5c3c55115 --- /dev/null +++ b/CI/conan/base/cross-windows @@ -0,0 +1,10 @@ +[settings] +os=Windows +compiler=gcc +compiler.libcxx=libstdc++11 +compiler.version=10 +compiler.cppstd=11 +build_type=Release + +[conf] +tools.cmake.cmaketoolchain:generator = Ninja diff --git a/CI/conan/mingw32-linux.jinja b/CI/conan/mingw32-linux.jinja new file mode 100644 index 000000000..7173a0969 --- /dev/null +++ b/CI/conan/mingw32-linux.jinja @@ -0,0 +1,15 @@ +{% import 'base/cross-macro.j2' as cross -%} +include(base/cross-windows) +{% set target_host="i686-w64-mingw32" %} + +[settings] +arch=x86 + +[conf] +{{ cross.generate_conf(target_host)}} +tools.build:cflags = ["-msse2"] +tools.build:cxxflags = ["-msse2"] + +[env] +{{ cross.generate_env(target_host) }} +{{ cross.generate_env_win32(target_host) }} \ No newline at end of file diff --git a/CI/conan/mingw64-linux.jinja b/CI/conan/mingw64-linux.jinja new file mode 100644 index 000000000..4c6b59ef0 --- /dev/null +++ b/CI/conan/mingw64-linux.jinja @@ -0,0 +1,13 @@ +{% import 'base/cross-macro.j2' as cross -%} +include(base/cross-windows) +{% set target_host="x86_64-w64-mingw32" %} + +[settings] +arch=x86_64 + +[conf] +{{ cross.generate_conf(target_host)}} + +[env] +{{ cross.generate_env(target_host) }} +{{ cross.generate_env_win32(target_host) }} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 8762f8c77..ebd1e6620 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,7 +91,7 @@ if(APPLE_IOS AND COPY_CONFIG_ON_BUILD) endif() # No QT Linguist on MXE -if((MINGW) AND (${CMAKE_CROSSCOMPILING})) +if((MINGW) AND (${CMAKE_CROSSCOMPILING}) AND (NOT USING_CONAN)) set(ENABLE_TRANSLATIONS OFF) endif() @@ -329,6 +329,27 @@ if(ENABLE_LUA) add_definitions(-DSCRIPTING_ENABLED=1) endif() +if(USING_CONAN AND (MINGW AND CMAKE_HOST_UNIX)) + # Hack for workaround https://github.com/conan-io/conan-center-index/issues/15405 + # Remove once it will be fixed + execute_process(COMMAND + bash -c "grep -rl Mf ${CONAN_INSTALL_FOLDER} | xargs sed -i 's/Mf/mf/g'" + ) + # Hack for workaround ffmpeg broken linking (conan ffmpeg forgots to link to ws2_32) + # Remove once it will be fixed + execute_process(COMMAND + bash -c "grep -rl secur32 ${CONAN_INSTALL_FOLDER} | xargs sed -i 's/secur32)/secur32 ws2_32)/g'" + ) + execute_process(COMMAND + bash -c "grep -rl secur32 ${CONAN_INSTALL_FOLDER} | xargs sed -i 's/secur32 mfplat/secur32 ws2_32 mfplat/g'" + ) + # Fixup tbb for cross-compiling on Conan + # Remove once it will be fixed + execute_process(COMMAND + bash -c "grep -rl tbb12 ${CONAN_INSTALL_FOLDER} | xargs sed -i 's/tbb tbb12/tbb12/g'" + ) +endif() + ############################################ # Finding packages # ############################################ @@ -545,9 +566,19 @@ endif() if(WIN32) - file(GLOB dep_files - ${dep_files} - "${CMAKE_FIND_ROOT_PATH}/bin/*.dll") + if(USING_CONAN) + #Conan imports enabled + vcmi_install_conan_deps("\${CMAKE_INSTALL_PREFIX}") + file(GLOB dep_files + ${dep_files} + "${CMAKE_SYSROOT}/bin/*.dll" + "${CMAKE_SYSROOT}/lib/*.dll" + "${CONAN_SYSTEM_LIBRARY_LOCATION}/*.dll") + else() + file(GLOB dep_files + ${dep_files} + "${CMAKE_FIND_ROOT_PATH}/bin/*.dll") + endif() if((${CMAKE_CROSSCOMPILING}) AND (DEFINED MSYS)) message(STATUS "Detected MXE build") diff --git a/CMakePresets.json b/CMakePresets.json index d31671bc1..2abf86650 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -81,6 +81,19 @@ "FORCE_BUNDLED_MINIZIP": "ON" } }, + { + "name": "windows-mingw-conan-linux", + "displayName": "Ninja+Conan release", + "description": "VCMI Windows Ninja using Conan on Linux", + "inherits": [ + "build-with-conan", + "default-release" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "FORCE_BUNDLED_FL": "ON" + } + }, { "name": "macos-ninja-release", "displayName": "Ninja release", @@ -222,6 +235,12 @@ "configurePreset": "windows-msvc-release", "inherits": "default-release" }, + { + "name": "windows-mingw-conan-linux", + "configurePreset": "windows-mingw-conan-linux", + "inherits": "default-release", + "configuration": "Release" + }, { "name": "ios-release-conan", "configurePreset": "ios-release-conan", @@ -271,6 +290,11 @@ "name": "windows-msvc-release", "configurePreset": "windows-msvc-release", "inherits": "default-release" + }, + { + "name": "windows-mingw-conan-linux", + "configurePreset": "windows-mingw-conan-linux", + "inherits": "default-release" } ] } diff --git a/conanfile.py b/conanfile.py index a3030c689..174170eae 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,6 +1,7 @@ from conan import ConanFile from conan.errors import ConanInvalidConfiguration from conan.tools.apple import is_apple_os +from conan.tools.build import cross_building from conan.tools.cmake import CMakeDeps, CMakeToolchain from conans import tools @@ -37,7 +38,9 @@ class VCMI(ConanFile): def configure(self): # SDL_image and Qt depend on it, in iOS both are static - self.options["libpng"].shared = self.settings.os != "iOS" + # Enable static libpng due to https://github.com/conan-io/conan-center-index/issues/15440, + # which leads to VCMI crashes of MinGW + self.options["libpng"].shared = is_apple_os(self) and self.settings.os != "iOS" # static Qt for iOS is the only viable option at the moment self.options["qt"].shared = self.settings.os != "iOS" @@ -157,6 +160,11 @@ class VCMI(ConanFile): self.options["qt"].openssl = not is_apple_os(self) if self.settings.os == "iOS": self.options["qt"].opengl = "es2" + if not is_apple_os(self) and cross_building(self): + self.options["qt"].cross_compile = self.env["CONAN_CROSS_COMPILE"] + # No Qt OpenGL for cross-compiling for Windows, Conan does not support it + if self.settings.os == "Windows" and cross_building(self): + self.options["qt"].opengl = "no" # transitive deps # doesn't link to overridden bzip2 & zlib, the tool isn't needed anyway @@ -184,6 +192,9 @@ class VCMI(ConanFile): ] for lib in systemLibsOverrides: self.requires(f"{lib}@vcmi/apple", override=True) + else: + self.requires("zlib/[~1.2.13]", override=True) # minizip / Qt + self.requires("libiconv/[~1.17]", override=True) # ffmpeg / sdl # TODO: the latest official release of LuaJIT (which is quite old) can't be built for arm if self.options.with_luajit and not str(self.settings.arch).startswith("arm"): @@ -193,6 +204,8 @@ class VCMI(ConanFile): tc = CMakeToolchain(self) tc.variables["USING_CONAN"] = True tc.variables["CONAN_INSTALL_FOLDER"] = self.install_folder + if cross_building(self) and self.settings.os == "Windows": + tc.variables["CONAN_SYSTEM_LIBRARY_LOCATION"] = self.env["CONAN_SYSTEM_LIBRARY_LOCATION"] tc.generate() deps = CMakeDeps(self) @@ -214,4 +227,9 @@ class VCMI(ConanFile): deps.generate() def imports(self): - self.copy("*.dylib", "Frameworks", "lib") + if is_apple_os(self): + self.copy("*.dylib", "Frameworks", "lib") + elif self.settings.os == "Windows": + self.copy("*.dll", src="bin/archdatadir/plugins/platforms", dst="platforms") + self.copy("*.dll", src="bin/archdatadir/plugins/styles", dst="styles") + self.copy("*.dll", src="@bindirs", dst="", excludes="archdatadir/*") From 57b93e00cab72cbde7beabf1bff2636bd5fa2795 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Mon, 23 Jan 2023 00:54:25 +0300 Subject: [PATCH 07/13] github/workflows: add conan-win32 workflow This will not work for now, but added for future proof --- .github/workflows/github.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index d09d54734..71af551bf 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -113,6 +113,15 @@ jobs: pack: 1 extension: exe preset: windows-msvc-release + - platform: mingw-ubuntu + os: ubuntu-22.04 + test: 0 + pack: 1 + extension: exe + cpack_args: -D CPACK_NSIS_EXECUTABLE=`which makensis` + cmake_args: -G Ninja + preset: windows-mingw-conan-linux + conan_profile: mingw32-linux.jinja runs-on: ${{ matrix.os }} defaults: run: From bd0c7c2b54878ca354b0cd7cdf7749c2015522be Mon Sep 17 00:00:00 2001 From: Konstantin Date: Mon, 23 Jan 2023 16:28:06 +0300 Subject: [PATCH 08/13] vcmi: add before_install.sh For now, it uses pregenerated deps from my repository, but should be transitioned to vcmi one after PR is finished --- CI/mingw-ubuntu/before_install.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 CI/mingw-ubuntu/before_install.sh diff --git a/CI/mingw-ubuntu/before_install.sh b/CI/mingw-ubuntu/before_install.sh new file mode 100755 index 000000000..6a18ba315 --- /dev/null +++ b/CI/mingw-ubuntu/before_install.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +sudo apt-get update +sudo apt-get install ninja-build mingw-w64 nsis +sudo update-alternatives --set i686-w64-mingw32-g++ /usr/bin/i686-w64-mingw32-g++-posix + +# Workaround for getting new MinGW headers on Ubuntu 22.04. +# Remove it once MinGW headers version in repository will be 10.0 at least +curl -O -L http://mirrors.kernel.org/ubuntu/pool/universe/m/mingw-w64/mingw-w64-common_10.0.0-2_all.deb \ + && sudo dpkg -i mingw-w64-common_10.0.0-2_all.deb; +curl -O -L http://mirrors.kernel.org/ubuntu/pool/universe/m/mingw-w64/mingw-w64-i686-dev_10.0.0-2_all.deb \ + && sudo dpkg -i mingw-w64-i686-dev_10.0.0-2_all.deb; + +mkdir ~/.conan ; cd ~/.conan +curl -L "https://github.com/rilian-la-te/vcmi-deps-windows-conan/releases/download/0.0.1/vcmi-deps-windows-conan.tgz" \ + | tar -xzf - From d62d5a83ab980b3ca04dddd322bd7b21c2e057ed Mon Sep 17 00:00:00 2001 From: Konstantin Date: Wed, 25 Jan 2023 18:08:40 +0300 Subject: [PATCH 09/13] CMakeLists.txt: fix compilation with latest TBB on 22.04 It has a config file only for None build type. Map this as fallback for all build types. --- CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ebd1e6620..1fff62f4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,12 +168,12 @@ set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) #Global fallback mapping -# RelWithDebInfo falls back to Release, then MinSizeRel -set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO RelWithDebInfo Release MinSizeRel "") -# MinSizeRel falls back to Release, then RelWithDebInfo -set(CMAKE_MAP_IMPORTED_CONFIG_MINSIZEREL MinSizeRel Release RelWithDebInfo "") -# Release falls back to RelWithDebInfo, then MinSizeRel -set(CMAKE_MAP_IMPORTED_CONFIG_RELEASE Release RelWithDebInfo MinSizeRel "") +# RelWithDebInfo falls back to Release, then MinSizeRel, and then to None (tbb in 22.04 requires it) +set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO RelWithDebInfo Release MinSizeRel None "") +# MinSizeRel falls back to Release, then RelWithDebInfo, and then to None (tbb in 22.04 requires it) +set(CMAKE_MAP_IMPORTED_CONFIG_MINSIZEREL MinSizeRel Release RelWithDebInfo None "") +# Release falls back to RelWithDebInfo, then MinSizeRel, and then to None (tbb in 22.04 requires it) +set(CMAKE_MAP_IMPORTED_CONFIG_RELEASE Release RelWithDebInfo MinSizeRel None "") set(CMAKE_XCODE_ATTRIBUTE_APP_DISPLAY_NAME ${APP_DISPLAY_NAME}) set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES) From 30784477e02fc19f47c52c4aa0519724c27e6356 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Wed, 25 Jan 2023 18:09:36 +0300 Subject: [PATCH 10/13] CMakeLists.txt: strip on package if no debuginfo is requested It significantly reduces size of the executable --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fff62f4d..471a4696b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -659,6 +659,12 @@ if(WIN32) endif() set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS " Delete \\\"$DESKTOP\\\\VCMI.lnk\\\" ") + # Strip MinGW CPack target if build configuration without debug info + if(MINGW) + if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug") OR (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")) + set(CPACK_STRIP_FILES ON) + endif() + endif() # set the install/unistall icon used for the installer itself # There is a bug in NSI that does not handle full unix paths properly. set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/client\\\\vcmi.ico") From 38ebb62c3e030b1a6081b371a241bc01211951da Mon Sep 17 00:00:00 2001 From: Konstantin Date: Wed, 25 Jan 2023 19:44:57 +0300 Subject: [PATCH 11/13] conan: build for 64-bit windows by default This was strongly suggested by VCMI developers. --- .github/workflows/github.yml | 2 +- CI/mingw-ubuntu/before_install.sh | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 71af551bf..e2b285e6f 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -121,7 +121,7 @@ jobs: cpack_args: -D CPACK_NSIS_EXECUTABLE=`which makensis` cmake_args: -G Ninja preset: windows-mingw-conan-linux - conan_profile: mingw32-linux.jinja + conan_profile: mingw64-linux.jinja runs-on: ${{ matrix.os }} defaults: run: diff --git a/CI/mingw-ubuntu/before_install.sh b/CI/mingw-ubuntu/before_install.sh index 6a18ba315..75e8d47a8 100755 --- a/CI/mingw-ubuntu/before_install.sh +++ b/CI/mingw-ubuntu/before_install.sh @@ -2,15 +2,15 @@ sudo apt-get update sudo apt-get install ninja-build mingw-w64 nsis -sudo update-alternatives --set i686-w64-mingw32-g++ /usr/bin/i686-w64-mingw32-g++-posix +sudo update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix # Workaround for getting new MinGW headers on Ubuntu 22.04. # Remove it once MinGW headers version in repository will be 10.0 at least curl -O -L http://mirrors.kernel.org/ubuntu/pool/universe/m/mingw-w64/mingw-w64-common_10.0.0-2_all.deb \ && sudo dpkg -i mingw-w64-common_10.0.0-2_all.deb; -curl -O -L http://mirrors.kernel.org/ubuntu/pool/universe/m/mingw-w64/mingw-w64-i686-dev_10.0.0-2_all.deb \ - && sudo dpkg -i mingw-w64-i686-dev_10.0.0-2_all.deb; +curl -O -L http://mirrors.kernel.org/ubuntu/pool/universe/m/mingw-w64/mingw-w64-x86-64-dev_10.0.0-2_all.deb \ + && sudo dpkg -i mingw-w64-x86-64-dev_10.0.0-2_all.deb; mkdir ~/.conan ; cd ~/.conan -curl -L "https://github.com/rilian-la-te/vcmi-deps-windows-conan/releases/download/0.0.1/vcmi-deps-windows-conan.tgz" \ +curl -L "https://github.com/vcmi/vcmi-deps-windows-conan/releases/download/1.0/vcmi-deps-windows-conan-w64.tgz" \ | tar -xzf - From f31ec77e1c6eabd10b81ebad54a62f4c9c36f2be Mon Sep 17 00:00:00 2001 From: Konstantin Date: Thu, 26 Jan 2023 12:41:14 +0300 Subject: [PATCH 12/13] docs/conan.md: add Windows instructions Add instructions for building a Windows binaries from Linux in Conan --- docs/conan.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/docs/conan.md b/docs/conan.md index 6e0a2e834..165b20b1c 100644 --- a/docs/conan.md +++ b/docs/conan.md @@ -8,6 +8,7 @@ The following platforms are supported and known to work, others might require ch - **macOS**: x86_64 (Intel) - target 10.13 (High Sierra), arm64 (Apple Silicon) - target 11.0 (Big Sur) - **iOS**: arm64 - target 12.0 +- **Windows**: x86_64 and x86 fully supported with building from Linux ## Getting started @@ -22,11 +23,14 @@ The following platforms are supported and known to work, others might require ch - macOS: libraries are built with Apple clang 14 (Xcode 14.2), should be consumable by Xcode and Xcode CLT 14.x (older library versions are also available for Xcode 13, see Releases in the respective repo) - iOS: libraries are built with Apple clang 14 (Xcode 14.2), should be consumable by Xcode 14.x (older library versions are also available for Xcode 13, see Releases in the respective repo) + - Windows: libraries are built with x86_64-mingw-w64-gcc version 10 (which is available in repositories of Ubuntu 22.04) 2. Download the binaries archive and unpack it to `~/.conan` directory: - [macOS](https://github.com/vcmi/vcmi-deps-macos/releases/latest): pick **intel.txz** if you have Intel Mac, otherwise - **intel-cross-arm.txz** - [iOS](https://github.com/vcmi/vcmi-ios-deps/releases/latest) + - [Windows] (https://github.com/vcmi/vcmi-deps-windows-conan/releases/latest): pick **vcmi-deps-windows-conan-w64.tgz** + if you want x86, otherwise pick **vcmi-deps-windows-conan.tgz** 3. Only if you have Apple Silicon Mac and trying to build for macOS or iOS: follow [instructions how to build Qt host tools for Apple Silicon](https://github.com/vcmi/vcmi-ios-deps#note-for-arm-macs), on step 3 copy them to `~/.conan/data/qt/5.15.x/_/_/package/SOME_HASH/bin` (`5.15.x` and `SOME_HASH` are placeholders). @@ -50,6 +54,7 @@ The highlighted parts can be adjusted: - ***conan-generated***: directory (absolute or relative) where the generated files will appear. This value is used in CMake presets from VCMI, but you can actually use any directory and override it in your local CMake presets. - ***never***: use this value to avoid building any dependency from source. You can also use `missing` to build recipes, that are not present in your local cache, from source. - ***CI/conan/PROFILE***: if you want to consume our prebuilt binaries, ***PROFILE*** must be replaced with one of filenames from our [Conan profiles directory](../CI/conan) (determining the right file should be straight-forward). Otherwise, either select one of our profiles or replace ***CI/conan/PROFILE*** with `default` (your default profile). +- ***note for Windows x86***: use profile mingw32-linux.jinja for building instead of mingw64-linux.jinja If you use `--build=never` and this command fails, then it means that you can't use prebuilt binaries out of the box. For example, try using `--build=missing` instead. @@ -147,3 +152,29 @@ cmake --preset ios-conan ] } ``` + +### Build VCMI with all deps for 32-bit windows in Ubuntu 22.04 WSL +```powershell +wsl --install +wsl --install -d Ubuntu +ubuntu +``` +Next steps are identical both in WSL and in real Ubuntu 22.04 +```bash +sudo pip3 install conan +sudo apt install cmake build-essential +sed -i 's/x86_64-w64-mingw32/i686-w64-mingw32/g' CI/mingw-ubuntu/before-install.sh +sed -i 's/x86-64/i686/g' CI/mingw-ubuntu/before-install.sh +sudo ./CI/mingw-ubuntu/before-install.sh +conan install . \ + --install-folder=conan-generated \ + --no-imports \ + --build=missing \ + --profile:build=default \ + --profile:host=CI/conan/mingw32-linux \ + -c tools.cmake.cmaketoolchain.presets:max_schema_version=2 +cmake --preset windows-mingw-conan-linux +cmake --build --preset windows-mingw-conan-linux --target package +``` +After that, you will have functional VCMI installer for 32-bit windows. + From 2aaaa5a05a1e7e6a423b37f65af4157db529014d Mon Sep 17 00:00:00 2001 From: Konstantin Date: Thu, 26 Jan 2023 18:29:38 +0300 Subject: [PATCH 13/13] CMakeLists.txt: check CMAKE_SYSTEM_PROCESSOR Check CMAKE_SYSTEM_PROCESSOR when generating NSIS package. This allows us correctly determine install dir on Windows --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 471a4696b..5a4ce5d68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -649,7 +649,11 @@ if(WIN32) else() set(CPACK_NSIS_PACKAGE_NAME "VCMI ${CPACK_PACKAGE_VERSION} ${PACKAGE_NAME_SUFFIX} ") endif() - set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES") + if(CMAKE_SYSTEM_PROCESSOR MATCHES ".*64") + set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64") + else() + set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES") + endif() if(ENABLE_LAUNCHER) set(CPACK_PACKAGE_EXECUTABLES "VCMI_launcher;VCMI") set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS " CreateShortCut \\\"$DESKTOP\\\\VCMI.lnk\\\" \\\"$INSTDIR\\\\VCMI_launcher.exe\\\"")