CMakeLists.txt 32 KB

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