CMakeLists.txt 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  1. # Minimum required version greatly affect CMake behavior
  2. # So cmake_minimum_required must be called before the project()
  3. # 3.16.0 is used since it's used by our currently oldest suppored system: Ubuntu-20.04
  4. cmake_minimum_required(VERSION 3.16.0)
  5. project(VCMI)
  6. # TODO
  7. # macOS:
  8. # - There is problem with running fixup_bundle in main project after subdirectories.
  9. # Cmake put them after all install code of main CMakelists in cmake_install.cmake
  10. # Currently I just added extra add_subdirectory and CMakeLists.txt in osx directory to bypass that.
  11. #
  12. # Vckpg:
  13. # - Improve install code once there is better way to deploy DLLs and Qt plugins
  14. #
  15. # Other:
  16. # - Cleanup remove_directory copy_directory if performance will be a problem.
  17. # We can use some macro over copy_if_different since it's only work for single file.
  18. # - Find a way to move add_custom_command for assets deploy out of "lib/CMakeLists.txt"
  19. # - Consider to remove M_DATA_DIR, DM_BIN_DIR, DM_LIB_DIR and not use them in code as well
  20. # - Try to get rid of FOLDER override with define_property
  21. # It's used currently to make sure that 3rd-party dependencies in git submodules get proper FOLDER property
  22. # - Make FindFuzzyLite check for the right version and disable FORCE_BUNDLED_FL by default
  23. if(APPLE)
  24. if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
  25. set(APPLE_MACOS 1)
  26. else()
  27. set(APPLE_IOS 1)
  28. endif()
  29. endif()
  30. ############################################
  31. # User-provided options #
  32. ############################################
  33. if(NOT CMAKE_BUILD_TYPE)
  34. set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
  35. "Choose the type of build, options are: Debug Release RelWithDebInfo. Default is RelWithDebInfo."
  36. FORCE)
  37. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo)
  38. endif()
  39. set(singleProcess OFF)
  40. set(staticAI OFF)
  41. if(ANDROID)
  42. set(staticAI ON)
  43. set(singleProcess ON)
  44. endif()
  45. option(ENABLE_ERM "Enable compilation of ERM scripting module" OFF)
  46. option(ENABLE_LUA "Enable compilation of LUA scripting module" OFF)
  47. if(NOT ANDROID)
  48. option(ENABLE_LAUNCHER "Enable compilation of launcher" ON)
  49. option(ENABLE_EDITOR "Enable compilation of map editor" ON)
  50. endif()
  51. option(ENABLE_TRANSLATIONS "Enable generation of translations for launcher and editor" ON)
  52. option(ENABLE_NULLKILLER_AI "Enable compilation of Nullkiller AI library" ON)
  53. if(APPLE_IOS)
  54. set(BUNDLE_IDENTIFIER_PREFIX "" CACHE STRING "Bundle identifier prefix")
  55. set(APP_DISPLAY_NAME "VCMI" CACHE STRING "App name on the home screen")
  56. set(ENABLE_SINGLE_APP_BUILD ON)
  57. else()
  58. option(ENABLE_TEST "Enable compilation of unit tests" OFF)
  59. option(ENABLE_SINGLE_APP_BUILD "Builds client and server as single executable" ${singleProcess})
  60. endif()
  61. option(ENABLE_PCH "Enable compilation using precompiled headers" ON)
  62. option(ENABLE_GITVERSION "Enable Version.cpp with Git commit hash" ON)
  63. option(ENABLE_DEBUG_CONSOLE "Enable debug console for Windows builds" ON)
  64. option(ENABLE_STRICT_COMPILATION "Treat all compiler warnings as errors" OFF)
  65. option(ENABLE_MULTI_PROCESS_BUILDS "Enable /MP flag for MSVS solution" ON)
  66. option(COPY_CONFIG_ON_BUILD "Copies config folder into output directory at building phase" ON)
  67. option(ENABLE_STATIC_AI_LIBS "Add AI code into VCMI lib directly" ${staticAI})
  68. option(ENABLE_COLORIZED_COMPILER_OUTPUT "Colorize compilation output (Clang/GNU)." ON)
  69. if(ENABLE_COLORIZED_COMPILER_OUTPUT)
  70. if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  71. add_compile_options(-fcolor-diagnostics)
  72. elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  73. add_compile_options(-fdiagnostics-color=always)
  74. endif()
  75. endif()
  76. # Used for Snap packages and also useful for debugging
  77. if(NOT APPLE_IOS AND NOT ANDROID)
  78. option(ENABLE_MONOLITHIC_INSTALL "Install everything in single directory on Linux and Mac" OFF)
  79. endif()
  80. option(ENABLE_CCACHE "Speed up recompilation by caching previous compilations" OFF)
  81. if(ENABLE_CCACHE)
  82. find_program(CCACHE ccache REQUIRED)
  83. endif()
  84. # The XCode and MSVC builds each require some more configuration further down.
  85. if(ENABLE_CCACHE)
  86. set(CMAKE_C_COMPILER_LAUNCHER "ccache")
  87. set(CMAKE_CXX_COMPILER_LAUNCHER "ccache")
  88. endif()
  89. if(ENABLE_CCACHE AND (CMAKE_GENERATOR STREQUAL "Xcode"))
  90. # https://stackoverflow.com/a/36515503/2278742
  91. # Set up wrapper scripts
  92. configure_file(xcode/launch-c.in xcode/launch-c)
  93. configure_file(xcode/launch-cxx.in xcode/launch-cxx)
  94. execute_process(COMMAND chmod a+rx
  95. "${CMAKE_BINARY_DIR}/xcode/launch-c"
  96. "${CMAKE_BINARY_DIR}/xcode/launch-cxx")
  97. # Set Xcode project attributes to route compilation through our scripts
  98. set(CMAKE_XCODE_ATTRIBUTE_CC "${CMAKE_BINARY_DIR}/xcode/launch-c")
  99. set(CMAKE_XCODE_ATTRIBUTE_CXX "${CMAKE_BINARY_DIR}/xcode/launch-cxx")
  100. set(CMAKE_XCODE_ATTRIBUTE_LD "${CMAKE_BINARY_DIR}/xcode/launch-c")
  101. set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CMAKE_BINARY_DIR}/xcode/launch-cxx")
  102. endif()
  103. # Allow to pass package name from Travis CI
  104. set(PACKAGE_NAME_SUFFIX "" CACHE STRING "Suffix for CPack package name")
  105. set(PACKAGE_FILE_NAME "" CACHE STRING "Override for CPack package filename")
  106. # ERM depends on LUA implicitly
  107. if(ENABLE_ERM AND NOT ENABLE_LUA)
  108. set(ENABLE_LUA ON)
  109. endif()
  110. # We don't want to deploy assets into build directory for android/iOS build
  111. if((APPLE_IOS OR ANDROID) AND COPY_CONFIG_ON_BUILD)
  112. set(COPY_CONFIG_ON_BUILD OFF)
  113. endif()
  114. ############################################
  115. # Miscellaneous options #
  116. ############################################
  117. set(CMAKE_MODULE_PATH ${CMAKE_HOME_DIRECTORY}/cmake_modules ${PROJECT_SOURCE_DIR}/CI)
  118. # Contains custom functions and macros, but don't altering any options
  119. include(VCMIUtils)
  120. include(VersionDefinition)
  121. if(ANDROID)
  122. set(VCMI_VERSION "${APP_SHORT_VERSION}")
  123. configure_file("android/GeneratedVersion.java.in" "${CMAKE_SOURCE_DIR}/android/vcmi-app/src/main/java/eu/vcmi/vcmi/util/GeneratedVersion.java" @ONLY)
  124. endif()
  125. vcmi_print_important_variables()
  126. # Options to enable folders in CMake generated projects for Visual Studio, Xcode, etc
  127. # Very useful to put 3rd-party libraries such as Minizip, GoogleTest and FuzzyLite in their own folders
  128. set_property(GLOBAL PROPERTY USE_FOLDERS TRUE)
  129. # Make FOLDER property inheritable
  130. # So when we set FOLDER property on AI directory all and targets inside will inherit it
  131. #
  132. # Important! This trick depend on undefined behavior since we override CMake own property.
  133. # In same time define_property documentation states it's function for custom properties.
  134. define_property(
  135. TARGET
  136. PROPERTY FOLDER
  137. INHERITED
  138. BRIEF_DOCS "Set the folder name."
  139. FULL_DOCS "Use to organize targets in an IDE."
  140. )
  141. # Generate Version.cpp
  142. if(ENABLE_GITVERSION)
  143. add_custom_target(update_version ALL
  144. BYPRODUCTS "Version.cpp"
  145. COMMAND ${CMAKE_COMMAND} -DGIT_SHA1="${GIT_SHA1}" -P "${PROJECT_SOURCE_DIR}/cmake_modules/Version.cmake"
  146. )
  147. else()
  148. add_definitions(-DVCMI_NO_EXTRA_VERSION)
  149. endif(ENABLE_GITVERSION)
  150. # Precompiled header configuration
  151. if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0 )
  152. set(ENABLE_PCH OFF) # broken
  153. endif()
  154. if(ENABLE_PCH)
  155. macro(enable_pch name)
  156. target_precompile_headers(${name} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:<StdInc.h$<ANGLE-R>>)
  157. endmacro(enable_pch)
  158. else()
  159. macro(enable_pch ignore)
  160. endmacro(enable_pch)
  161. endif()
  162. ############################################
  163. # Documentation section #
  164. ############################################
  165. include(UseDoxygen OPTIONAL)
  166. ############################################
  167. # Compile and linking options #
  168. ############################################
  169. #Enable C++17 Globally
  170. set (CMAKE_CXX_STANDARD 17)
  171. #General visibility options
  172. set(CMAKE_CXX_VISIBILITY_PRESET hidden)
  173. set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
  174. #Global fallback mapping
  175. # RelWithDebInfo falls back to Release, then MinSizeRel, and then to None (tbb in 22.04 requires it)
  176. set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO RelWithDebInfo Release MinSizeRel None "")
  177. # MinSizeRel falls back to Release, then RelWithDebInfo, and then to None (tbb in 22.04 requires it)
  178. set(CMAKE_MAP_IMPORTED_CONFIG_MINSIZEREL MinSizeRel Release RelWithDebInfo None "")
  179. # Release falls back to RelWithDebInfo, then MinSizeRel, and then to None (tbb in 22.04 requires it)
  180. set(CMAKE_MAP_IMPORTED_CONFIG_RELEASE Release RelWithDebInfo MinSizeRel None "")
  181. set(CMAKE_XCODE_ATTRIBUTE_APP_DISPLAY_NAME ${APP_DISPLAY_NAME})
  182. set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES)
  183. set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT[variant=Debug] dwarf)
  184. set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE NO)
  185. set(CMAKE_XCODE_ATTRIBUTE_ENABLE_NS_ASSERTIONS NO)
  186. set(CMAKE_XCODE_ATTRIBUTE_ENABLE_NS_ASSERTIONS[variant=Debug] YES)
  187. set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_64_TO_32_BIT_CONVERSION NO)
  188. set(CMAKE_XCODE_ATTRIBUTE_MARKETING_VERSION ${APP_SHORT_VERSION})
  189. set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH NO)
  190. set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH[variant=Debug] YES)
  191. #Check for endian
  192. if(${CMAKE_VERSION} VERSION_LESS "3.20.0")
  193. include(TestBigEndian)
  194. test_big_endian(VCMI_ENDIAN_BIG)
  195. if(VCMI_ENDIAN_BIG)
  196. add_definitions(-DVCMI_ENDIAN_BIG)
  197. endif()
  198. elseif(${CMAKE_CXX_BYTE_ORDER} EQUAL "BIG_ENDIAN")
  199. add_definitions(-DVCMI_ENDIAN_BIG)
  200. endif()
  201. if(ENABLE_LAUNCHER)
  202. add_definitions(-DENABLE_LAUNCHER)
  203. endif()
  204. if(ENABLE_EDITOR)
  205. add_definitions(-DENABLE_EDITOR)
  206. endif()
  207. if(ENABLE_SINGLE_APP_BUILD)
  208. add_definitions(-DSINGLE_PROCESS_APP=1)
  209. endif()
  210. if(APPLE_IOS)
  211. set(CMAKE_MACOSX_RPATH 1)
  212. set(CMAKE_OSX_DEPLOYMENT_TARGET 12.0)
  213. if(NOT USING_CONAN)
  214. list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_PREFIX_PATH}") # required for Boost
  215. set(CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH FALSE)
  216. set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH FALSE)
  217. endif()
  218. set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED NO)
  219. set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED_FOR_APPS YES)
  220. set(CMAKE_XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "${BUNDLE_IDENTIFIER_PREFIX}.$(PRODUCT_NAME)")
  221. set(CMAKE_XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2")
  222. endif()
  223. if(APPLE_MACOS)
  224. # Not supported by standard library of our current minimal target - macOS 10.14 or newer required
  225. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-aligned-allocation")
  226. endif()
  227. if(MINGW OR MSVC)
  228. # Windows Vista or newer for FuzzyLite 6 to compile
  229. # Except for conan which already has this definition in its preset
  230. if(NOT USING_CONAN)
  231. add_definitions(-D_WIN32_WINNT=0x0600)
  232. endif()
  233. #delete lib prefix for dlls (libvcmi -> vcmi)
  234. set(CMAKE_SHARED_LIBRARY_PREFIX "")
  235. if(MSVC)
  236. if(ENABLE_CCACHE)
  237. # https://github.com/ccache/ccache/discussions/1154#discussioncomment-3611387
  238. file(COPY_FILE
  239. ${CCACHE} ${CMAKE_BINARY_DIR}/cl.exe
  240. ONLY_IF_DIFFERENT)
  241. set(CMAKE_VS_GLOBALS
  242. "CLToolExe=cl.exe"
  243. "CLToolPath=${CMAKE_BINARY_DIR}"
  244. "TrackFileAccess=false"
  245. "UseMultiToolTask=true"
  246. )
  247. endif()
  248. add_definitions(-DBOOST_ALL_NO_LIB)
  249. add_definitions(-DBOOST_ALL_DYN_LINK)
  250. set(Boost_USE_STATIC_LIBS OFF)
  251. # Don't link with SDLMain
  252. if(ENABLE_DEBUG_CONSOLE)
  253. set(SDL2_BUILDING_LIBRARY ON)
  254. add_definitions(-DVCMI_WITH_DEBUG_CONSOLE)
  255. endif()
  256. # Suppress warnings
  257. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  258. add_definitions(-D_SCL_SECURE_NO_WARNINGS)
  259. add_definitions(-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING) # Fix gtest and gmock build
  260. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
  261. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
  262. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4250") # 4250: 'class1' : inherits 'class2::member' via dominance
  263. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251") # 4251: class 'xxx' needs to have dll-interface to be used by clients of class 'yyy'
  264. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244") # 4244: conversion from 'xxx' to 'yyy', possible loss of data
  265. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267") # 4267: conversion from 'xxx' to 'yyy', possible loss of data
  266. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4275") # 4275: non dll-interface class 'xxx' used as base for dll-interface class
  267. #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4800") # 4800: implicit conversion from 'xxx' to bool. Possible information loss
  268. if(ENABLE_STRICT_COMPILATION)
  269. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX") # Treats all compiler warnings as errors
  270. endif()
  271. if(ENABLE_MULTI_PROCESS_BUILDS)
  272. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
  273. endif()
  274. # Workaround: Visual Studio has issues with exports of classes that inherit templates
  275. # https://stackoverflow.com/questions/44960760/msvc-dll-exporting-class-that-inherits-from-template-cause-lnk2005-already-defin
  276. # Reported to Microsoft here:
  277. # https://developercommunity.visualstudio.com/content/problem/224597/linker-failing-because-of-multiple-definitions-of.html
  278. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /FORCE:MULTIPLE")
  279. # Required at least for compatibility with Boost 1.68 on Vcpkg
  280. set(SYSTEM_LIBS ${SYSTEM_LIBS} bcrypt)
  281. endif(MSVC)
  282. if(MINGW)
  283. # Temporary (?) workaround for failing builds on MinGW CI due to bug in TBB
  284. set(CMAKE_CXX_EXTENSIONS ON)
  285. set(SYSTEM_LIBS ${SYSTEM_LIBS} ole32 oleaut32 ws2_32 mswsock dbghelp bcrypt)
  286. # Check for iconv (may be needed for Boost.Locale)
  287. include(CheckLibraryExists)
  288. check_library_exists(iconv libiconv_open "" ICONV_FOUND)
  289. if(ICONV_FOUND)
  290. set(SYSTEM_LIBS ${SYSTEM_LIBS} iconv)
  291. endif()
  292. # Prevent compiler issues when building Debug
  293. # Assembler might fail with "too many sections"
  294. # With big-obj or 64-bit build will take hours
  295. if(CMAKE_BUILD_TYPE MATCHES Debug)
  296. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Og")
  297. endif()
  298. endif(MINGW)
  299. endif(MINGW OR MSVC)
  300. if(ANDROID)
  301. if(ANDROID_NDK_MAJOR LESS 23 AND ANDROID_ABI MATCHES "^armeabi")
  302. # libunwind must come before other shared libs:
  303. # https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md#Unwinding
  304. list(APPEND SYSTEM_LIBS unwind)
  305. endif()
  306. list(APPEND SYSTEM_LIBS log)
  307. endif()
  308. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR NOT WIN32)
  309. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
  310. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpointer-arith")
  311. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wuninitialized")
  312. if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0 OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
  313. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmismatched-tags")
  314. endif()
  315. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter") # low chance of valid reports, a lot of emitted warnings
  316. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch") # large number of false-positives, disabled
  317. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reorder") # large number of noise, low chance of any significant issues
  318. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-compare") # low chance of any significant issues
  319. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-varargs") # emitted in fuzzylite headers, disabled
  320. if(ENABLE_STRICT_COMPILATION)
  321. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
  322. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=array-bounds") # false positives in boost::multiarray during release build, keep as warning-only
  323. endif()
  324. # Fix string inspection with lldb
  325. # https://stackoverflow.com/questions/58578615/cannot-inspect-a-stdstring-variable-in-lldb
  326. if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  327. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fstandalone-debug")
  328. endif()
  329. if(UNIX)
  330. set(SYSTEM_LIBS ${SYSTEM_LIBS} ${CMAKE_DL_LIBS})
  331. endif()
  332. endif()
  333. # Check if some platform-specific libraries are needed for linking
  334. if(NOT WIN32 AND NOT APPLE_IOS)
  335. include(CheckLibraryExists)
  336. # Shared memory functions used by Boost.Interprocess
  337. # FindBoost handle linking with pthreads, but doesn't handle this
  338. CHECK_LIBRARY_EXISTS(rt shm_open "" HAVE_RT_LIB)
  339. if(HAVE_RT_LIB)
  340. set(SYSTEM_LIBS ${SYSTEM_LIBS} rt)
  341. endif()
  342. if(HAIKU)
  343. set(SYSTEM_LIBS ${SYSTEM_LIBS} network)
  344. endif()
  345. endif()
  346. if(ENABLE_LUA)
  347. add_definitions(-DSCRIPTING_ENABLED=1)
  348. endif()
  349. if(USING_CONAN AND (MINGW AND CMAKE_HOST_UNIX))
  350. # Hack for workaround https://github.com/conan-io/conan-center-index/issues/15405
  351. # Remove once it will be fixed
  352. execute_process(COMMAND
  353. bash -c "grep -rl Mf ${CONAN_INSTALL_FOLDER} | xargs sed -i 's/Mf/mf/g'"
  354. )
  355. # Hack for workaround ffmpeg broken linking (conan ffmpeg forgots to link to ws2_32)
  356. # Remove once it will be fixed
  357. execute_process(COMMAND
  358. bash -c "grep -rl secur32 ${CONAN_INSTALL_FOLDER} | xargs sed -i 's/secur32)/secur32 ws2_32)/g'"
  359. )
  360. execute_process(COMMAND
  361. bash -c "grep -rl secur32 ${CONAN_INSTALL_FOLDER} | xargs sed -i 's/secur32 mfplat/secur32 ws2_32 mfplat/g'"
  362. )
  363. # Fixup tbb for cross-compiling on Conan
  364. # Remove once it will be fixed
  365. execute_process(COMMAND
  366. bash -c "grep -rl tbb12 ${CONAN_INSTALL_FOLDER} | xargs sed -i 's/tbb tbb12/tbb12/g'"
  367. )
  368. endif()
  369. ############################################
  370. # Finding packages #
  371. ############################################
  372. find_package(Boost 1.48.0 REQUIRED COMPONENTS date_time filesystem locale program_options system thread)
  373. find_package(ZLIB REQUIRED)
  374. # Conan compatibility
  375. if(TARGET zlib::zlib)
  376. add_library(ZLIB::ZLIB ALIAS zlib::zlib)
  377. endif()
  378. set(FFMPEG_COMPONENTS avutil swscale avformat avcodec)
  379. if(APPLE_IOS AND NOT USING_CONAN)
  380. list(APPEND FFMPEG_COMPONENTS swresample)
  381. endif()
  382. find_package(ffmpeg COMPONENTS ${FFMPEG_COMPONENTS})
  383. option(FORCE_BUNDLED_MINIZIP "Force bundled Minizip library" OFF)
  384. if(NOT FORCE_BUNDLED_MINIZIP)
  385. find_package(minizip)
  386. if(TARGET minizip::minizip)
  387. add_definitions(-DUSE_SYSTEM_MINIZIP)
  388. endif()
  389. endif()
  390. find_package(SDL2 REQUIRED)
  391. find_package(SDL2_image REQUIRED)
  392. if(TARGET SDL2_image::SDL2_image)
  393. add_library(SDL2::Image ALIAS SDL2_image::SDL2_image)
  394. endif()
  395. find_package(SDL2_mixer REQUIRED)
  396. if(TARGET SDL2_mixer::SDL2_mixer)
  397. add_library(SDL2::Mixer ALIAS SDL2_mixer::SDL2_mixer)
  398. endif()
  399. find_package(SDL2_ttf REQUIRED)
  400. if(TARGET SDL2_ttf::SDL2_ttf)
  401. add_library(SDL2::TTF ALIAS SDL2_ttf::SDL2_ttf)
  402. endif()
  403. if(ENABLE_LAUNCHER OR ENABLE_EDITOR)
  404. # Widgets finds its own dependencies (QtGui and QtCore).
  405. find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Network)
  406. find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Network)
  407. if(ENABLE_TRANSLATIONS)
  408. find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS LinguistTools)
  409. add_definitions(-DENABLE_QT_TRANSLATIONS)
  410. endif()
  411. endif()
  412. if(ENABLE_NULLKILLER_AI)
  413. find_package(TBB REQUIRED)
  414. endif()
  415. if(ENABLE_LUA)
  416. find_package(luajit)
  417. if(TARGET luajit::luajit)
  418. message(STATUS "Using LuaJIT provided by system")
  419. else()
  420. message(STATUS "Cannot find LuaJIT! Fallback to using usual Lua.")
  421. find_package(Lua REQUIRED)
  422. if(Lua_FOUND)
  423. add_library(luajit::luajit UNKNOWN IMPORTED)
  424. set_target_properties(luajit::luajit PROPERTIES
  425. INTERFACE_INCLUDE_DIRECTORIES "${LUA_INCLUDE_DIR}")
  426. set_target_properties(luajit::luajit PROPERTIES
  427. IMPORTED_LOCATION "${LUA_LIBRARIES}")
  428. endif()
  429. endif()
  430. endif()
  431. ############################################
  432. # Output directories #
  433. ############################################
  434. if(WIN32) # on Win everything goes into H3 root directory
  435. set(BIN_DIR "." CACHE STRING "Where to install binaries")
  436. set(LIB_DIR "." CACHE STRING "Where to install main library")
  437. set(DATA_DIR "." CACHE STRING "Where to install data files")
  438. elseif(APPLE)
  439. # includes lib path which determines where to install shared libraries (either /lib or /lib64)
  440. include(GNUInstallDirs)
  441. set(CMAKE_INSTALL_RPATH "@executable_path/../Frameworks")
  442. if(ENABLE_MONOLITHIC_INSTALL)
  443. set(BIN_DIR "." CACHE STRING "Where to install binaries")
  444. set(LIB_DIR "." CACHE STRING "Where to install main library")
  445. set(DATA_DIR "." CACHE STRING "Where to install data files")
  446. else()
  447. if(APPLE_MACOS)
  448. set(APP_BUNDLE_DIR "${CMAKE_PROJECT_NAME}.app")
  449. set(APP_BUNDLE_CONTENTS_DIR "${APP_BUNDLE_DIR}/Contents")
  450. set(APP_BUNDLE_BINARY_DIR "${APP_BUNDLE_CONTENTS_DIR}/MacOS")
  451. set(APP_BUNDLE_RESOURCES_DIR "${APP_BUNDLE_CONTENTS_DIR}/Resources")
  452. set(BIN_DIR "${APP_BUNDLE_BINARY_DIR}" CACHE STRING "Where to install binaries")
  453. set(LIB_DIR "${APP_BUNDLE_CONTENTS_DIR}/Frameworks" CACHE STRING "Where to install main library")
  454. set(DATA_DIR "${APP_BUNDLE_RESOURCES_DIR}/Data" CACHE STRING "Where to install data files")
  455. else()
  456. set(LIB_DIR "Frameworks")
  457. set(DATA_DIR ".")
  458. endif()
  459. endif()
  460. elseif(ANDROID)
  461. include(GNUInstallDirs)
  462. set(LIB_DIR "jniLibs/${ANDROID_ABI}")
  463. set(DATA_DIR "assets")
  464. else()
  465. # includes lib path which determines where to install shared libraries (either /lib or /lib64)
  466. include(GNUInstallDirs)
  467. if(ENABLE_MONOLITHIC_INSTALL)
  468. set(BIN_DIR "." CACHE STRING "Where to install binaries")
  469. set(LIB_DIR "." CACHE STRING "Where to install main library")
  470. set(DATA_DIR "." CACHE STRING "Where to install data files")
  471. # following constants only used for platforms using XDG (Linux, BSD, etc)
  472. add_definitions(-DM_DATA_DIR="${DATA_DIR}")
  473. add_definitions(-DM_BIN_DIR="${BIN_DIR}")
  474. add_definitions(-DM_LIB_DIR="${LIB_DIR}")
  475. set(CMAKE_INSTALL_RPATH "$ORIGIN/")
  476. else()
  477. if(NOT BIN_DIR)
  478. set(BIN_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING "Where to install binaries")
  479. endif()
  480. if(NOT LIB_DIR)
  481. set(LIB_DIR "${CMAKE_INSTALL_LIBDIR}/vcmi" CACHE STRING "Where to install main library")
  482. endif()
  483. if(NOT DATA_DIR)
  484. set(DATA_DIR "${CMAKE_INSTALL_DATAROOTDIR}/vcmi" CACHE STRING "Where to install data files")
  485. endif()
  486. # following constants only used for platforms using XDG (Linux, BSD, etc)
  487. add_definitions(-DM_DATA_DIR="${CMAKE_INSTALL_PREFIX}/${DATA_DIR}")
  488. add_definitions(-DM_BIN_DIR="${CMAKE_INSTALL_PREFIX}/${BIN_DIR}")
  489. add_definitions(-DM_LIB_DIR="${CMAKE_INSTALL_PREFIX}/${LIB_DIR}")
  490. set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_DIR}")
  491. endif()
  492. endif()
  493. # iOS/Android have flat libs directory structure
  494. if(APPLE_IOS OR ANDROID)
  495. set(AI_LIB_DIR "${LIB_DIR}")
  496. set(SCRIPTING_LIB_DIR "${LIB_DIR}")
  497. else()
  498. set(AI_LIB_DIR "${LIB_DIR}/AI")
  499. set(SCRIPTING_LIB_DIR "${LIB_DIR}/scripting")
  500. endif()
  501. #######################################
  502. # Add subdirectories #
  503. #######################################
  504. if(APPLE_IOS)
  505. add_subdirectory(ios)
  506. endif()
  507. set(VCMI_LIB_TARGET vcmi)
  508. add_subdirectory_with_folder("AI" AI)
  509. include(VCMI_lib)
  510. add_subdirectory(lib)
  511. if(ENABLE_SINGLE_APP_BUILD)
  512. add_subdirectory(lib_server)
  513. endif()
  514. if(ENABLE_ERM)
  515. add_subdirectory(scripting/erm)
  516. endif()
  517. if(ENABLE_LUA)
  518. add_subdirectory(scripting/lua)
  519. endif()
  520. if(NOT TARGET minizip::minizip)
  521. add_subdirectory_with_folder("3rdparty" lib/minizip)
  522. add_library(minizip::minizip ALIAS minizip)
  523. endif()
  524. if(ENABLE_LAUNCHER)
  525. add_subdirectory(launcher)
  526. endif()
  527. if(ENABLE_EDITOR)
  528. add_subdirectory(mapeditor)
  529. endif()
  530. add_subdirectory(client)
  531. add_subdirectory(server)
  532. if(ENABLE_TEST)
  533. enable_testing()
  534. add_subdirectory(test)
  535. endif()
  536. #######################################
  537. # Installation section #
  538. #######################################
  539. if(ANDROID)
  540. if(ANDROID_STL MATCHES "_shared$")
  541. set(stlLibName "${CMAKE_SHARED_LIBRARY_PREFIX}${ANDROID_STL}${CMAKE_SHARED_LIBRARY_SUFFIX}")
  542. install(FILES "${CMAKE_SYSROOT}/usr/lib/${ANDROID_SYSROOT_LIB_SUBDIR}/${stlLibName}"
  543. DESTINATION ${LIB_DIR}
  544. )
  545. endif()
  546. # zip internal assets - 'config' and 'Mods' dirs, save md5 of the zip
  547. install(CODE "
  548. cmake_path(ABSOLUTE_PATH CMAKE_INSTALL_PREFIX
  549. OUTPUT_VARIABLE absolute_install_prefix
  550. )
  551. set(absolute_data_dir \"\${absolute_install_prefix}/${DATA_DIR}\")
  552. file(MAKE_DIRECTORY \"\${absolute_data_dir}\")
  553. set(internal_data_zip \"\${absolute_data_dir}/internalData.zip\")
  554. execute_process(COMMAND
  555. \"${CMAKE_COMMAND}\" -E tar c \"\${internal_data_zip}\" --format=zip -- config Mods
  556. WORKING_DIRECTORY \"${CMAKE_SOURCE_DIR}\"
  557. )
  558. file(MD5 \"\${internal_data_zip}\" internal_data_zip_md5)
  559. file(WRITE \"\${absolute_data_dir}/internalDataHash.txt\"
  560. \${internal_data_zip_md5}
  561. )
  562. ")
  563. else()
  564. install(DIRECTORY config DESTINATION ${DATA_DIR})
  565. install(DIRECTORY Mods DESTINATION ${DATA_DIR})
  566. endif()
  567. if(ENABLE_LUA)
  568. install(DIRECTORY scripts DESTINATION ${DATA_DIR})
  569. endif()
  570. # that script is useless for Windows / iOS / Android
  571. if(NOT WIN32 AND NOT APPLE_IOS AND NOT ANDROID)
  572. install(FILES vcmibuilder DESTINATION ${BIN_DIR} PERMISSIONS
  573. OWNER_WRITE OWNER_READ OWNER_EXECUTE
  574. GROUP_READ GROUP_EXECUTE
  575. WORLD_READ WORLD_EXECUTE)
  576. endif()
  577. if(WIN32)
  578. if(USING_CONAN)
  579. #Conan imports enabled
  580. vcmi_install_conan_deps("\${CMAKE_INSTALL_PREFIX}")
  581. file(GLOB dep_files
  582. ${dep_files}
  583. "${CMAKE_SYSROOT}/bin/*.dll"
  584. "${CMAKE_SYSROOT}/lib/*.dll"
  585. "${CONAN_SYSTEM_LIBRARY_LOCATION}/*.dll")
  586. else()
  587. file(GLOB dep_files
  588. ${dep_files}
  589. "${CMAKE_FIND_ROOT_PATH}/bin/*.dll")
  590. endif()
  591. if(CMAKE_BUILD_TYPE MATCHES Debug)
  592. # Copy debug versions of libraries if build type is debug
  593. set(debug_postfix d)
  594. endif()
  595. if(ENABLE_LAUNCHER OR ENABLE_EDITOR)
  596. get_target_property(QtCore_location Qt${QT_VERSION_MAJOR}::Core LOCATION)
  597. get_filename_component(Qtbin_folder ${QtCore_location} PATH)
  598. file(GLOB dep_files
  599. ${dep_files}
  600. ${Qtbin_folder}/Qt5Core${debug_postfix}.dll
  601. ${Qtbin_folder}/Qt5Gui${debug_postfix}.dll
  602. ${Qtbin_folder}/Qt5Widgets${debug_postfix}.dll
  603. ${Qtbin_folder}/Qt5Network${debug_postfix}.dll
  604. ${Qtbin_folder}/icu*.dll)
  605. get_target_property(integration_type Qt${QT_VERSION_MAJOR}::QWindowsIntegrationPlugin TYPE)
  606. if(NOT(integration_type STREQUAL "INTERFACE_LIBRARY"))
  607. get_target_property(integration_loc Qt${QT_VERSION_MAJOR}::QWindowsIntegrationPlugin LOCATION)
  608. install(
  609. FILES ${integration_loc}
  610. DESTINATION ${BIN_DIR}/platforms
  611. )
  612. install(
  613. FILES "$<TARGET_FILE:Qt${QT_VERSION_MAJOR}::QWindowsVistaStylePlugin>"
  614. DESTINATION ${BIN_DIR}/styles)
  615. endif()
  616. endif()
  617. install(FILES ${dep_files} DESTINATION ${BIN_DIR})
  618. endif(WIN32)
  619. #######################################
  620. # Packaging section #
  621. #######################################
  622. if(MSVC)
  623. SET(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION ${BIN_DIR})
  624. Include(InstallRequiredSystemLibraries)
  625. endif()
  626. set(CPACK_PACKAGE_VERSION_MAJOR ${VCMI_VERSION_MAJOR})
  627. set(CPACK_PACKAGE_VERSION_MINOR ${VCMI_VERSION_MINOR})
  628. set(CPACK_PACKAGE_VERSION_PATCH ${VCMI_VERSION_PATCH})
  629. # vcmi does not have "patch version" in version string
  630. set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
  631. #TODO: remove version from Global.h and use this one as define?
  632. set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
  633. if("${PACKAGE_NAME_SUFFIX}" STREQUAL "")
  634. set(CPACK_PACKAGE_NAME "VCMI")
  635. else()
  636. set(CPACK_PACKAGE_NAME "VCMI ${PACKAGE_NAME_SUFFIX}")
  637. endif()
  638. if("${PACKAGE_FILE_NAME}" STREQUAL "")
  639. set(CPACK_PACKAGE_FILE_NAME "vcmi-${CPACK_PACKAGE_VERSION}")
  640. else()
  641. set(CPACK_PACKAGE_FILE_NAME "${PACKAGE_FILE_NAME}")
  642. endif()
  643. set(CPACK_PACKAGE_VENDOR "VCMI team")
  644. if(WIN32)
  645. # Note: due to NSI script generation process all of the backward slashes here are useful
  646. set(CPACK_MONOLITHIC_INSTALL 1)
  647. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/license.txt")
  648. set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}")
  649. if("${PACKAGE_NAME_SUFFIX}" STREQUAL "")
  650. set(CPACK_NSIS_PACKAGE_NAME "VCMI ${CPACK_PACKAGE_VERSION}")
  651. else()
  652. set(CPACK_NSIS_PACKAGE_NAME "VCMI ${CPACK_PACKAGE_VERSION} ${PACKAGE_NAME_SUFFIX} ")
  653. endif()
  654. if(CMAKE_SYSTEM_PROCESSOR MATCHES ".*64")
  655. set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64")
  656. else()
  657. set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES")
  658. endif()
  659. if(ENABLE_LAUNCHER)
  660. set(VCMI_MAIN_EXECUTABLE "VCMI_launcher")
  661. else()
  662. set(VCMI_MAIN_EXECUTABLE "VCMI_client")
  663. endif()
  664. set(CPACK_PACKAGE_EXECUTABLES "${VCMI_MAIN_EXECUTABLE};VCMI")
  665. set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
  666. CreateShortCut \\\"$DESKTOP\\\\VCMI.lnk\\\" \\\"$INSTDIR\\\\${VCMI_MAIN_EXECUTABLE}.exe\\\"
  667. ExecShell '' 'netsh' 'advfirewall firewall add rule name=vcmi_server dir=in action=allow program=\\\"$INSTDIR\\\\vcmi_server.exe\\\" enable=yes profile=public,private' SW_HIDE
  668. ")
  669. set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "
  670. Delete \\\"$DESKTOP\\\\VCMI.lnk\\\"
  671. ExecShell '' 'netsh' 'advfirewall firewall delete rule name=vcmi_server' SW_HIDE
  672. ")
  673. # Strip MinGW CPack target if build configuration without debug info
  674. if(MINGW)
  675. if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug") OR (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
  676. set(CPACK_STRIP_FILES ON)
  677. endif()
  678. endif()
  679. # set the install/unistall icon used for the installer itself
  680. # There is a bug in NSI that does not handle full unix paths properly.
  681. set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/client\\\\vcmi.ico")
  682. set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}/client\\\\vcmi.ico")
  683. # set the package header icon for MUI
  684. set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/client\\\\vcmi.ico")
  685. set(CPACK_NSIS_MENU_LINKS "http://vcmi.eu/" "VCMI Web Site")
  686. set(CPACK_NSIS_INSTALLED_ICON_NAME "VCMI_client.exe")
  687. set(CPACK_NSIS_COMPRESSOR "/SOLID lzma")
  688. set(CPACK_NSIS_DISPLAY_NAME "${CPACK_NSIS_PACKAGE_NAME}, open-source engine for Heroes of Might and Magic III ")
  689. set(CPACK_NSIS_HELP_LINK "http://vcmi.eu/")
  690. set(CPACK_NSIS_URL_INFO_ABOUT "http://vcmi.eu/")
  691. set(CPACK_NSIS_CONTACT @CPACK_PACKAGE_CONTACT@)
  692. set(CPACK_NSIS_EXECUTABLES_DIRECTORY ".")
  693. # Use BundleUtilities to fix build when Vcpkg is used and disable it for mingw
  694. if(NOT (${CMAKE_CROSSCOMPILING}))
  695. add_subdirectory(win)
  696. endif()
  697. elseif(APPLE_MACOS AND NOT ENABLE_MONOLITHIC_INSTALL)
  698. set(CPACK_MONOLITHIC_INSTALL 1)
  699. set(CPACK_GENERATOR "DragNDrop")
  700. set(CPACK_DMG_BACKGROUND_IMAGE "${CMAKE_SOURCE_DIR}/osx/dmg_background.png")
  701. # Workaround for this issue:
  702. # CPack Error: Error executing: /usr/bin/hdiutil detach "/Volumes/VCMI"
  703. # https://github.com/actions/runner-images/issues/7522#issuecomment-1564467252
  704. set(CPACK_COMMAND_HDIUTIL "/usr/bin/sudo /usr/bin/hdiutil")
  705. # CMake code for CPACK_DMG_DS_STORE executed before DS_STORE_SETUP_SCRIPT
  706. # So we can keep both enabled and this shouldn't hurt
  707. # set(CPACK_DMG_DS_STORE "${CMAKE_SOURCE_DIR}/osx/dmg_DS_Store")
  708. set(CPACK_DMG_DS_STORE_SETUP_SCRIPT "${CMAKE_SOURCE_DIR}/osx/DS_Store_Setup.scpt")
  709. # Always use "VCMI" as volume name so full path will be /Volumes/VCMI/
  710. # Otherwise DMG background image wouldn't work
  711. # Pre-generated DS_Store use absolute path to background image
  712. set(CPACK_DMG_VOLUME_NAME "${CMAKE_PROJECT_NAME}")
  713. include(GetGitRevisionDescription)
  714. get_git_head_revision(GIT_REFSPEC GIT_SHA1)
  715. string(TIMESTAMP CURRENT_YEAR "%Y")
  716. set(MACOSX_BUNDLE_NAME "${CMAKE_PROJECT_NAME}")
  717. set(MACOSX_BUNDLE_BUNDLE_NAME "${CMAKE_PROJECT_NAME}")
  718. set(MACOSX_BUNDLE_COPYRIGHT "Copyright © 2007-${CURRENT_YEAR} VCMI team")
  719. set(MACOSX_BUNDLE_GUI_IDENTIFIER "eu.vcmi.vcmi")
  720. set(MACOSX_BUNDLE_BUNDLE_VERSION ${GIT_SHA1})
  721. set(MACOSX_BUNDLE_SHORT_VERSION_STRING ${APP_SHORT_VERSION})
  722. if(ENABLE_LAUNCHER)
  723. set(MACOSX_BUNDLE_EXECUTABLE_NAME "vcmilauncher")
  724. else()
  725. set(MACOSX_BUNDLE_EXECUTABLE_NAME "vcmiclient")
  726. endif()
  727. set(MACOSX_BUNDLE_ICON_FILE "vcmi.icns")
  728. install(FILES "${CMAKE_SOURCE_DIR}/osx/vcmi.icns" DESTINATION ${APP_BUNDLE_RESOURCES_DIR})
  729. configure_file("${CMAKE_SOURCE_DIR}/osx/Info.plist.in" "${CMAKE_BINARY_DIR}/Info.plist")
  730. install(FILES "${CMAKE_BINARY_DIR}/Info.plist" DESTINATION ${APP_BUNDLE_CONTENTS_DIR})
  731. # Bundle fixing code must be in separate directory to be executed after all other install code
  732. add_subdirectory(osx)
  733. elseif(APPLE_IOS)
  734. set(CPACK_GENERATOR ZIP)
  735. set(CPACK_ARCHIVE_FILE_EXTENSION ipa)
  736. set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
  737. set(CPACK_INSTALL_CMAKE_PROJECTS "${CMAKE_CURRENT_BINARY_DIR};${CMAKE_PROJECT_NAME};app;/")
  738. else()
  739. set(CPACK_GENERATOR TGZ)
  740. endif()
  741. include(CPack)