CMakeLists.txt 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. # Minimum required version greatly affect CMake behavior
  2. # So cmake_minimum_required must be called before the project()
  3. # 3.10.0 is used since it's minimal in MXE dependencies for now
  4. cmake_minimum_required(VERSION 3.10.0)
  5. project(VCMI)
  6. # TODO
  7. # macOS:
  8. # - There is problem with running fixup_bundle in main project after subdirectories.
  9. # Cmake put them after all install code of main CMakelists in cmake_install.cmake
  10. # Currently I just added extra add_subdirectory and CMakeLists.txt in osx directory to bypass that.
  11. #
  12. # MXE:
  13. # - Try to implement MXE support into BundleUtilities so we can deploy deps automatically
  14. #
  15. # Vckpg:
  16. # - Improve install code once there is better way to deploy DLLs and Qt plugins
  17. # - Move Vcpkg install BundleUtilities code from osx/CMakeLists.txt
  18. #
  19. # Other:
  20. # - Cleanup remove_directory copy_directory if performance will be a problem.
  21. # We can use some macro over copy_if_different since it's only work for single file.
  22. # - Find a way to move add_custom_command for assets deploy out of "lib/CMakeLists.txt"
  23. # - Consider to remove M_DATA_DIR, DM_BIN_DIR, DM_LIB_DIR and not use them in code as well
  24. # - Try to get rid of FOLDER override with define_property
  25. # It's used currently to make sure that 3rd-party dependencies in git submodules get proper FOLDER property
  26. # - Make FindFuzzyLite check for the right version and disable FORCE_BUNDLED_FL by default
  27. if(APPLE)
  28. if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
  29. set(APPLE_MACOS 1)
  30. else()
  31. set(APPLE_IOS 1)
  32. endif()
  33. endif(APPLE)
  34. ############################################
  35. # User-provided options #
  36. ############################################
  37. if(NOT CMAKE_BUILD_TYPE)
  38. set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
  39. "Choose the type of build, options are: Debug Release RelWithDebInfo. Default is RelWithDebInfo."
  40. FORCE)
  41. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo)
  42. endif()
  43. set(VCMI_VERSION_MAJOR 1)
  44. set(VCMI_VERSION_MINOR 0)
  45. set(VCMI_VERSION_PATCH 0)
  46. option(ENABLE_ERM "Enable compilation of ERM scripting module" OFF)
  47. option(ENABLE_LUA "Enable compilation of LUA scripting module" OFF)
  48. if(NOT APPLE_IOS)
  49. option(ENABLE_LAUNCHER "Enable compilation of launcher" ON)
  50. endif()
  51. option(ENABLE_TEST "Enable compilation of unit tests" ON)
  52. if(NOT ${CMAKE_VERSION} VERSION_LESS "3.16.0")
  53. option(ENABLE_PCH "Enable compilation using precompiled headers" ON)
  54. endif(NOT ${CMAKE_VERSION} VERSION_LESS "3.16.0")
  55. option(ENABLE_GITVERSION "Enable Version.cpp with Git commit hash" ON)
  56. option(ENABLE_DEBUG_CONSOLE "Enable debug console for Windows builds" ON)
  57. option(ENABLE_MULTI_PROCESS_BUILDS "Enable /MP flag for MSVS solution" ON)
  58. # Used for Snap packages and also useful for debugging
  59. if(NOT APPLE_IOS)
  60. option(ENABLE_MONOLITHIC_INSTALL "Install everything in single directory on Linux and Mac" OFF)
  61. endif()
  62. # Allow to pass package name from Travis CI
  63. set(PACKAGE_NAME_SUFFIX "" CACHE STRING "Suffix for CPack package name")
  64. set(PACKAGE_FILE_NAME "" CACHE STRING "Override for CPack package filename")
  65. # ERM depends on LUA implicitly
  66. if(ENABLE_ERM AND NOT ENABLE_LUA)
  67. set(ENABLE_LUA ON)
  68. endif()
  69. ############################################
  70. # Miscellaneous options #
  71. ############################################
  72. set(CMAKE_MODULE_PATH ${CMAKE_HOME_DIRECTORY}/cmake_modules ${PROJECT_SOURCE_DIR}/CI)
  73. # Contains custom functions and macros, but don't altering any options
  74. include(VCMIUtils)
  75. vcmi_print_important_variables()
  76. # Options to enable folders in CMake generated projects for Visual Studio, Xcode, etc
  77. # Very useful to put 3rd-party libraries such as Minizip, GoogleTest and FuzzyLite in their own folders
  78. set_property(GLOBAL PROPERTY USE_FOLDERS TRUE)
  79. # Make FOLDER property inheritable
  80. # So when we set FOLDER property on AI directory all and targets inside will inherit it
  81. #
  82. # Important! This trick depend on undefined behavior since we override CMake own property.
  83. # In same time define_property documentation states it's function for custom properties.
  84. define_property(
  85. TARGET
  86. PROPERTY FOLDER
  87. INHERITED
  88. BRIEF_DOCS "Set the folder name."
  89. FULL_DOCS "Use to organize targets in an IDE."
  90. )
  91. # Generate Version.cpp
  92. if(ENABLE_GITVERSION)
  93. add_custom_target(update_version ALL
  94. BYPRODUCTS "Version.cpp"
  95. COMMAND ${CMAKE_COMMAND} -DGIT_SHA1="${GIT_SHA1}" -P "${PROJECT_SOURCE_DIR}/cmake_modules/Version.cmake"
  96. )
  97. else()
  98. add_definitions(-DVCMI_NO_EXTRA_VERSION)
  99. endif(ENABLE_GITVERSION)
  100. # Precompiled header configuration
  101. if(ENABLE_PCH AND NOT ${CMAKE_VERSION} VERSION_LESS "3.16.0")
  102. macro(enable_pch name)
  103. target_precompile_headers(${name} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:<StdInc.h$<ANGLE-R>>)
  104. endmacro(enable_pch)
  105. else(ENABLE_PCH AND NOT ${CMAKE_VERSION} VERSION_LESS "3.16.0")
  106. macro(enable_pch ignore)
  107. endmacro(enable_pch)
  108. endif(ENABLE_PCH AND NOT ${CMAKE_VERSION} VERSION_LESS "3.16.0")
  109. ############################################
  110. # Documentation section #
  111. ############################################
  112. include(UseDoxygen OPTIONAL)
  113. ############################################
  114. # Compile and linking options #
  115. ############################################
  116. #Enable C++14 Globally
  117. set (CMAKE_CXX_STANDARD 14)
  118. #General visibility options
  119. set(CMAKE_CXX_VISIBILITY_PRESET hidden)
  120. set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
  121. #Global fallback mapping
  122. # RelWithDebInfo falls back to Release, then MinSizeRel
  123. set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO RelWithDebInfo Release MinSizeRel "")
  124. # MinSizeRel falls back to Release, then RelWithDebInfo
  125. set(CMAKE_MAP_IMPORTED_CONFIG_MINSIZEREL MinSizeRel Release RelWithDebInfo "")
  126. # Release falls back to RelWithDebInfo, then MinSizeRel
  127. set(CMAKE_MAP_IMPORTED_CONFIG_RELEASE Release RelWithDebInfo MinSizeRel "")
  128. if(APPLE_IOS)
  129. set(SYSTEM_LIBS ${SYSTEM_LIBS} iconv) # boost.locale
  130. endif(APPLE_IOS)
  131. if(MINGW OR MSVC)
  132. # Windows Vista or newer for FuzzyLite 6 to compile
  133. add_definitions(-D_WIN32_WINNT=0x0600)
  134. #delete lib prefix for dlls (libvcmi -> vcmi)
  135. set(CMAKE_SHARED_LIBRARY_PREFIX "")
  136. if(MSVC)
  137. add_definitions(-DBOOST_ALL_NO_LIB)
  138. add_definitions(-DBOOST_ALL_DYN_LINK)
  139. set(Boost_USE_STATIC_LIBS OFF)
  140. # Don't link with SDLMain
  141. if(ENABLE_DEBUG_CONSOLE)
  142. set(SDL2_BUILDING_LIBRARY ON)
  143. add_definitions(-DVCMI_WITH_DEBUG_CONSOLE)
  144. endif()
  145. # Suppress warnings
  146. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  147. add_definitions(-D_SCL_SECURE_NO_WARNINGS)
  148. # 4250: 'class1' : inherits 'class2::member' via dominance
  149. # 4251: class 'xxx' needs to have dll-interface to be used by clients of class 'yyy'
  150. # 4275: non dll-interface class 'xxx' used as base for dll-interface class
  151. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /wd4250 /wd4251 /wd4275")
  152. if(ENABLE_MULTI_PROCESS_BUILDS)
  153. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
  154. endif()
  155. # Workaround: Visual Studio has issues with exports of classes that inherit templates
  156. # https://stackoverflow.com/questions/44960760/msvc-dll-exporting-class-that-inherits-from-template-cause-lnk2005-already-defin
  157. # Reported to Microsoft here:
  158. # https://developercommunity.visualstudio.com/content/problem/224597/linker-failing-because-of-multiple-definitions-of.html
  159. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /FORCE:MULTIPLE")
  160. # Required at least for compatibility with Boost 1.68 on Vcpkg
  161. set(SYSTEM_LIBS ${SYSTEM_LIBS} bcrypt)
  162. endif(MSVC)
  163. if(MINGW)
  164. set(SYSTEM_LIBS ${SYSTEM_LIBS} ole32 oleaut32 ws2_32 mswsock dbghelp bcrypt)
  165. # Check for iconv (may be needed for Boost.Locale)
  166. include(CheckLibraryExists)
  167. check_library_exists(iconv libiconv_open "" ICONV_FOUND)
  168. if(ICONV_FOUND)
  169. set(SYSTEM_LIBS ${SYSTEM_LIBS} iconv)
  170. endif()
  171. # Prevent compiler issues when building Debug
  172. # Assembler might fail with "too many sections"
  173. # With big-obj or 64-bit build will take hours
  174. if(CMAKE_BUILD_TYPE MATCHES Debug)
  175. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Og")
  176. endif()
  177. endif(MINGW)
  178. endif(MINGW OR MSVC)
  179. if(CMAKE_COMPILER_IS_GNUCXX OR NOT WIN32) #so far all *nix compilers support such parameters
  180. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpointer-arith -Wuninitialized")
  181. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing -Wno-switch -Wno-sign-compare -Wno-unused-local-typedefs")
  182. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-overloaded-virtual -Wno-type-limits -Wno-unknown-pragmas")
  183. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reorder")
  184. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-varargs") # fuzzylite - Operation.h
  185. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  186. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-mismatched-tags -Wno-unknown-warning-option -Wno-missing-braces")
  187. endif()
  188. if(UNIX)
  189. set(SYSTEM_LIBS ${SYSTEM_LIBS} ${CMAKE_DL_LIBS})
  190. endif()
  191. endif()
  192. # Check if some platform-specific libraries are needed for linking
  193. if(NOT WIN32 AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
  194. include(CheckLibraryExists)
  195. # Shared memory functions used by Boost.Interprocess
  196. # FindBoost handle linking with pthreads, but doesn't handle this
  197. CHECK_LIBRARY_EXISTS(rt shm_open "" HAVE_RT_LIB)
  198. if(HAVE_RT_LIB)
  199. set(SYSTEM_LIBS ${SYSTEM_LIBS} rt)
  200. endif()
  201. endif()
  202. if(ENABLE_LUA)
  203. add_compile_definitions(SCRIPTING_ENABLED=1)
  204. endif()
  205. ############################################
  206. # Finding packages #
  207. ############################################
  208. find_package(Boost 1.48.0 REQUIRED COMPONENTS date_time filesystem locale program_options system thread)
  209. find_package(ZLIB REQUIRED)
  210. # Conan compatibility
  211. if(TARGET zlib::zlib)
  212. add_library(ZLIB::ZLIB ALIAS zlib::zlib)
  213. endif()
  214. find_package(ffmpeg COMPONENTS avutil swscale avformat avcodec)
  215. option(FORCE_BUNDLED_MINIZIP "Force bundled Minizip library" OFF)
  216. if(NOT FORCE_BUNDLED_MINIZIP)
  217. find_package(minizip)
  218. if(TARGET minizip::minizip)
  219. add_definitions(-DUSE_SYSTEM_MINIZIP)
  220. endif()
  221. endif()
  222. find_package(SDL2 REQUIRED)
  223. find_package(SDL2_image REQUIRED)
  224. find_package(SDL2_mixer REQUIRED)
  225. if(TARGET SDL2_mixer::SDL2_mixer)
  226. add_library(SDL2::Mixer ALIAS SDL2_mixer::SDL2_mixer)
  227. endif()
  228. find_package(SDL2_ttf REQUIRED)
  229. if(TARGET SDL2_ttf::SDL2_ttf)
  230. add_library(SDL2::TTF ALIAS SDL2_ttf::SDL2_ttf)
  231. endif()
  232. find_package(TBB REQUIRED)
  233. if(ENABLE_LAUNCHER)
  234. # Widgets finds its own dependencies (QtGui and QtCore).
  235. find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Network)
  236. find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Network)
  237. endif()
  238. if(ENABLE_LUA)
  239. find_package(luajit)
  240. # MXE paths hardcoded for current dependencies pack - tried and could not make it work another way
  241. if((MINGW) AND (${CMAKE_CROSSCOMPILING}) AND (DEFINED MSYS) AND (NOT TARGET luajit::luajit))
  242. add_library(luajit::luajit STATIC IMPORTED)
  243. set_target_properties(luajit::luajit PROPERTIES
  244. INTERFACE_INCLUDE_DIRECTORIES "/usr/lib/mxe/usr/i686-w64-mingw32.static/include/luajit-2.0")
  245. set_target_properties(luajit::luajit PROPERTIES
  246. IMPORTED_LOCATION "/usr/lib/mxe/usr/i686-w64-mingw32.static/lib/libluajit-5.1.a")
  247. endif()
  248. if(TARGET luajit::luajit)
  249. message(STATUS "Using LuaJIT provided by system")
  250. else()
  251. message(STATUS "Cannot find LuaJIT! Fallback to using usual Lua.")
  252. find_package(Lua REQUIRED)
  253. if(Lua_FOUND)
  254. add_library(luajit::luajit UNKNOWN IMPORTED)
  255. set_target_properties(luajit::luajit PROPERTIES
  256. INTERFACE_INCLUDE_DIRECTORIES "${LUA_INCLUDE_DIR}")
  257. set_target_properties(luajit::luajit PROPERTIES
  258. IMPORTED_LOCATION "${LUA_LIBRARIES}")
  259. endif()
  260. endif()
  261. endif()
  262. ############################################
  263. # Output directories #
  264. ############################################
  265. if(WIN32) # on Win everything goes into H3 root directory
  266. set(BIN_DIR "." CACHE STRING "Where to install binaries")
  267. set(LIB_DIR "." CACHE STRING "Where to install main library")
  268. set(DATA_DIR "." CACHE STRING "Where to install data files")
  269. elseif(APPLE)
  270. # includes lib path which determines where to install shared libraries (either /lib or /lib64)
  271. include(GNUInstallDirs)
  272. set(CMAKE_INSTALL_RPATH "@executable_path/../Frameworks")
  273. if(ENABLE_MONOLITHIC_INSTALL)
  274. set(BIN_DIR "." CACHE STRING "Where to install binaries")
  275. set(LIB_DIR "." CACHE STRING "Where to install main library")
  276. set(DATA_DIR "." CACHE STRING "Where to install data files")
  277. else()
  278. set(APP_BUNDLE_DIR "${CMAKE_PROJECT_NAME}.app")
  279. if(APPLE_MACOS)
  280. set(APP_BUNDLE_CONTENTS_DIR "${APP_BUNDLE_DIR}/Contents")
  281. set(APP_BUNDLE_BINARY_DIR "${APP_BUNDLE_CONTENTS_DIR}/MacOS")
  282. else()
  283. set(APP_BUNDLE_CONTENTS_DIR "${APP_BUNDLE_DIR}")
  284. set(APP_BUNDLE_BINARY_DIR "${APP_BUNDLE_DIR}")
  285. endif(APPLE_MACOS)
  286. set(APP_BUNDLE_RESOURCES_DIR "${APP_BUNDLE_CONTENTS_DIR}/Resources")
  287. set(BIN_DIR "${APP_BUNDLE_BINARY_DIR}" CACHE STRING "Where to install binaries")
  288. set(LIB_DIR "${APP_BUNDLE_CONTENTS_DIR}/Frameworks" CACHE STRING "Where to install main library")
  289. set(DATA_DIR "${APP_BUNDLE_RESOURCES_DIR}/Data" CACHE STRING "Where to install data files")
  290. endif()
  291. else()
  292. # includes lib path which determines where to install shared libraries (either /lib or /lib64)
  293. include(GNUInstallDirs)
  294. if(ENABLE_MONOLITHIC_INSTALL)
  295. set(CMAKE_INSTALL_RPATH "$ORIGIN/")
  296. set(BIN_DIR "." CACHE STRING "Where to install binaries")
  297. set(LIB_DIR "." CACHE STRING "Where to install main library")
  298. set(DATA_DIR "." CACHE STRING "Where to install data files")
  299. else()
  300. if(NOT BIN_DIR)
  301. set(BIN_DIR "bin" CACHE STRING "Where to install binaries")
  302. endif()
  303. if(NOT LIB_DIR)
  304. set(LIB_DIR "${CMAKE_INSTALL_LIBDIR}/vcmi" CACHE STRING "Where to install main library")
  305. endif()
  306. if(NOT DATA_DIR)
  307. set(DATA_DIR "share/vcmi" CACHE STRING "Where to install data files")
  308. endif()
  309. endif()
  310. # following constants only used for platforms using XDG (Linux, BSD, etc)
  311. add_definitions(-DM_DATA_DIR="${CMAKE_INSTALL_PREFIX}/${DATA_DIR}")
  312. add_definitions(-DM_BIN_DIR="${CMAKE_INSTALL_PREFIX}/${BIN_DIR}")
  313. add_definitions(-DM_LIB_DIR="${CMAKE_INSTALL_PREFIX}/${LIB_DIR}")
  314. endif()
  315. set(AI_LIB_DIR "${LIB_DIR}/AI")
  316. set(SCRIPTING_LIB_DIR "${LIB_DIR}/scripting")
  317. #######################################
  318. # Add subdirectories #
  319. #######################################
  320. if(ENABLE_ERM)
  321. add_subdirectory(scripting/erm)
  322. endif()
  323. if(ENABLE_LUA)
  324. add_subdirectory(scripting/lua)
  325. endif()
  326. if(NOT TARGET minizip::minizip)
  327. add_subdirectory_with_folder("3rdparty" lib/minizip)
  328. add_library(minizip::minizip ALIAS minizip)
  329. endif()
  330. add_subdirectory(lib)
  331. add_subdirectory(client)
  332. add_subdirectory(server)
  333. add_subdirectory_with_folder("AI" AI)
  334. if(ENABLE_LAUNCHER)
  335. add_subdirectory(launcher)
  336. endif()
  337. if(ENABLE_TEST)
  338. enable_testing()
  339. add_subdirectory(test)
  340. endif()
  341. #######################################
  342. # Installation section #
  343. #######################################
  344. install(DIRECTORY config DESTINATION ${DATA_DIR})
  345. install(DIRECTORY scripts DESTINATION ${DATA_DIR})
  346. install(DIRECTORY Mods DESTINATION ${DATA_DIR})
  347. # that script is useless for Windows
  348. if(NOT WIN32)
  349. install(FILES vcmibuilder DESTINATION ${BIN_DIR} PERMISSIONS
  350. OWNER_WRITE OWNER_READ OWNER_EXECUTE
  351. GROUP_READ GROUP_EXECUTE
  352. WORLD_READ WORLD_EXECUTE)
  353. endif()
  354. if(WIN32)
  355. file(GLOB dep_files
  356. ${dep_files}
  357. "${CMAKE_FIND_ROOT_PATH}/bin/*.dll")
  358. if((${CMAKE_CROSSCOMPILING}) AND (DEFINED MSYS))
  359. message(STATUS "Detected MXE build")
  360. elseif(CMAKE_BUILD_TYPE MATCHES Debug)
  361. # Copy debug versions of libraries if build type is debug
  362. set(debug_postfix d)
  363. endif()
  364. if(ENABLE_LAUNCHER)
  365. get_target_property(QtCore_location Qt${QT_VERSION_MAJOR}::Core LOCATION)
  366. get_filename_component(Qtbin_folder ${QtCore_location} PATH)
  367. file(GLOB dep_files
  368. ${dep_files}
  369. ${Qtbin_folder}/Qt5Core${debug_postfix}.dll
  370. ${Qtbin_folder}/Qt5Gui${debug_postfix}.dll
  371. ${Qtbin_folder}/Qt5Widgets${debug_postfix}.dll
  372. ${Qtbin_folder}/Qt5Network${debug_postfix}.dll
  373. ${Qtbin_folder}/icu*.dll)
  374. get_target_property(integration_type Qt${QT_VERSION_MAJOR}::QWindowsIntegrationPlugin TYPE)
  375. if(NOT(integration_type STREQUAL "INTERFACE_LIBRARY"))
  376. get_target_property(integration_loc Qt${QT_VERSION_MAJOR}::QWindowsIntegrationPlugin LOCATION)
  377. install(
  378. FILES ${integration_loc}
  379. DESTINATION ${BIN_DIR}/platforms
  380. )
  381. endif()
  382. endif()
  383. install(FILES ${dep_files} DESTINATION ${BIN_DIR})
  384. endif(WIN32)
  385. #######################################
  386. # Packaging section #
  387. #######################################
  388. set(CPACK_PACKAGE_VERSION_MAJOR ${VCMI_VERSION_MAJOR})
  389. set(CPACK_PACKAGE_VERSION_MINOR ${VCMI_VERSION_MINOR})
  390. set(CPACK_PACKAGE_VERSION_PATCH ${VCMI_VERSION_PATCH})
  391. # vcmi does not have "patch version" in version string
  392. set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
  393. #TODO: remove version from Global.h and use this one as define?
  394. set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
  395. if("${PACKAGE_NAME_SUFFIX}" STREQUAL "")
  396. set(CPACK_PACKAGE_NAME "VCMI")
  397. else()
  398. set(CPACK_PACKAGE_NAME "VCMI ${PACKAGE_NAME_SUFFIX}")
  399. endif()
  400. if("${PACKAGE_FILE_NAME}" STREQUAL "")
  401. set(CPACK_PACKAGE_FILE_NAME "vcmi-${CPACK_PACKAGE_VERSION}")
  402. else()
  403. set(CPACK_PACKAGE_FILE_NAME "${PACKAGE_FILE_NAME}")
  404. endif()
  405. set(CPACK_PACKAGE_VENDOR "VCMI team")
  406. if(WIN32)
  407. # Note: due to NSI script generation process all of the backward slashes here are useful
  408. set(CPACK_MONOLITHIC_INSTALL 1)
  409. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/license.txt")
  410. set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}")
  411. if("${PACKAGE_NAME_SUFFIX}" STREQUAL "")
  412. set(CPACK_NSIS_PACKAGE_NAME "VCMI ${CPACK_PACKAGE_VERSION}")
  413. else()
  414. set(CPACK_NSIS_PACKAGE_NAME "VCMI ${CPACK_PACKAGE_VERSION} ${PACKAGE_NAME_SUFFIX} ")
  415. endif()
  416. set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES")
  417. if(ENABLE_LAUNCHER)
  418. set(CPACK_PACKAGE_EXECUTABLES "VCMI_launcher;VCMI")
  419. set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS " CreateShortCut \\\"$DESKTOP\\\\VCMI.lnk\\\" \\\"$INSTDIR\\\\VCMI_launcher.exe\\\"")
  420. else()
  421. set(CPACK_PACKAGE_EXECUTABLES "VCMI_client;VCMI")
  422. set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS " CreateShortCut \\\"$DESKTOP\\\\VCMI.lnk\\\" \\\"$INSTDIR\\\\VCMI_client.exe\\\"")
  423. endif()
  424. set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS " Delete \\\"$DESKTOP\\\\VCMI.lnk\\\" ")
  425. # set the install/unistall icon used for the installer itself
  426. # There is a bug in NSI that does not handle full unix paths properly.
  427. set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/client\\\\vcmi.ico")
  428. set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}/client\\\\vcmi.ico")
  429. # set the package header icon for MUI
  430. set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/client\\\\vcmi.ico")
  431. set(CPACK_NSIS_MENU_LINKS "http://vcmi.eu/" "VCMI Web Site")
  432. set(CPACK_NSIS_INSTALLED_ICON_NAME "VCMI_client.exe")
  433. set(CPACK_NSIS_COMPRESSOR "/SOLID lzma")
  434. set(CPACK_NSIS_DISPLAY_NAME "${CPACK_NSIS_PACKAGE_NAME}, open-source engine for Heroes of Might and Magic III ")
  435. set(CPACK_NSIS_HELP_LINK "http://vcmi.eu/")
  436. set(CPACK_NSIS_URL_INFO_ABOUT "http://vcmi.eu/")
  437. set(CPACK_NSIS_CONTACT @CPACK_PACKAGE_CONTACT@)
  438. set(CPACK_NSIS_EXECUTABLES_DIRECTORY ".")
  439. # Use BundleUtilities to fix build when Vcpkg is used and disable it for MXE
  440. if(NOT (${CMAKE_CROSSCOMPILING}))
  441. add_subdirectory(osx)
  442. add_subdirectory(win)
  443. endif()
  444. elseif(APPLE_MACOS AND NOT ENABLE_MONOLITHIC_INSTALL)
  445. set(CPACK_MONOLITHIC_INSTALL 1)
  446. set(CPACK_GENERATOR "DragNDrop")
  447. set(CPACK_DMG_BACKGROUND_IMAGE "${CMAKE_SOURCE_DIR}/osx/dmg_background.png")
  448. # CMake code for CPACK_DMG_DS_STORE executed before DS_STORE_SETUP_SCRIPT
  449. # So we can keep both enabled and this shouldn't hurt
  450. # set(CPACK_DMG_DS_STORE "${CMAKE_SOURCE_DIR}/osx/dmg_DS_Store")
  451. set(CPACK_DMG_DS_STORE_SETUP_SCRIPT "${CMAKE_SOURCE_DIR}/osx/DS_Store_Setup.scpt")
  452. # Always use "VCMI" as volume name so full path will be /Volumes/VCMI/
  453. # Otherwise DMG background image wouldn't work
  454. # Pre-generated DS_Store use absolute path to background image
  455. set(CPACK_DMG_VOLUME_NAME "${CMAKE_PROJECT_NAME}")
  456. set(MACOSX_BUNDLE_NAME "${CMAKE_PROJECT_NAME}")
  457. set(MACOSX_BUNDLE_BUNDLE_NAME "${CMAKE_PROJECT_NAME}")
  458. if(ENABLE_LAUNCHER)
  459. set(MACOSX_BUNDLE_EXECUTABLE_NAME "vcmilauncher")
  460. else()
  461. set(MACOSX_BUNDLE_EXECUTABLE_NAME "vcmiclient")
  462. endif()
  463. set(MACOSX_BUNDLE_ICON_FILE "vcmi.icns")
  464. install(FILES "${CMAKE_SOURCE_DIR}/osx/vcmi.icns" DESTINATION ${APP_BUNDLE_RESOURCES_DIR})
  465. configure_file("${CMAKE_SOURCE_DIR}/osx/Info.plist.in" "${CMAKE_BINARY_DIR}/Info.plist")
  466. install(FILES "${CMAKE_BINARY_DIR}/Info.plist" DESTINATION ${APP_BUNDLE_CONTENTS_DIR})
  467. # Bundle fixing code must be in separate directory to be executed after all other install code
  468. add_subdirectory(osx)
  469. else()
  470. set(CPACK_GENERATOR TGZ)
  471. endif()
  472. include(CPack)