CMakeLists.txt 20 KB

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