CMakeLists.txt 33 KB

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