1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Merge pull request #1498 from rilian-la-te/conan-v2

Conan as MXE replacement
This commit is contained in:
Ivan Savenko
2023-01-27 23:14:37 +02:00
committed by GitHub
20 changed files with 231 additions and 30 deletions

View File

@@ -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: mingw64-linux.jinja
runs-on: ${{ matrix.os }}
defaults:
run:

View File

@@ -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)

View File

@@ -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 -%}

View File

@@ -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

View File

@@ -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) }}

View File

@@ -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) }}

View File

@@ -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 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-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/vcmi/vcmi-deps-windows-conan/releases/download/1.0/vcmi-deps-windows-conan-w64.tgz" \
| tar -xzf -

View File

@@ -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()
@@ -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)
@@ -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
@@ -328,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 #
############################################
@@ -544,9 +566,19 @@ endif()
if(WIN32)
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")
@@ -617,7 +649,11 @@ if(WIN32)
else()
set(CPACK_NSIS_PACKAGE_NAME "VCMI ${CPACK_PACKAGE_VERSION} ${PACKAGE_NAME_SUFFIX} ")
endif()
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\\\"")
@@ -627,6 +663,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")

View File

@@ -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"
}
]
}

View File

@@ -207,11 +207,8 @@ void BattleInterface::stacksAreAttacked(std::vector<StackAttackedInfo> attackedI
std::array<int, 2> killedBySide = {0, 0};
int targets = 0;
for(const StackAttackedInfo & attackedInfo : attackedInfos)
{
++targets;
ui8 side = attackedInfo.defender->side;
killedBySide.at(side) += attackedInfo.amountKilled;
}

View File

@@ -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();

View File

@@ -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++;
}
}

View File

@@ -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()

View File

@@ -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):
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/*")

View File

@@ -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.

View File

@@ -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)

View File

@@ -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;

View File

@@ -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);

View File

@@ -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<FileBuf>(p, mode) {}
static bool CreateFile(const boost::filesystem::path& filename);
static bool createFile(const boost::filesystem::path& filename);
static zlib_filefunc64_def* GetMinizipFilefunc();
};

View File

@@ -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);