CMakeLists.txt 31 KB

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