CMakeLists.txt 31 KB

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