CMakeLists.txt 22 KB

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