From f10e5e3b9918574af5122f5433b9a914894fb4dc Mon Sep 17 00:00:00 2001 From: Andrey Filipenkov Date: Thu, 13 Oct 2022 13:04:32 +0300 Subject: [PATCH] [Conan] add iOS support --- AI/Nullkiller/CMakeLists.txt | 2 +- CI/conan/ios-arm64 | 14 ++++++++++++++ CI/conan/ios-armv7 | 14 ++++++++++++++ CMakeLists.txt | 13 +++++++++---- client/CMakeLists.txt | 1 + cmake_modules/VCMIUtils.cmake | 13 +++++++++++++ cmake_modules/VCMI_lib.cmake | 2 +- conanfile.py | 33 ++++++++++++++++++++++++--------- ios/CMakeLists.txt | 1 + launcher/CMakeLists.txt | 12 ++++++++++++ launcher/main.cpp | 7 +++++++ osx/CMakeLists.txt | 7 +------ 12 files changed, 98 insertions(+), 21 deletions(-) create mode 100644 CI/conan/ios-arm64 create mode 100644 CI/conan/ios-armv7 diff --git a/AI/Nullkiller/CMakeLists.txt b/AI/Nullkiller/CMakeLists.txt index 0ccf0a281..7af251a30 100644 --- a/AI/Nullkiller/CMakeLists.txt +++ b/AI/Nullkiller/CMakeLists.txt @@ -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() diff --git a/CI/conan/ios-arm64 b/CI/conan/ios-arm64 new file mode 100644 index 000000000..f702a6302 --- /dev/null +++ b/CI/conan/ios-arm64 @@ -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 diff --git a/CI/conan/ios-armv7 b/CI/conan/ios-armv7 new file mode 100644 index 000000000..35a87253d --- /dev/null +++ b/CI/conan/ios-armv7 @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index f4fd162ba..64b32c254 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index b0a9f614a..301a21562 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -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 "$" COMMAND ${CMAKE_COMMAND} --install "${CMAKE_BINARY_DIR}" --component "${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}" --config "$" --prefix "$" diff --git a/cmake_modules/VCMIUtils.cmake b/cmake_modules/VCMIUtils.cmake index 1b1a520d1..50ace693d 100644 --- a/cmake_modules/VCMIUtils.cmake +++ b/cmake_modules/VCMIUtils.cmake @@ -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() diff --git a/cmake_modules/VCMI_lib.cmake b/cmake_modules/VCMI_lib.cmake index 9ba3074c2..1e1f60c29 100644 --- a/cmake_modules/VCMI_lib.cmake +++ b/cmake_modules/VCMI_lib.cmake @@ -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}) diff --git a/conanfile.py b/conanfile.py index 57f65d6e8..4131d73af 100644 --- a/conanfile.py +++ b/conanfile.py @@ -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() diff --git a/ios/CMakeLists.txt b/ios/CMakeLists.txt index 0f8359c1c..c4e4ded93 100644 --- a/ios/CMakeLists.txt +++ b/ios/CMakeLists.txt @@ -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}) diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 695d1524a..10f8f2b54 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -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 \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) diff --git a/launcher/main.cpp b/launcher/main.cpp index 343bc85a5..94bccc43e 100644 --- a/launcher/main.cpp +++ b/launcher/main.cpp @@ -12,6 +12,13 @@ #include +// 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; diff --git a/osx/CMakeLists.txt b/osx/CMakeLists.txt index 6fbcb041b..a4db588ba 100644 --- a/osx/CMakeLists.txt +++ b/osx/CMakeLists.txt @@ -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 -")