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

[Conan] add iOS support

This commit is contained in:
Andrey Filipenkov
2022-10-13 13:04:32 +03:00
parent 233997d18d
commit f10e5e3b99
12 changed files with 98 additions and 21 deletions

View File

@@ -138,6 +138,6 @@ vcmi_set_output_dir(Nullkiller "AI")
enable_pch(Nullkiller)
install(TARGETS Nullkiller RUNTIME DESTINATION ${AI_LIB_DIR} LIBRARY DESTINATION ${AI_LIB_DIR})
if(APPLE_IOS)
if(APPLE_IOS AND NOT USING_CONAN)
install(IMPORTED_RUNTIME_ARTIFACTS TBB::tbb LIBRARY DESTINATION ${LIB_DIR}) # CMake 3.21+
endif()

14
CI/conan/ios-arm64 Normal file
View File

@@ -0,0 +1,14 @@
[settings]
os=iOS
os.version=12.0
os.sdk=iphoneos
arch=armv8
compiler=apple-clang
compiler.version=13
compiler.libcxx=libc++
build_type=Release
[options]
[build_requires]
[env]
[conf]
tools.cmake.cmaketoolchain:generator = Ninja

14
CI/conan/ios-armv7 Normal file
View File

@@ -0,0 +1,14 @@
[settings]
os=iOS
os.version=10.0
os.sdk=iphoneos
arch=armv7
compiler=apple-clang
compiler.version=13
compiler.libcxx=libc++
build_type=Release
[options]
[build_requires]
[env]
[conf]
tools.cmake.cmaketoolchain:generator = Ninja

View File

@@ -180,9 +180,11 @@ if(APPLE_IOS)
set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_OSX_DEPLOYMENT_TARGET 12.0)
list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_PREFIX_PATH}") # required for Boost
set(CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH FALSE)
set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH FALSE)
if(NOT USING_CONAN)
list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_PREFIX_PATH}") # required for Boost
set(CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH FALSE)
set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH FALSE)
endif()
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED NO)
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED_FOR_APPS YES)
@@ -294,7 +296,7 @@ if(TARGET zlib::zlib)
endif()
set(FFMPEG_COMPONENTS avutil swscale avformat avcodec)
if(APPLE_IOS)
if(APPLE_IOS AND NOT USING_CONAN)
list(APPEND FFMPEG_COMPONENTS swresample)
endif()
find_package(ffmpeg COMPONENTS ${FFMPEG_COMPONENTS})
@@ -309,6 +311,9 @@ endif()
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
if(TARGET SDL2_image::SDL2_image)
add_library(SDL2::Image ALIAS SDL2_image::SDL2_image)
endif()
find_package(SDL2_mixer REQUIRED)
if(TARGET SDL2_mixer::SDL2_mixer)
add_library(SDL2::Mixer ALIAS SDL2_mixer::SDL2_mixer)

View File

@@ -268,6 +268,7 @@ vcmi_set_output_dir(vcmiclient "")
enable_pch(vcmiclient)
if(APPLE_IOS)
vcmi_install_conan_deps("\${CMAKE_INSTALL_PREFIX}")
add_custom_command(TARGET vcmiclient POST_BUILD
COMMAND ios/set_build_version.sh "$<TARGET_BUNDLE_CONTENT_DIR:vcmiclient>"
COMMAND ${CMAKE_COMMAND} --install "${CMAKE_BINARY_DIR}" --component "${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}" --config "$<CONFIG>" --prefix "$<TARGET_BUNDLE_CONTENT_DIR:vcmiclient>"

View File

@@ -134,3 +134,16 @@ function(install_vcpkg_imported_tgt tgt)
message("${tgt_name}: ${TGT_DLL}")
install(FILES ${TGT_DLL} DESTINATION ${BIN_DIR})
endfunction(install_vcpkg_imported_tgt)
# install dependencies from Conan, install_dir should contain \${CMAKE_INSTALL_PREFIX}
function(vcmi_install_conan_deps install_dir)
if(NOT USING_CONAN)
return()
endif()
install(CODE "
execute_process(COMMAND
conan imports \"${CMAKE_SOURCE_DIR}\" --install-folder \"${CMAKE_SOURCE_DIR}/conan-generated\" --import-folder \"${install_dir}\"
)
file(REMOVE \"${install_dir}/conan_imports_manifest.txt\")
")
endfunction()

View File

@@ -500,7 +500,7 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
if("${LIBRARY_TYPE}" STREQUAL SHARED)
install(TARGETS ${TARGET_NAME} RUNTIME DESTINATION ${LIB_DIR} LIBRARY DESTINATION ${LIB_DIR})
endif()
if(APPLE_IOS)
if(APPLE_IOS AND NOT USING_CONAN)
get_target_property(LINKED_LIBS ${TARGET_NAME} LINK_LIBRARIES)
foreach(LINKED_LIB IN LISTS LINKED_LIBS)
if(NOT TARGET ${LINKED_LIB})

View File

@@ -1,13 +1,14 @@
from conan import ConanFile
from conan.tools.apple import is_apple_os
from conan.tools.cmake import CMakeDeps
from conan.tools.cmake import CMakeDeps, CMakeToolchain
from conans import tools
import os
required_conan_version = ">=1.51.3"
class VCMI(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeToolchain"
requires = [
"boost/1.80.0",
"ffmpeg/4.4.3",
@@ -57,10 +58,8 @@ class VCMI(ConanFile):
default_options = {
# shared libs
"boost/*:shared": True,
"libpng/*:shared": True, # SDL_image and Qt depend on it
"minizip/*:shared": True,
"onetbb/*:shared": True,
"qt/*:shared": True,
# we need only the following Boost parts:
# date_time filesystem locale program_options system thread
@@ -108,7 +107,6 @@ class VCMI(ConanFile):
"sdl/*:vulkan": False,
"sdl_image/*:imageio": True,
"sdl_image/*:lbm": False,
"sdl_image/*:pnm": False,
"sdl_image/*:svg": False,
@@ -129,7 +127,6 @@ class VCMI(ConanFile):
"sdl_mixer/*:wav": False,
"qt/*:config": " ".join(_qtOptions),
"qt/*:openssl": False,
"qt/*:qttools": True,
"qt/*:with_freetype": False,
"qt/*:with_libjpeg": False,
@@ -144,6 +141,19 @@ 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"
self.options["qt"].openssl = not is_apple_os(self)
self.options["qt"].shared = self.settings.os != "iOS"
if self.settings.os == "iOS":
self.options["qt"].opengl = "es2"
self.options["sdl"].sdl2main = self.settings.os != "iOS"
if is_apple_os(self):
self.options["sdl_image"].imageio = True
# workaround: macOS deployment target isn't passed to linker when building Boost
# TODO: remove when https://github.com/conan-io/conan-center-index/pull/12468 is merged
if is_apple_os(self):
@@ -159,6 +169,7 @@ class VCMI(ConanFile):
self.options["boost"].extra_b2_flags = f"linkflags={deploymentTargetFlag}"
def requirements(self):
# TODO: will no longer be needed after merging https://github.com/conan-io/conan-center-index/pull/13399
self.requires("libpng/1.6.38", override=True) # freetype / Qt
# use Apple system libraries instead of external ones
@@ -170,13 +181,17 @@ class VCMI(ConanFile):
"zlib/1.2.12",
]
for lib in systemLibsOverrides:
self.requires(f"{lib}@kambala/apple", override=True)
self.requires(f"{lib}@vcmi/apple", override=True)
# TODO: the latest official release of LuaJIT (which is quite old) can't be built for arm Mac
if self.settings.os != "Macos" or self.settings.arch != "armv8":
# TODO: the latest official release of LuaJIT (which is quite old) can't be built for arm
if not str(self.settings.arch).startswith("arm"):
self.requires("luajit/2.0.5")
def generate(self):
tc = CMakeToolchain(self)
tc.variables["USING_CONAN"] = True
tc.generate()
deps = CMakeDeps(self)
if os.getenv("USE_CONAN_WITH_ALL_CONFIGS", "0") == "0":
deps.generate()

View File

@@ -8,3 +8,4 @@ target_link_libraries(iOS_utils PRIVATE
target_include_directories(iOS_utils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
vcmi_set_output_dir(iOS_utils "")
install(TARGETS iOS_utils RUNTIME DESTINATION ${LIB_DIR} LIBRARY DESTINATION ${LIB_DIR})

View File

@@ -119,6 +119,18 @@ enable_pch(vcmilauncher)
if(APPLE_IOS)
set(ICONS_DESTINATION ${DATA_DIR})
# workaround https://github.com/conan-io/conan-center-index/issues/13332
if(USING_CONAN)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/QIOSIntegrationPlugin.h
"#include <QtPlugin>\nQ_IMPORT_PLUGIN(QIOSIntegrationPlugin)"
)
# target_include_directories(vcmilauncher PRIVATE ${CMAKE_BINARY_DIR})
target_link_libraries(vcmilauncher
Qt${QT_VERSION_MAJOR}::QIOSIntegrationPlugin
qt::QIOSIntegrationPlugin
)
endif()
else()
set(ICONS_DESTINATION ${DATA_DIR}/launcher)

View File

@@ -12,6 +12,13 @@
#include <QApplication>
// Conan workaround https://github.com/conan-io/conan-center-index/issues/13332
#ifdef VCMI_IOS
#if __has_include("QIOSIntegrationPlugin.h")
#include "QIOSIntegrationPlugin.h"
#endif
#endif
int main(int argc, char * argv[])
{
int result;

View File

@@ -38,12 +38,7 @@ if(APPLE_MACOS)
endif()
# deploy other dylibs with conan
install(CODE "
execute_process(COMMAND
conan imports \"${CMAKE_SOURCE_DIR}\" --install-folder \"${CMAKE_SOURCE_DIR}/conan-generated\" --import-folder \"${bundleContentsDir}\"
)
file(REMOVE \"${bundleContentsDir}/conan_imports_manifest.txt\")
")
vcmi_install_conan_deps("${bundleContentsDir}")
# perform ad-hoc codesigning
set(codesignCommand "codesign --verbose=4 --force --options=runtime --timestamp=none --sign -")