CMakeLists.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. project(vcmi)
  2. cmake_minimum_required(VERSION 2.8.12)
  3. # TODO:
  4. # 1) Detection of Qt5 and compilation of launcher, unless explicitly disabled
  5. # where to look for cmake modules
  6. set(CMAKE_MODULE_PATH ${CMAKE_HOME_DIRECTORY}/cmake_modules)
  7. # enable Release mode but only if it was not set
  8. if (NOT CMAKE_BUILD_TYPE)
  9. set(CMAKE_BUILD_TYPE RelWithDebInfo)
  10. endif()
  11. # VCMI version
  12. set(VCMI_VERSION_MAJOR 0)
  13. set(VCMI_VERSION_MINOR 97)
  14. set(VCMI_VERSION_PATCH 0)
  15. option(ENABLE_ERM "Enable compilation of ERM scripting module" OFF)
  16. option(ENABLE_EDITOR "Enable compilation of map editor" OFF)
  17. option(ENABLE_LAUNCHER "Enable compilation of launcher" ON)
  18. option(ENABLE_TEST "Enable compilation of unit tests" OFF)
  19. option(ENABLE_PCH "Enable compilation using precompiled headers" ON)
  20. option(ENABLE_SDL2 "Use SDL2 for compilation instead of SDL 1.2" ON)
  21. ############################################
  22. # Building section #
  23. ############################################
  24. if (APPLE)
  25. # Default location for thirdparty libs
  26. set(CMAKE_INCLUDE_PATH "../include" "${CMAKE_OSX_SYSROOT}/usr/include")
  27. set(CMAKE_LIBRARY_PATH "../lib")
  28. set(CMAKE_FRAMEWORK_PATH "../Frameworks")
  29. set(BOOST_ROOT "../")
  30. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_HOME_DIRECTORY}/bin")
  31. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_HOME_DIRECTORY}/bin")
  32. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_HOME_DIRECTORY}/bin")
  33. set(CMAKE_XCODE_ATTRIBUTE_CONFIGURATION_BUILD_DIR "${CMAKE_HOME_DIRECTORY}/bin/$(CONFIGURATION)")
  34. set(CMAKE_XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path/../Frameworks @executable_path/")
  35. # Build with clang ang libc++
  36. set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11")
  37. set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
  38. # On OS X we use Sparkle framework for updates
  39. find_path(SPARKLE_INCLUDE_DIR Sparkle.h)
  40. find_library(SPARKLE_FRAMEWORK NAMES Sparkle)
  41. # Xcode 5.0 fix
  42. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=256")
  43. # Link with iconv
  44. set(SYSTEM_LIBS ${SYSTEM_LIBS} libiconv.dylib)
  45. endif()
  46. if (WIN32)
  47. add_definitions(-DBOOST_THREAD_USE_LIB)
  48. add_definitions(-D_WIN32_WINNT=0x0501)
  49. set(SYSTEM_LIBS ${SYSTEM_LIBS} ole32 oleaut32 ws2_32 mswsock)
  50. #delete lib prefix for dlls (libvcmi -> vcmi)
  51. set(CMAKE_SHARED_LIBRARY_PREFIX "")
  52. if(MINGW)
  53. #MinGW: check for iconv (may be needed for boost.locale)
  54. include(CheckLibraryExists)
  55. check_library_exists(iconv libiconv_open "" ICONV_FOUND)
  56. if(ICONV_FOUND)
  57. set(SYSTEM_LIBS ${SYSTEM_LIBS} iconv)
  58. endif()
  59. #MinGW: copy runtime to VCMI location
  60. get_filename_component(MINGW_BIN_PATH ${CMAKE_CXX_COMPILER} PATH )
  61. set(dep_files ${dep_files} "${MINGW_BIN_PATH}/libwinpthread-*.dll")
  62. set(dep_files ${dep_files} "${MINGW_BIN_PATH}/libgcc_s_*.dll")
  63. set(dep_files ${dep_files} "${MINGW_BIN_PATH}/libstdc++-*.dll")
  64. #MinGW: use O1 to prevent compiler crash in some cases
  65. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1")
  66. endif()
  67. if(MSVC)
  68. #MSVC: Fix problems with linking
  69. add_definitions(-DBOOST_ALL_NO_LIB)
  70. set(Boost_USE_STATIC_LIBS ON)
  71. #MSVC: Don't link with SDLMain
  72. set(SDL2_BUILDING_LIBRARY ON)
  73. #MSVC: Suppress warnings
  74. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  75. add_definitions(-D_SCL_SECURE_NO_WARNINGS)
  76. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /wd4251")
  77. endif()
  78. endif()
  79. if(NOT WIN32)
  80. INCLUDE(CheckLibraryExists)
  81. #check if some platform-specific libraries are needed for linking
  82. CHECK_LIBRARY_EXISTS(rt shm_open "" HAVE_RT_LIB)
  83. if(HAVE_RT_LIB)
  84. set(SYSTEM_LIBS ${SYSTEM_LIBS} rt)
  85. endif()
  86. CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_DL_LIB)
  87. if(HAVE_DL_LIB)
  88. set(SYSTEM_LIBS ${SYSTEM_LIBS} dl)
  89. endif()
  90. endif()
  91. set(FFmpeg_FIND_COMPONENTS AVFORMAT SWSCALE)
  92. find_package(Boost 1.48.0 COMPONENTS filesystem locale program_options system thread REQUIRED)
  93. find_package(ZLIB REQUIRED)
  94. find_package(FFmpeg REQUIRED)
  95. find_package(Minizip)
  96. if (MINIZIP_FOUND)
  97. add_definitions(-DUSE_SYSTEM_MINIZIP)
  98. endif()
  99. if (ENABLE_SDL2)
  100. find_package(SDL2 REQUIRED)
  101. find_package(SDL2_image REQUIRED)
  102. find_package(SDL2_mixer REQUIRED)
  103. find_package(SDL2_ttf REQUIRED)
  104. set(SDL_INCLUDE_DIR "${SDL2_INCLUDE_DIR}")
  105. set(SDLTTF_INCLUDE_DIR "${SDL2_TTF_INCLUDE_DIR}")
  106. set(SDLIMAGE_INCLUDE_DIR "${SDL2_IMAGE_INCLUDE_DIR}")
  107. set(SDLMIXER_INCLUDE_DIR "${SDL2_MIXER_INCLUDE_DIR}")
  108. set(SDL_LIBRARY "${SDL2_LIBRARY}")
  109. set(SDLTTF_LIBRARY "${SDL2_TTF_LIBRARY}")
  110. set(SDLIMAGE_LIBRARY "${SDL2_IMAGE_LIBRARY}")
  111. set(SDLMIXER_LIBRARY "${SDL2_MIXER_LIBRARY}")
  112. else()
  113. find_package(SDL REQUIRED)
  114. find_package(SDL_image REQUIRED)
  115. find_package(SDL_mixer REQUIRED)
  116. find_package(SDL_ttf REQUIRED)
  117. endif()
  118. include(cotire)
  119. if (ENABLE_EDITOR OR ENABLE_LAUNCHER)
  120. # Widgets finds its own dependencies (QtGui and QtCore).
  121. find_package(Qt5Widgets REQUIRED)
  122. endif()
  123. if (ENABLE_LAUNCHER)
  124. find_package(Qt5Network REQUIRED)
  125. endif()
  126. if(ENABLE_TEST)
  127. # find_package overwrites BOOST_* variables which are already set, so all components have to be included again
  128. find_package(Boost 1.48.0 COMPONENTS program_options filesystem system thread locale unit_test_framework REQUIRED)
  129. endif()
  130. if(CMAKE_COMPILER_IS_GNUCXX OR NOT WIN32) #so far all *nix compilers support such parameters
  131. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  132. set(CLANG_SPECIFIC_FLAGS "-Wno-mismatched-tags -Wno-unknown-warning-option")
  133. endif()
  134. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -Wextra -Wpointer-arith -Wno-strict-aliasing -Wno-switch -Wno-sign-compare -Wno-unused-local-typedefs -Wno-unused-parameter -Wuninitialized -Wno-overloaded-virtual -Wno-type-limits -Wno-unknown-pragmas -Wno-reorder ${CLANG_SPECIFIC_FLAGS}")
  135. if(UNIX)
  136. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
  137. endif()
  138. endif()
  139. if(WIN32) # on Win everything goes into H3 root directory
  140. set(BIN_DIR "." CACHE STRING "Where to install binaries")
  141. set(LIB_DIR "." CACHE STRING "Where to install main library")
  142. set(DATA_DIR "." CACHE STRING "Where to install data files")
  143. elseif(APPLE)
  144. # includes lib path which determines where to install shared libraries (either /lib or /lib64)
  145. include(GNUInstallDirs)
  146. set(BIN_DIR "." CACHE STRING "Where to install binaries")
  147. set(LIB_DIR "." CACHE STRING "Where to install main library")
  148. set(DATA_DIR "../h3" CACHE STRING "Where to install data files")
  149. else()
  150. # includes lib path which determines where to install shared libraries (either /lib or /lib64)
  151. include(GNUInstallDirs)
  152. if (NOT BIN_DIR)
  153. set(BIN_DIR "bin" CACHE STRING "Where to install binaries")
  154. endif()
  155. if (NOT LIB_DIR)
  156. set(LIB_DIR "${CMAKE_INSTALL_LIBDIR}/vcmi" CACHE STRING "Where to install main library")
  157. endif()
  158. if (NOT DATA_DIR)
  159. set(DATA_DIR "share/vcmi" CACHE STRING "Where to install data files")
  160. endif()
  161. endif()
  162. set (AI_LIB_DIR "${LIB_DIR}/AI")
  163. set (SCRIPTING_LIB_DIR "${LIB_DIR}/scripting")
  164. #define required constants
  165. add_definitions(-DM_DATA_DIR="${CMAKE_INSTALL_PREFIX}/${DATA_DIR}")
  166. add_definitions(-DM_BIN_DIR="${CMAKE_INSTALL_PREFIX}/${BIN_DIR}")
  167. add_definitions(-DM_LIB_DIR="${CMAKE_INSTALL_PREFIX}/${LIB_DIR}")
  168. SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/vcmi")
  169. SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  170. # precompiled header configuration
  171. SET(PCH_PROPERTIES
  172. COTIRE_ENABLE_PRECOMPILED_HEADER ${ENABLE_PCH}
  173. COTIRE_ADD_UNITY_BUILD FALSE
  174. COTIRE_CXX_PREFIX_HEADER_INIT "StdInc.h"
  175. )
  176. if (ENABLE_ERM)
  177. add_subdirectory(scripting/erm)
  178. endif()
  179. if (NOT MINIZIP_FOUND)
  180. add_subdirectory(lib/minizip)
  181. set(MINIZIP_LIBRARIES minizip)
  182. endif()
  183. add_subdirectory(lib)
  184. add_subdirectory(client)
  185. add_subdirectory(server)
  186. add_subdirectory(AI)
  187. if (ENABLE_EDITOR)
  188. add_subdirectory(editor)
  189. endif()
  190. if (ENABLE_LAUNCHER)
  191. add_subdirectory(launcher)
  192. endif()
  193. if(ENABLE_TEST)
  194. add_subdirectory(test)
  195. endif()
  196. #######################################
  197. # Installation section #
  198. #######################################
  199. # For apple this files will be already inside vcmiclient bundle
  200. if (NOT APPLE)
  201. # copy whole directory but .svn control files
  202. install(DIRECTORY config DESTINATION ${DATA_DIR} PATTERN ".svn" EXCLUDE)
  203. # copy vcmi mod along with all its content
  204. install(DIRECTORY Mods/vcmi DESTINATION ${DATA_DIR}/Mods PATTERN ".svn" EXCLUDE)
  205. install(FILES vcmibuilder DESTINATION ${BIN_DIR} PERMISSIONS
  206. OWNER_WRITE OWNER_READ OWNER_EXECUTE
  207. GROUP_READ GROUP_EXECUTE
  208. WORLD_READ WORLD_EXECUTE)
  209. endif()
  210. if(WIN32)
  211. file(GLOB dep_files
  212. ${dep_files}
  213. "${CMAKE_FIND_ROOT_PATH}/bin/*.dll")
  214. #Copy debug versions of libraries if build type is debug. Doesn't work in MSVC!
  215. if(CMAKE_BUILD_TYPE MATCHES DEBUG)
  216. set(debug_postfix d)
  217. endif(CMAKE_BUILD_TYPE MATCHES DEBUG)
  218. if (ENABLE_EDITOR OR ENABLE_LAUNCHER)
  219. get_target_property(QtCore_location Qt5::Core LOCATION)
  220. get_filename_component(Qtbin_folder ${QtCore_location} PATH)
  221. file(GLOB dep_files
  222. ${dep_files}
  223. ${Qtbin_folder}/Qt5Core${debug_postfix}.dll
  224. ${Qtbin_folder}/Qt5Gui${debug_postfix}.dll
  225. ${Qtbin_folder}/Qt5Widgets${debug_postfix}.dll
  226. ${Qtbin_folder}/icu*.dll)
  227. file(GLOB dep_qwindows
  228. ${Qtbin_folder}/../plugins/platforms/qwindows${debug_postfix}.dll)
  229. if(MSVC)
  230. file(GLOB dep_files
  231. ${dep_files}
  232. ${Qtbin_folder}/libEGL.dll
  233. ${Qtbin_folder}/libGLESv2.dll)
  234. endif()
  235. endif()
  236. if (ENABLE_LAUNCHER)
  237. file(GLOB dep_files
  238. ${dep_files}
  239. ${Qtbin_folder}/Qt5Network${debug_postfix}.dll)
  240. endif()
  241. if(MSVC)
  242. #install MSVC runtime
  243. include(InstallRequiredSystemLibraries)
  244. install(FILES ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} DESTINATION ${BIN_DIR})
  245. endif()
  246. install(FILES ${dep_files} DESTINATION ${BIN_DIR})
  247. install(FILES ${dep_qwindows} DESTINATION ${BIN_DIR}/platforms)
  248. elseif(NOT APPLE)
  249. #install icons and desktop file on Linux
  250. #FIXME: move to client makefile?
  251. install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.64x64.png" DESTINATION share/icons/hicolor/64x64/apps RENAME vcmiclient.png)
  252. install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.48x48.png" DESTINATION share/icons/hicolor/48x48/apps RENAME vcmiclient.png)
  253. install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.32x32.png" DESTINATION share/icons/hicolor/32x32/apps RENAME vcmiclient.png)
  254. install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.256x256.png" DESTINATION share/icons/hicolor/256x256/apps RENAME vcmiclient.png)
  255. install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.desktop" DESTINATION share/applications)
  256. if (ENABLE_LAUNCHER) #FIXME: move to launcher makefile?
  257. install(FILES "${CMAKE_SOURCE_DIR}/launcher/vcmilauncher.desktop" DESTINATION share/applications)
  258. endif()
  259. endif()
  260. #######################################
  261. # Packaging section #
  262. #######################################
  263. set(CPACK_PACKAGE_VERSION_MAJOR ${VCMI_VERSION_MAJOR})
  264. set(CPACK_PACKAGE_VERSION_MINOR ${VCMI_VERSION_MINOR})
  265. set(CPACK_PACKAGE_VERSION_PATCH ${VCMI_VERSION_PATCH})
  266. # vcmi does not have "patch version" in version string
  267. set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
  268. #TODO: remove version from Global.h and use this one as define?
  269. set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
  270. if(WIN32)
  271. set(CPACK_MONOLITHIC_INSTALL 1)
  272. set(CPACK_PACKAGE_NAME "VCMI")
  273. set(CPACK_PACKAGE_VENDOR "VCMI team")
  274. set(CPACK_PACKAGE_FILE_NAME "vcmi-${CPACK_PACKAGE_VERSION}-win32")
  275. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/license.txt")
  276. set(CPACK_PACKAGE_EXECUTABLES "VCMI_launcher;VCMI")
  277. set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}")
  278. set(CPACK_NSIS_PACKAGE_NAME "VCMI ${CPACK_PACKAGE_VERSION}")
  279. set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES")
  280. set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS " CreateShortCut \\\"$DESKTOP\\\\VCMI.lnk\\\" \\\"$INSTDIR\\\\VCMI_launcher.exe\\\"")
  281. set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS " Delete \\\"$DESKTOP\\\\VCMI.lnk\\\" ")
  282. configure_file("${CMAKE_SOURCE_DIR}/cmake_modules/CMakeCPackOptions.cmake.in" "${CMAKE_BINARY_DIR}/CMakeCPackOptions.cmake" @ONLY)
  283. set(CPACK_PROJECT_CONFIG_FILE "${CMAKE_BINARY_DIR}/CMakeCPackOptions.cmake")
  284. elseif(APPLE)
  285. set(CPACK_GENERATOR DragNDrop)
  286. set(CPACK_DMG_BACKGROUND_IMAGE "${CMAKE_SOURCE_DIR}/osx/dmg_background.png")
  287. set(CPACK_DMG_DS_STORE "${CMAKE_SOURCE_DIR}/osx/dmg_DS_Store")
  288. else()
  289. set(CPACK_GENERATOR TGZ)
  290. endif()
  291. INCLUDE(CPack)