CMakeLists.txt 21 KB

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