CMakeLists.txt 24 KB

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