CMakeLists.txt 20 KB

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