CMakeLists.txt 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 Release)
  11. endif()
  12. # VCMI version
  13. set(VCMI_VERSION_MAJOR 0)
  14. set(VCMI_VERSION_MINOR 93)
  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" OFF)
  19. option(ENABLE_TEST "Enable compilation of unit tests" OFF)
  20. ############################################
  21. # Building section #
  22. ############################################
  23. if (APPLE)
  24. # Default location for thirdparty libs
  25. set(CMAKE_INCLUDE_PATH "../include" "${CMAKE_OSX_SYSROOT}/usr/include")
  26. set(CMAKE_LIBRARY_PATH "../lib")
  27. set(CMAKE_FRAMEWORK_PATH "../Frameworks")
  28. set(BOOST_ROOT "../")
  29. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_HOME_DIRECTORY}/bin")
  30. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_HOME_DIRECTORY}/bin")
  31. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_HOME_DIRECTORY}/bin")
  32. set(CMAKE_XCODE_ATTRIBUTE_CONFIGURATION_BUILD_DIR "${CMAKE_HOME_DIRECTORY}/bin/$(CONFIGURATION)")
  33. set(CMAKE_XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path/../Frameworks")
  34. # Build with clang ang libc++
  35. set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11")
  36. set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
  37. # On OS X we use Sparkle framework for updates
  38. find_path(SPARKLE_INCLUDE_DIR Sparkle.h)
  39. find_library(SPARKLE_FRAMEWORK NAMES Sparkle)
  40. endif()
  41. find_package(Boost 1.46.0 COMPONENTS program_options filesystem system thread REQUIRED)
  42. find_package(SDL REQUIRED)
  43. find_package(SDL_image REQUIRED)
  44. find_package(SDL_mixer REQUIRED)
  45. find_package(SDL_ttf REQUIRED)
  46. find_package(ZLIB REQUIRED)
  47. if (ENABLE_EDITOR OR ENABLE_LAUNCHER)
  48. # Widgets finds its own dependencies (QtGui and QtCore).
  49. find_package(Qt5Widgets REQUIRED)
  50. endif()
  51. if (ENABLE_LAUNCHER)
  52. find_package(Qt5Network REQUIRED)
  53. endif()
  54. if(ENABLE_TEST)
  55. # find_package overwrites BOOST_* variables which are already set, so all components have to be
  56. # included again
  57. find_package(Boost 1.46.0 COMPONENTS program_options filesystem system thread unit_test_framework REQUIRED)
  58. endif()
  59. if(NOT WIN32)
  60. set(FFmpeg_FIND_COMPONENTS AVFORMAT SWSCALE)
  61. find_package(FFmpeg REQUIRED)
  62. INCLUDE(CheckLibraryExists)
  63. #check if some platform-specific libraries are needed for linking client and server
  64. CHECK_LIBRARY_EXISTS(rt shm_open "" HAVE_RT_LIB)
  65. if(HAVE_RT_LIB)
  66. set(RT_LIB -lrt)
  67. endif()
  68. CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_DL_LIB)
  69. if(HAVE_DL_LIB)
  70. set(DL_LIB -ldl)
  71. endif()
  72. endif()
  73. if(CMAKE_COMPILER_IS_GNUCXX OR NOT WIN32) #so far all *nix compilers support such parameters
  74. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  75. set(CLANG_SPECIFIC_FLAGS "-Wno-mismatched-tags")
  76. endif()
  77. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -Wextra -Wpointer-arith -Wno-switch -Wno-sign-compare -Wno-unused-parameter -Wno-overloaded-virtual ${CLANG_SPECIFIC_FLAGS}")
  78. endif()
  79. if(WIN32) # on Win everything goes into H3 root directory
  80. set(BIN_DIR "" CACHE STRING "Where to install binaries")
  81. set(LIB_DIR "" CACHE STRING "Where to install main library")
  82. set(DATA_DIR "" CACHE STRING "Where to install data files")
  83. elseif(APPLE)
  84. # includes lib path which determines where to install shared libraries (either /lib or /lib64)
  85. include(GNUInstallDirs)
  86. set(BIN_DIR "." CACHE STRING "Where to install binaries")
  87. set(LIB_DIR "." CACHE STRING "Where to install main library")
  88. set(DATA_DIR "../h3" CACHE STRING "Where to install data files")
  89. else()
  90. # includes lib path which determines where to install shared libraries (either /lib or /lib64)
  91. include(GNUInstallDirs)
  92. if (NOT BIN_DIR)
  93. set(BIN_DIR "bin" CACHE STRING "Where to install binaries")
  94. endif()
  95. if (NOT LIB_DIR)
  96. set(LIB_DIR "${CMAKE_INSTALL_LIBDIR}/vcmi" CACHE STRING "Where to install main library")
  97. endif()
  98. if (NOT DATA_DIR)
  99. set(DATA_DIR "share/vcmi" CACHE STRING "Where to install data files")
  100. endif()
  101. endif()
  102. set (AI_LIB_DIR "${LIB_DIR}/AI")
  103. set (SCRIPTING_LIB_DIR "${LIB_DIR}/scripting")
  104. #define required constants
  105. add_definitions(-DM_DATA_DIR="${CMAKE_INSTALL_PREFIX}/${DATA_DIR}")
  106. add_definitions(-DM_BIN_DIR="${CMAKE_INSTALL_PREFIX}/${BIN_DIR}")
  107. add_definitions(-DM_LIB_DIR="${CMAKE_INSTALL_PREFIX}/${LIB_DIR}")
  108. SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/vcmi")
  109. SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  110. add_subdirectory(lib)
  111. add_subdirectory(lib/minizip)
  112. add_subdirectory(client)
  113. add_subdirectory(server)
  114. add_subdirectory(AI)
  115. if (ENABLE_ERM)
  116. add_subdirectory(scripting/erm)
  117. endif()
  118. if (ENABLE_EDITOR)
  119. add_subdirectory(editor)
  120. endif()
  121. if (ENABLE_LAUNCHER)
  122. add_subdirectory(launcher)
  123. endif()
  124. if(ENABLE_TEST)
  125. add_subdirectory(test)
  126. endif()
  127. #######################################
  128. # Installation section #
  129. #######################################
  130. # For apple this files will be already inside vcmiclient bundle
  131. if (NOT APPLE)
  132. # copy whole directory but .svn control files
  133. install(DIRECTORY config DESTINATION ${DATA_DIR} PATTERN ".svn" EXCLUDE)
  134. # copy vcmi mod along with all its content
  135. install(DIRECTORY Mods/vcmi DESTINATION ${DATA_DIR}/Mods PATTERN ".svn" EXCLUDE)
  136. # copy only files added by vcmi for WoG
  137. install(FILES Mods/WoG/mod.json DESTINATION ${DATA_DIR}/Mods/WoG)
  138. install(DIRECTORY Mods/WoG/config DESTINATION ${DATA_DIR}/Mods/WoG PATTERN ".svn" EXCLUDE)
  139. install(FILES vcmibuilder DESTINATION ${BIN_DIR} PERMISSIONS
  140. OWNER_WRITE OWNER_READ OWNER_EXECUTE
  141. GROUP_READ GROUP_EXECUTE
  142. WORLD_READ WORLD_EXECUTE)
  143. endif()
  144. if(WIN32)
  145. #TODO: install any additional dll's. This version (may be broken) will copy all dll's including H3 ones
  146. #FILE(GLOB dll_files "${CMAKE_BINARY_DIR}/*.dll")
  147. #INSTALL(FILES ${dll_files} DESTINATION ${BIN_DIR})
  148. elseif(APPLE)
  149. else()
  150. #install icons and desktop file on Linux
  151. install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.64x64.png" DESTINATION share/icons/hicolor/64x64/apps RENAME vcmiclient.png)
  152. install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.48x48.png" DESTINATION share/icons/hicolor/48x48/apps RENAME vcmiclient.png)
  153. install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.32x32.png" DESTINATION share/icons/hicolor/32x32/apps RENAME vcmiclient.png)
  154. install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.256x256.png" DESTINATION share/icons/hicolor/256x256/apps RENAME vcmiclient.png)
  155. install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.desktop" DESTINATION share/applications)
  156. endif()
  157. #######################################
  158. # Packaging section #
  159. #######################################
  160. set(CPACK_PACKAGE_VERSION_MAJOR ${VCMI_VERSION_MAJOR})
  161. set(CPACK_PACKAGE_VERSION_MINOR ${VCMI_VERSION_MINOR})
  162. set(CPACK_PACKAGE_VERSION_PATCH ${VCMI_VERSION_PATCH})
  163. # vcmi does not have "patch version" in version string
  164. set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
  165. #TODO: remove version from Global.h and use this one as define?
  166. set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
  167. if(WIN32)
  168. set(CPACK_GENERATOR ZIP) # just use zip? CPack has some GUI install as well
  169. elseif(APPLE)
  170. set(CPACK_GENERATOR DragNDrop)
  171. set(CPACK_DMG_BACKGROUND_IMAGE "${CMAKE_SOURCE_DIR}/osx/dmg_background.png")
  172. set(CPACK_DMG_DS_STORE "${CMAKE_SOURCE_DIR}/osx/dmg_DS_Store")
  173. else()
  174. set(CPACK_GENERATOR TGZ)
  175. endif()
  176. INCLUDE(CPack)