CMakeLists.txt 33 KB

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