CMakeLists.txt 33 KB

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