CMakeLists.txt 18 KB

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