CMakeLists.txt 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. project(vcmi)
  2. cmake_minimum_required(VERSION 2.6)
  3. # TODO:
  4. # 1) Detection of system version of minizip and use it instead of local
  5. # 2) Detection of Qt5 and compilation of launcher, unless explicitly disabled
  6. # where to look for cmake modules
  7. set(CMAKE_MODULE_PATH ${CMAKE_HOME_DIRECTORY}/cmake_modules)
  8. # enable Release mode but only if it was not set
  9. if (NOT CMAKE_BUILD_TYPE)
  10. set(CMAKE_BUILD_TYPE RelWithDebInfo)
  11. endif()
  12. # VCMI version
  13. set(VCMI_VERSION_MAJOR 0)
  14. set(VCMI_VERSION_MINOR 94)
  15. set(VCMI_VERSION_PATCH 0)
  16. option(ENABLE_ERM "Enable compilation of ERM scripting module" OFF)
  17. option(ENABLE_EDITOR "Enable compilation of map editor" OFF)
  18. option(ENABLE_LAUNCHER "Enable compilation of launcher" ON)
  19. option(ENABLE_TEST "Enable compilation of unit tests" OFF)
  20. option(ENABLE_PCH "Enable compilation using precompiled headers" OFF)
  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")
  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. endif()
  44. find_package(Boost 1.48.0 COMPONENTS program_options filesystem system thread locale REQUIRED)
  45. find_package(SDL REQUIRED)
  46. find_package(SDL_image REQUIRED)
  47. find_package(SDL_mixer REQUIRED)
  48. find_package(SDL_ttf REQUIRED)
  49. find_package(ZLIB REQUIRED)
  50. include(cotire)
  51. if (ENABLE_EDITOR OR ENABLE_LAUNCHER)
  52. # Widgets finds its own dependencies (QtGui and QtCore).
  53. find_package(Qt5Widgets REQUIRED)
  54. endif()
  55. if (ENABLE_LAUNCHER)
  56. find_package(Qt5Network REQUIRED)
  57. endif()
  58. if(ENABLE_TEST)
  59. # find_package overwrites BOOST_* variables which are already set, so all components have to be
  60. # included again
  61. find_package(Boost 1.48.0 COMPONENTS program_options filesystem system thread locale unit_test_framework REQUIRED)
  62. endif()
  63. if(APPLE)
  64. set(Boost_LIBRARIES ${Boost_LIBRARIES} libiconv.dylib) # Our prebuilt boost_locale for OS X depends on iconv
  65. endif()
  66. if(NOT WIN32)
  67. set(FFmpeg_FIND_COMPONENTS AVFORMAT SWSCALE)
  68. find_package(FFmpeg REQUIRED)
  69. INCLUDE(CheckLibraryExists)
  70. #check if some platform-specific libraries are needed for linking
  71. CHECK_LIBRARY_EXISTS(rt shm_open "" HAVE_RT_LIB)
  72. if(HAVE_RT_LIB)
  73. set(RT_LIB -lrt)
  74. endif()
  75. CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_DL_LIB)
  76. if(HAVE_DL_LIB)
  77. set(DL_LIB -ldl)
  78. endif()
  79. endif()
  80. if(CMAKE_COMPILER_IS_GNUCXX OR NOT WIN32) #so far all *nix compilers support such parameters
  81. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  82. set(CLANG_SPECIFIC_FLAGS "-Wno-mismatched-tags")
  83. endif()
  84. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -Wextra -Wpointer-arith -Wno-switch -Wno-sign-compare -Wno-unused-parameter -Wuninitialized -Wno-overloaded-virtual ${CLANG_SPECIFIC_FLAGS}")
  85. endif()
  86. if(WIN32) # on Win everything goes into H3 root directory
  87. set(BIN_DIR "" CACHE STRING "Where to install binaries")
  88. set(LIB_DIR "" CACHE STRING "Where to install main library")
  89. set(DATA_DIR "" CACHE STRING "Where to install data files")
  90. elseif(APPLE)
  91. # includes lib path which determines where to install shared libraries (either /lib or /lib64)
  92. include(GNUInstallDirs)
  93. set(BIN_DIR "." CACHE STRING "Where to install binaries")
  94. set(LIB_DIR "." CACHE STRING "Where to install main library")
  95. set(DATA_DIR "../h3" CACHE STRING "Where to install data files")
  96. else()
  97. # includes lib path which determines where to install shared libraries (either /lib or /lib64)
  98. include(GNUInstallDirs)
  99. if (NOT BIN_DIR)
  100. set(BIN_DIR "bin" CACHE STRING "Where to install binaries")
  101. endif()
  102. if (NOT LIB_DIR)
  103. set(LIB_DIR "${CMAKE_INSTALL_LIBDIR}/vcmi" CACHE STRING "Where to install main library")
  104. endif()
  105. if (NOT DATA_DIR)
  106. set(DATA_DIR "share/vcmi" CACHE STRING "Where to install data files")
  107. endif()
  108. endif()
  109. set (AI_LIB_DIR "${LIB_DIR}/AI")
  110. set (SCRIPTING_LIB_DIR "${LIB_DIR}/scripting")
  111. #define required constants
  112. add_definitions(-DM_DATA_DIR="${CMAKE_INSTALL_PREFIX}/${DATA_DIR}")
  113. add_definitions(-DM_BIN_DIR="${CMAKE_INSTALL_PREFIX}/${BIN_DIR}")
  114. add_definitions(-DM_LIB_DIR="${CMAKE_INSTALL_PREFIX}/${LIB_DIR}")
  115. SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/vcmi")
  116. SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  117. # precompiled header configuration
  118. SET(PCH_PROPERTIES
  119. COTIRE_ENABLE_PRECOMPILED_HEADER ${ENABLE_PCH}
  120. COTIRE_ADD_UNITY_BUILD FALSE
  121. COTIRE_CXX_PREFIX_HEADER_INIT "StdInc.h"
  122. )
  123. if (ENABLE_ERM)
  124. add_subdirectory(scripting/erm)
  125. endif()
  126. add_subdirectory(lib)
  127. add_subdirectory(client)
  128. add_subdirectory(lib/minizip)
  129. add_subdirectory(server)
  130. add_subdirectory(AI)
  131. if (ENABLE_EDITOR)
  132. add_subdirectory(editor)
  133. endif()
  134. if (ENABLE_LAUNCHER)
  135. add_subdirectory(launcher)
  136. endif()
  137. if(ENABLE_TEST)
  138. add_subdirectory(test)
  139. endif()
  140. #######################################
  141. # Installation section #
  142. #######################################
  143. # For apple this files will be already inside vcmiclient bundle
  144. if (NOT APPLE)
  145. # copy whole directory but .svn control files
  146. install(DIRECTORY config DESTINATION ${DATA_DIR} PATTERN ".svn" EXCLUDE)
  147. # copy vcmi mod along with all its content
  148. install(DIRECTORY Mods/vcmi DESTINATION ${DATA_DIR}/Mods PATTERN ".svn" EXCLUDE)
  149. # copy only files added by vcmi for WoG
  150. install(FILES Mods/WoG/mod.json DESTINATION ${DATA_DIR}/Mods/WoG)
  151. install(DIRECTORY Mods/WoG/config DESTINATION ${DATA_DIR}/Mods/WoG PATTERN ".svn" EXCLUDE)
  152. install(FILES vcmibuilder DESTINATION ${BIN_DIR} PERMISSIONS
  153. OWNER_WRITE OWNER_READ OWNER_EXECUTE
  154. GROUP_READ GROUP_EXECUTE
  155. WORLD_READ WORLD_EXECUTE)
  156. endif()
  157. if(WIN32)
  158. #TODO: install any additional dll's. This version (may be broken) will copy all dll's including H3 ones
  159. #FILE(GLOB dll_files "${CMAKE_BINARY_DIR}/*.dll")
  160. #INSTALL(FILES ${dll_files} DESTINATION ${BIN_DIR})
  161. elseif(APPLE)
  162. else()
  163. #install icons and desktop file on Linux
  164. #FIXME: move to client makefile?
  165. install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.64x64.png" DESTINATION share/icons/hicolor/64x64/apps RENAME vcmiclient.png)
  166. install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.48x48.png" DESTINATION share/icons/hicolor/48x48/apps RENAME vcmiclient.png)
  167. install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.32x32.png" DESTINATION share/icons/hicolor/32x32/apps RENAME vcmiclient.png)
  168. install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.256x256.png" DESTINATION share/icons/hicolor/256x256/apps RENAME vcmiclient.png)
  169. install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.desktop" DESTINATION share/applications)
  170. if (ENABLE_LAUNCHER) #FIXME: move to launcher makefile?
  171. install(FILES "${CMAKE_SOURCE_DIR}/launcher/vcmilauncher.desktop" DESTINATION share/applications)
  172. endif()
  173. endif()
  174. #######################################
  175. # Packaging section #
  176. #######################################
  177. set(CPACK_PACKAGE_VERSION_MAJOR ${VCMI_VERSION_MAJOR})
  178. set(CPACK_PACKAGE_VERSION_MINOR ${VCMI_VERSION_MINOR})
  179. set(CPACK_PACKAGE_VERSION_PATCH ${VCMI_VERSION_PATCH})
  180. # vcmi does not have "patch version" in version string
  181. set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
  182. #TODO: remove version from Global.h and use this one as define?
  183. set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
  184. if(WIN32)
  185. set(CPACK_GENERATOR ZIP) # just use zip? CPack has some GUI install as well
  186. elseif(APPLE)
  187. set(CPACK_GENERATOR DragNDrop)
  188. set(CPACK_DMG_BACKGROUND_IMAGE "${CMAKE_SOURCE_DIR}/osx/dmg_background.png")
  189. set(CPACK_DMG_DS_STORE "${CMAKE_SOURCE_DIR}/osx/dmg_DS_Store")
  190. else()
  191. set(CPACK_GENERATOR TGZ)
  192. endif()
  193. INCLUDE(CPack)