CMakeLists.txt 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. #####################################################################
  2. #
  3. # "Getting Started with CMake", a tutorial video by Eric Wing.
  4. # Part 1 of 6: http://www.youtube.com/watch?v=CLvZTyji_Uw
  5. # Part 2 of 6: http://www.youtube.com/watch?v=gUW-RrRQjEg
  6. # Part 3 of 6: http://www.youtube.com/watch?v=sz6cPhbuTk4
  7. # Part 4 of 6: http://www.youtube.com/watch?v=JICZOkyNXbg
  8. # Part 5 of 6: http://www.youtube.com/watch?v=lAiuLHy4dCk
  9. # Part 6 of 6: http://www.youtube.com/watch?v=fAtJNzDZdH8
  10. #
  11. # You can use notepad++ for syntax highlighting.
  12. # Naming conventions:
  13. # WITH_* : option to use an external package or not
  14. # ENABLE_* : option to use an internal feature/code or not
  15. # HAVE_* : internal variable indicating if we have and are using something
  16. #
  17. #####################################################################
  18. #cmake_minimum_required( VERSION 2.8.4 )
  19. # Functional changes from 2.8.3 to 2.8.4:
  20. # string(SUBSTRING) works with length -1 as "rest of string"
  21. # changes to some CPack generators
  22. # CYGWIN no longer defines WIN32
  23. # CMP0017: Prefer files from the CMake module directory when including from there.
  24. set( CMAKE_LEGACY_CYGWIN_WIN32 0 )
  25. cmake_minimum_required( VERSION 2.8.3 )
  26. project( rAthena C )
  27. if( CYGWIN )
  28. unset( WIN32 )
  29. endif()
  30. #
  31. # Prevent building in the source directory by default
  32. #
  33. if( ALLOW_SAME_DIRECTORY )
  34. elseif( "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}" )
  35. option( ALLOW_SAME_DIRECTORY "Allow CMake to build in the source directory." OFF )
  36. message( FATAL_ERROR
  37. "Do not use the source directory to build your files, instead delete CMakeCache.txt, create a separate folder and build there.\n"
  38. "Example: (build in subdir 'build' and install to source dir)\n"
  39. " rm -f CMakeCache.txt\n"
  40. " mkdir build\n"
  41. " cd build\n"
  42. " cmake -G\"Unix Makefiles\" -DINSTALL_TO_SOURCE=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo ..\n"
  43. " make install\n"
  44. " cd ..\n"
  45. " rm -rf build\n"
  46. "To skip this check, set ALLOW_SAME_DIRECTORY to ON (-DALLOW_SAME_DIRECTORY=ON)" )
  47. endif()
  48. #
  49. # Global stuff
  50. #
  51. set( GLOBAL_LIBRARIES ${LINK_LIBRARIES} CACHE INTERNAL "" )# list (comma separated values)
  52. set( GLOBAL_INCLUDE_DIRS ${INCLUDE_DIRECTORIES} CACHE INTERNAL "" )# list (comma separated values)
  53. set( GLOBAL_DEFINITIONS ${COMPILE_DEFINITIONS} CACHE INTERNAL "" )# string (space separated values -DFOO=bar)
  54. mark_as_advanced( GLOBAL_LIBRARIES GLOBAL_INCLUDE_DIRS GLOBAL_DEFINITIONS )
  55. if( WIN32 )
  56. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DFD_SETSIZE=4096" )
  57. endif()
  58. if( MSVC )
  59. set_property( CACHE GLOBAL_LIBRARIES PROPERTY VALUE ${GLOBAL_LIBRARIES} "oldnames.lib" "ws2_32.lib" )
  60. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE" )
  61. endif()
  62. #
  63. # 3rd party
  64. #
  65. set( CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/cmake CACHE INTERNAL "" )
  66. include( CheckCSourceCompiles )
  67. include( CheckCSourceRuns )
  68. include( CheckIncludeFile )
  69. include( CheckFunctionExists )
  70. include( FindFunctionLibrary )
  71. include( TestBigEndian )
  72. #
  73. # Find svnversion
  74. #
  75. message( STATUS "Detecting svnversion" )
  76. find_program( SVNVERSION_EXECUTABLE svnversion )
  77. mark_as_advanced( SVNVERSION_EXECUTABLE )
  78. if( SVNVERSION_EXECUTABLE )
  79. message( STATUS "Found svnversion: ${SVNVERSION_EXECUTABLE}" )
  80. endif()
  81. message( STATUS "Detecting svnversion - done" )
  82. #
  83. # Find Subversion
  84. #
  85. message( STATUS "Detecting Subversion" )
  86. find_package( Subversion )
  87. message( STATUS "Detecting Subversion - done" )
  88. #
  89. # PACKETVER
  90. #
  91. set( PACKETVER CACHE STRING "Sets the PACKETVER define of the servers. (see src/common/mmo.h)" )
  92. if( PACKETVER )
  93. list( APPEND GLOBAL_DEFINITIONS PACKETVER=${PACKETVER} )
  94. endif()
  95. #
  96. # SVNVERSION
  97. #
  98. if( SVNVERSION_EXECUTABLE )
  99. message( STATUS "Getting svn version" )
  100. execute_process( COMMAND ${SVNVERSION_EXECUTABLE} ${PROJECT_SOURCE_DIR}
  101. OUTPUT_VARIABLE SVNVERSION
  102. OUTPUT_STRIP_TRAILING_WHITESPACE )
  103. if( SVNVERSION MATCHES "^Unversioned" )
  104. set( SVNVERSION )
  105. endif()
  106. string( REGEX REPLACE "[^1234567890MSexported]" "_" SVNVERSION "${SVNVERSION}" )
  107. message( STATUS "Found version: ${SVNVERSION}" )
  108. message( STATUS "Getting svn version - done" )
  109. endif()
  110. if( Subversion_FOUND AND SVNVERSION )
  111. message( STATUS "Getting svn branch" )
  112. Subversion_WC_INFO( ${PROJECT_SOURCE_DIR} rAthena )
  113. if( rAthena_WC_URL )
  114. string( REGEX MATCH "[^/]+$" BRANCH ${rAthena_WC_URL} )
  115. set( SVNVERSION "${BRANCH}-${SVNVERSION}" )
  116. message( STATUS "Found branch: ${BRANCH}" )
  117. endif()
  118. message( STATUS "Getting svn branch - done" )
  119. endif()
  120. #
  121. # math library (FreeBSD/Linux/Solaris)
  122. #
  123. message( STATUS "Detecting math library (m)" )
  124. CHECK_INCLUDE_FILE( math.h HAVE_MATH_H )
  125. if( NOT HAVE_MATH_H )
  126. message( FATAL_ERROR "math.h not found" )
  127. endif()
  128. set( CMAKE_REQUIRED_LIBRARIES ${GLOBAL_LIBRARIES} )
  129. find_function_library( floor FUNCTION_FLOOR_LIBRARIES m )
  130. if( FUNCTION_FLOOR_LIBRARIES )
  131. message( STATUS "Adding global library: ${FUNCTION_FLOOR_LIBRARIES}" )
  132. set_property( CACHE GLOBAL_LIBRARIES PROPERTY VALUE ${GLOBAL_LIBRARIES} ${FUNCTION_FLOOR_LIBRARIES} )
  133. endif()
  134. message( STATUS "Detecting math library (m) - done" )
  135. #
  136. # dynamic loading library (Linux)
  137. #
  138. if( NOT WIN32 )
  139. message( STATUS "Detecting dynamic loading library (dl)" )
  140. set( CMAKE_REQUIRED_LIBRARIES ${GLOBAL_LIBRARIES} )
  141. find_function_library( dlopen FUNCTION_DLOPEN_LIBRARIES dl )
  142. if( FUNCTION_DLOPEN_LIBRARIES )
  143. message( STATUS "Adding global library: ${FUNCTION_DLOPEN_LIBRARIES}" )
  144. set_property( CACHE GLOBAL_LIBRARIES PROPERTY VALUE ${GLOBAL_LIBRARIES} ${FUNCTION_DLOPEN_LIBRARIES} )
  145. endif()
  146. message( STATUS "Detecting dynamic loading library (dl) - done" )
  147. endif()
  148. #
  149. # networking library (Solaris/MinGW)
  150. #
  151. if( NOT MSVC )
  152. message( STATUS "Detecting networking library (socket/nsl/ws2_32)" )
  153. set( CMAKE_REQUIRED_LIBRARIES ${GLOBAL_LIBRARIES} )
  154. find_function_library( bind FUNCTION_BIND_LIBRARIES socket ws2_32 )
  155. if( FUNCTION_BIND_LIBRARIES )
  156. message( STATUS "Adding global library: ${FUNCTION_BIND_LIBRARIES}" )
  157. set_property( CACHE GLOBAL_LIBRARIES PROPERTY VALUE ${GLOBAL_LIBRARIES} ${FUNCTION_BIND_LIBRARIES} )
  158. endif()
  159. set( CMAKE_REQUIRED_LIBRARIES ${GLOBAL_LIBRARIES} )
  160. find_function_library( gethostbyname FUNCTION_GETHOSTBYNAME_LIBRARIES nsl )
  161. if( FUNCTION_GETHOSTBYNAME_LIBRARIES )
  162. message( STATUS "Adding global library: ${FUNCTION_GETHOSTBYNAME_LIBRARIES}" )
  163. set_property( CACHE GLOBAL_LIBRARIES PROPERTY VALUE ${GLOBAL_LIBRARIES} ${FUNCTION_GETHOSTBYNAME_LIBRARIES} )
  164. endif()
  165. message( STATUS "Detecting networking library (socket/nsl/ws2_32) - done" )
  166. endif()
  167. #
  168. # Test for big endian
  169. #
  170. TEST_BIG_ENDIAN( BIG_ENDIAN )
  171. if( NOT DEFINED BIG_ENDIAN )
  172. message( WARNING "unable to determine endianess, only LITTLE ENDIAN is supported" )
  173. elseif( BIG_ENDIAN )
  174. message( FATAL_ERROR "bigendian is not supported" )
  175. endif()
  176. #
  177. # Test monotonic clock
  178. #
  179. # CLOCK_MONOTONIC clock for clock_gettime
  180. # Normally defines _POSIX_TIMERS > 0 and _POSIX_MONOTONIC_CLOCK (for posix
  181. # compliant systems) and __FreeBSD_cc_version >= 500005 (for FreeBSD
  182. # >= 5.1.0, which does not have the posix defines (ref. r11983)) would be
  183. # checked but some systems define them even when they do not support it
  184. # (ref. bugreport:1003).
  185. #
  186. message( STATUS "Check for monotonic clock" )
  187. find_library( RT_LIBRARY rt )# (optional, rt on Debian)
  188. mark_as_advanced( RT_LIBRARY )
  189. set( CMAKE_REQUIRED_LIBRARIES ${GLOBAL_LIBRARIES} ${RT_LIBRARY} )
  190. file( READ "${CMAKE_SOURCE_DIR}/3rdparty/cmake/tests/HAVE_MONOTONIC_CLOCK.c" _SOURCE )
  191. CHECK_C_SOURCE_RUNS( "${_SOURCE}" HAVE_MONOTONIC_CLOCK )
  192. if( HAVE_MONOTONIC_CLOCK )
  193. message( STATUS "Check for monotonic clock - yes" )
  194. set_property( CACHE GLOBAL_LIBRARIES PROPERTY VALUE ${GLOBAL_LIBRARIES} ${RT_LIBRARY} )
  195. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DHAVE_MONOTONIC_CLOCK" )
  196. else()
  197. message( STATUS "Check for monotonic clock - no" )
  198. endif()
  199. #
  200. # Test if function exists:
  201. # setrlimit - used to set the socket limit
  202. # strnlen - string length with upper scan bound
  203. # getpid - process id
  204. # gettid - thread id
  205. #
  206. CHECK_FUNCTION_EXISTS( setrlimit HAVE_SETRLIMIT )
  207. CHECK_FUNCTION_EXISTS( strnlen HAVE_STRNLEN )
  208. CHECK_FUNCTION_EXISTS( getpid HAVE_GETPID )
  209. CHECK_FUNCTION_EXISTS( gettid HAVE_GETTID )
  210. foreach( define HAVE_SETRLIMIT HAVE_STRNLEN HAVE_GETPID HAVE_GETTID )
  211. if( ${define} )
  212. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -D${define}" )
  213. endif()
  214. endforeach()
  215. #
  216. # Use RDTSC instruction as a timing source (time stamp counter on x86 since Pentium) (default=OFF)
  217. #
  218. # Enable it when you've timing issues. (ex: in conjunction with XEN or Other Virtualization mechanisms)
  219. # Please ensure that you've disabled dynamic CPU-Frequencys, such as power saving options.
  220. # (On the most modern Dedicated Servers cpufreq is preconfigured, see your distribution's manual how to disable it)
  221. #
  222. option( ENABLE_RDTSC "use RDTSC instruction as a timing source (default=OFF)" OFF )
  223. if( ENABLE_RDTSC )
  224. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DENABLE_RDTSC" )
  225. message( STATUS "Enabled RDTSC as a timing source" )
  226. endif()
  227. #
  228. # Enable extra debug code (default=OFF)
  229. #
  230. option( ENABLE_EXTRA_DEBUG_CODE "enable extra debug code (default=OFF)" OFF )
  231. if( ENABLE_EXTRA_DEBUG_CODE )
  232. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DDEBUG" )
  233. message( STATUS "Enabled extra DEBUG code" )
  234. endif()
  235. #
  236. # Enable builtin memory manager (default=default)
  237. #
  238. set( MEMMGR_OPTIONS "default;yes;no" )
  239. set( ENABLE_MEMMGR "default" CACHE STRING "enable builtin memory manager: ${MEMMGR_OPTIONS} (default=default)" )
  240. set_property( CACHE ENABLE_MEMMGR PROPERTY STRINGS ${MEMMGR_OPTIONS} )
  241. if( ENABLE_MEMMGR STREQUAL "default" )
  242. # use source code default
  243. elseif( ENABLE_MEMMGR STREQUAL "yes" )
  244. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DUSE_MEMMGR" )
  245. message( STATUS "Enabled the builtin memory manager" )
  246. elseif( ENABLE_MEMMGR STREQUAL "no" )
  247. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DNO_MEMMGR" )
  248. message( STATUS "Disabled the builtin memory manager" )
  249. else()
  250. message( FATAL_ERROR "invalid option ENABLE_MEMMGR=${ENABLE_MEMMGR} (valid options: ${MEMMGR_OPTIONS})" )
  251. endif()
  252. #
  253. # Enable memory library (default=system)
  254. #
  255. set( MEMORY_OPTIONS "system;memwatch;dmalloc;gcollect" )
  256. set( ENABLE_MEMORY "system" CACHE STRING "enable memory library: ${MEMORY_OPTIONS} (default=system)" )
  257. set_property( CACHE ENABLE_MEMORY PROPERTY STRINGS ${MEMORY_OPTIONS} )
  258. if( ENABLE_MEMORY STREQUAL "system" )
  259. # use system functions
  260. elseif( ENABLE_MEMORY STREQUAL "memwatch" )
  261. CHECK_INCLUDE_FILE( memwatch.h HAVE_MEMWATCH_H )
  262. find_library( MEMWATCH_LIBRARY memwatch )
  263. mark_as_advanced( MEMWATCH_LIBRARY )
  264. if( HAVE_MEMWATCH_H AND MEMWATCH_LIBRARY )
  265. message( STATUS "Adding global library: ${MEMWATCH_LIBRARY}" )
  266. set_property( CACHE GLOBAL_LIBRARIES PROPERTY VALUE ${GLOBAL_LIBRARIES} ${MEMWATCH_LIBRARY} )
  267. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DMEMWATCH" )
  268. message( STATUS "Enabled the memory library memwatch" )
  269. else()
  270. message( FATAL_ERROR "Failed to enable the memory library memwatch" )
  271. endif()
  272. elseif( ENABLE_MEMORY STREQUAL "dmalloc" )
  273. CHECK_INCLUDE_FILE( dmalloc.h HAVE_DMALLOC_H )
  274. find_library( DMALLOC_LIBRARY dmalloc )
  275. mark_as_advanced( DMALLOC_LIBRARY )
  276. if( HAVE_DMALLOC_H AND DMALLOC_LIBRARY )
  277. message( STATUS "Adding global library: ${DMALLOC_LIBRARY}" )
  278. set_property( CACHE GLOBAL_LIBRARIES PROPERTY VALUE ${GLOBAL_LIBRARIES} ${DMALLOC_LIBRARY} )
  279. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DDMALLOC -DDMALLOC_FUNC_CHECK" )
  280. message( STATUS "Enabled the memory library dmalloc" )
  281. else()
  282. message( FATAL_ERROR "Failed to enable the memory library dmalloc" )
  283. endif()
  284. elseif( ENABLE_MEMORY STREQUAL "gcollect" )
  285. CHECK_INCLUDE_FILE( gc.h HAVE_GC_H )
  286. find_library( GC_LIBRARY gc )
  287. mark_as_advanced( GC_LIBRARY )
  288. if( HAVE_GC_H AND GC_LIBRARY )
  289. message( STATUS "Adding global library: ${GC_LIBRARY}" )
  290. set_property( CACHE GLOBAL_LIBRARIES PROPERTY VALUE ${GLOBAL_LIBRARIES} ${GC_LIBRARY} )
  291. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DGCOLLECT" )
  292. message( STATUS "Enabled the memory library gcollect" )
  293. else()
  294. message( FATAL_ERROR "Failed to enable the memory library gcollect" )
  295. endif()
  296. else()
  297. message( FATAL_ERROR "invalid option ENABLE_MEMORY=${ENABLE_MEMORY} (valid options: ${MEMORY_OPTIONS})" )
  298. endif()
  299. #
  300. # Enable profiler (default=none)
  301. #
  302. set( PROFILER_OPTIONS "none;gprof" )
  303. set( ENABLE_PROFILER "none" CACHE STRING "enable profiler: ${PROFILER_OPTIONS} (default=none)" )
  304. set_property( CACHE ENABLE_PROFILER PROPERTY STRINGS ${PROFILER_OPTIONS} )
  305. if( ENABLE_PROFILER STREQUAL "none" )
  306. # no profiler
  307. elseif( ENABLE_PROFILER STREQUAL "gprof" )
  308. if( CMAKE_C_COMPILER_ID STREQUAL "GNU" )
  309. if( NOT HAVE_GPROF_FLAGS )
  310. set_property( CACHE CMAKE_C_FLAGS PROPERTY VALUE "${CMAKE_C_FLAGS} -pg" )
  311. set_property( CACHE CMAKE_EXE_LINKER_FLAGS PROPERTY VALUE "${CMAKE_EXE_LINKER_FLAGS} -pg" )
  312. set( HAVE_GPROF_FLAGS ON CACHE INTERNAL "" )
  313. endif()
  314. message( STATUS "Enabled the profiler gprof" )
  315. else()
  316. message( FATAL_ERROR "Failed to enable the profiler gprof - not GNU" )
  317. endif()
  318. else()
  319. message( FATAL_ERROR "invalid option ENABLE_PROFILER=${ENABLE_PROFILER} (valid options: ${PROFILER_OPTIONS})" )
  320. endif()
  321. #
  322. # Enable extra buildbot code (default=OFF)
  323. #
  324. option( ENABLE_EXTRA_BUILDBOT_CODE "enable extra buildbot code (default=OFF)" OFF )
  325. if( ENABLE_EXTRA_BUILDBOT_CODE )
  326. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DBUILDBOT" )
  327. message( STATUS "Enabled extra BUILDBOT code" )
  328. endif()
  329. #####################################################################
  330. # package stuff
  331. #
  332. set( CPACK_PACKAGE_NAME "rAthena" )
  333. set( CPACK_PACKAGE_DESCRIPTION_SUMMARY "MMORPG server package" )
  334. set( CPACK_PACKAGE_VERSION ${SVNVERSION} )
  335. set( CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE )
  336. #set( CPACK_MONOLITHIC_INSTALL ON )
  337. include( CPACK OPTIONAL RESULT_VARIABLE HAVE_CPACK )
  338. if( HAVE_CPACK )
  339. option( WITH_CPACK "enable building packages with CPack ('package' target)" ON )
  340. endif()
  341. if( NOT WITH_CPACK )
  342. # empty replacements
  343. macro( cpack_add_component_group )
  344. endmacro()
  345. macro( cpack_add_component )
  346. endmacro()
  347. message( STATUS "Disabled package creation" )
  348. endif()
  349. set( Runtime "Runtime files" CACHE INTERNAL "" )
  350. set( Runtime_base "configurations, dbs, npcs, docs, ..." CACHE INTERNAL "" )
  351. set( Runtime_templates "conf/import and save (generated from conf/import-tmpl and save-tmpl)" CACHE INTERNAL "" )
  352. cpack_add_component_group( Runtime DESCRIPTION ${Runtime} DISPLAY_NAME "Runtime" )
  353. cpack_add_component( Runtime_base DESCRIPTION ${Runtime_base} DISPLAY_NAME "Base files" GROUP Runtime )
  354. cpack_add_component( Runtime_templates DESCRIPTION ${Runtime_templates} DISPLAY_NAME "Base templates" GROUP Runtime )
  355. set( Development "Development files" CACHE INTERNAL "" )
  356. set( Development_base "projects, 3rdparty, sources, templates" CACHE INTERNAL "" )
  357. cpack_add_component_group( Development DESCRIPTION ${Development} DISPLAY_NAME "Development" )
  358. cpack_add_component( Development_base DESCRIPTION ${Development_base} DISPLAY_NAME "Base files" GROUP Development )
  359. #
  360. # install stuff
  361. #
  362. option( INSTALL_COMPONENT_RUNTIME "install/package files needed to run the project" ON )
  363. option( INSTALL_COMPONENT_DEVELOPMENT "install/package files needed to build the project" OFF )
  364. option( INSTALL_TO_PATH "copy files to INSTALL_PATH" OFF )
  365. option( INSTALL_TO_SOURCE "copy files to source directory, skips what is already there (${CMAKE_CURRENT_SOURCE_DIR})" OFF )
  366. option( INSTALL_TO_SUBDIR "copy files to subdirectory (${CMAKE_CURRENT_BINARY_DIR}/install)" OFF )
  367. set( INSTALL_PATH "${CMAKE_INSTALL_PREFIX}" CACHE STRING "install path (only used when INSTALL_TO_PATH is set)" )
  368. mark_as_advanced( CMAKE_INSTALL_PREFIX )
  369. if( INSTALL_TO_PATH AND NOT ("${INSTALL_TO}" STREQUAL "path") )# changed to path
  370. set_property( CACHE INSTALL_TO_SOURCE INSTALL_TO_SUBDIR PROPERTY VALUE OFF )
  371. elseif( INSTALL_TO_SOURCE AND NOT ("${INSTALL_TO}" STREQUAL "source") )# changed to source
  372. set_property( CACHE INSTALL_TO_PATH INSTALL_TO_SUBDIR PROPERTY VALUE OFF )
  373. elseif( INSTALL_TO_SUBDIR AND NOT ("${INSTALL_TO}" STREQUAL "subdir") )# changed to subdir
  374. set_property( CACHE INSTALL_TO_PATH INSTALL_TO_SOURCE PROPERTY VALUE OFF )
  375. elseif( NOT INSTALL_TO_PATH AND NOT INSTALL_TO_SOURCE AND NOT INSTALL_TO_SUBDIR )# default
  376. set_property( CACHE INSTALL_TO_SUBDIR PROPERTY VALUE ON )
  377. endif()
  378. if( INSTALL_TO_PATH )
  379. set( INSTALL_TO "path" CACHE INTERNAL "" )
  380. set_property( CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "${INSTALL_PATH}" )
  381. elseif( INSTALL_TO_SOURCE )
  382. set( INSTALL_TO "source" CACHE INTERNAL "" )
  383. set_property( CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "${CMAKE_CURRENT_SOURCE_DIR}" )
  384. elseif( INSTALL_TO_SUBDIR )
  385. set( INSTALL_TO "subdir" CACHE INTERNAL "" )
  386. set_property( CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "${CMAKE_CURRENT_BINARY_DIR}/install" )
  387. endif()
  388. set( SVN_FOLDER_PATTERN "[\\.]svn" CACHE STRING "pattern of svn folder that we exclude from instalations" )
  389. mark_as_advanced( SVN_FOLDER_PATTERN )
  390. set( DEVELOPMENT_FILES
  391. "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt"
  392. "${CMAKE_CURRENT_SOURCE_DIR}/configure"
  393. "${CMAKE_CURRENT_SOURCE_DIR}/configure.in"
  394. "${CMAKE_CURRENT_SOURCE_DIR}/rAthena-9.sln"
  395. "${CMAKE_CURRENT_SOURCE_DIR}/rAthena-10.sln"
  396. )
  397. set( DEVELOPMENT_DIRECTORIES
  398. "3rdparty"
  399. "conf/import-tmpl"
  400. "src"
  401. "vcproj-9"
  402. "vcproj-10"
  403. )
  404. set( RUNTIME_FILES
  405. "${CMAKE_CURRENT_SOURCE_DIR}/athena-start"
  406. "${CMAKE_CURRENT_SOURCE_DIR}/char-server.sh"
  407. "${CMAKE_CURRENT_SOURCE_DIR}/charserv-sql.bat"
  408. "${CMAKE_CURRENT_SOURCE_DIR}/dbghelp.dll"
  409. "${CMAKE_CURRENT_SOURCE_DIR}/libmysql.dll"
  410. "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE"
  411. "${CMAKE_CURRENT_SOURCE_DIR}/login-server.sh"
  412. "${CMAKE_CURRENT_SOURCE_DIR}/logserv-sql.bat"
  413. "${CMAKE_CURRENT_SOURCE_DIR}/map-server.sh"
  414. "${CMAKE_CURRENT_SOURCE_DIR}/mapserv-sql.bat"
  415. "${CMAKE_CURRENT_SOURCE_DIR}/notice.txt"
  416. "${CMAKE_CURRENT_SOURCE_DIR}/pcre3.dll"
  417. "${CMAKE_CURRENT_SOURCE_DIR}/readme.html"
  418. "${CMAKE_CURRENT_SOURCE_DIR}/runserver-sql.bat"
  419. "${CMAKE_CURRENT_SOURCE_DIR}/serv.bat"
  420. "${CMAKE_CURRENT_SOURCE_DIR}/start"
  421. "${CMAKE_CURRENT_SOURCE_DIR}/zlib1.dll"
  422. )
  423. set( RUNTIME_DIRECTORIES
  424. "conf"
  425. "db"
  426. "doc"
  427. "log"
  428. "npc"
  429. "plugins"
  430. "readme"
  431. "sql-files"
  432. "tools"
  433. )
  434. if( INSTALL_TO_SOURCE )# skip, already in the source dir
  435. else()
  436. if( INSTALL_COMPONENT_RUNTIME )
  437. install( FILES ${RUNTIME_FILES}
  438. DESTINATION "."
  439. COMPONENT Runtime_base )
  440. foreach( DIR IN ITEMS ${RUNTIME_DIRECTORIES} )
  441. if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${DIR}/" )
  442. install( DIRECTORY "${DIR}/"
  443. DESTINATION "${DIR}"
  444. COMPONENT Runtime_base
  445. PATTERN ${SVN_FOLDER_PATTERN} EXCLUDE
  446. PATTERN "conf/import-tmpl" EXCLUDE )
  447. else()
  448. # create empty directory
  449. install( CODE "file(MAKE_DIRECTORY \"\${ENV}\${CMAKE_INSTALL_PREFIX}/${DIR}\")"
  450. COMPONENT Runtime_base )
  451. endif()
  452. endforeach()
  453. endif( INSTALL_COMPONENT_RUNTIME )
  454. if( INSTALL_COMPONENT_DEVELOPMENT )
  455. install( FILES ${DEVELOPMENT_FILES}
  456. DESTINATION "."
  457. COMPONENT Development_base )
  458. foreach( DIR IN ITEMS ${DEVELOPMENT_DIRECTORIES} )
  459. install( DIRECTORY "${DIR}/"
  460. DESTINATION "${DIR}"
  461. COMPONENT Development_base
  462. PATTERN ${SVN_FOLDER_PATTERN} EXCLUDE )
  463. endforeach()
  464. endif( INSTALL_COMPONENT_DEVELOPMENT )
  465. endif()
  466. if( INSTALL_COMPONENT_RUNTIME )
  467. # templates
  468. set( _TEMPLATES
  469. "conf/import-tmpl" "conf/import"
  470. )
  471. set( INSTALL_TEMPLATES_FILE "${CMAKE_CURRENT_BINARY_DIR}/InstallTemplates.cmake" )
  472. file( WRITE "${INSTALL_TEMPLATES_FILE}"
  473. "macro( INSTALL_TEMPLATE _SRC _DST )\n"
  474. " set( SRC \"${CMAKE_CURRENT_SOURCE_DIR}/\${_SRC}\" )\n"
  475. " set( DST \"\${CMAKE_INSTALL_PREFIX}/\${_DST}\" )\n"
  476. " if( EXISTS \"\${DST}\" )\n"
  477. " message( \"-- Already exists: \${DST}\" )\n"
  478. " else()\n"
  479. " message( \"-- Installing template: \${DST}\" )\n"
  480. " execute_process( COMMAND \"${CMAKE_COMMAND}\" -E copy \"\${SRC}\" \"\${DST}\" )\n"
  481. " endif()\n"
  482. "endmacro()\n"
  483. )
  484. while( _TEMPLATES )
  485. list( GET _TEMPLATES 0 _SRC )
  486. list( GET _TEMPLATES 1 _DST )
  487. list( REMOVE_AT _TEMPLATES 0 1 )
  488. if( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_SRC}" )
  489. file( GLOB _PATHS "${CMAKE_CURRENT_SOURCE_DIR}/${_SRC}/*" )
  490. foreach( _PATH IN ITEMS ${_PATHS} )
  491. string( REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/${_SRC}/" "" _PATH "${_PATH}" )
  492. if( NOT "${_PATH}" MATCHES "${SVN_FOLDER_PATTERN}" )
  493. list( APPEND _TEMPLATES "${_SRC}/${_PATH}" "${_DST}/${_PATH}" )
  494. endif()
  495. endforeach()
  496. else()
  497. file( APPEND "${INSTALL_TEMPLATES_FILE}" "INSTALL_TEMPLATE( \"${_SRC}\" \"${_DST}\" )\n" )
  498. endif()
  499. endwhile()
  500. install( SCRIPT "${INSTALL_TEMPLATES_FILE}"
  501. COMPONENT Runtime_templates )
  502. endif( INSTALL_COMPONENT_RUNTIME )
  503. #
  504. # sources
  505. #
  506. set( TARGET_LIST CACHE INTERNAL "" )
  507. add_subdirectory( 3rdparty )
  508. add_subdirectory( src )
  509. #####################################################################
  510. # final checks and warnings
  511. #
  512. if( CMAKE_SIZEOF_VOID_P EQUAL 8 )
  513. message( WARNING "64bit should work, but is not recommended." )
  514. elseif( NOT CMAKE_SIZEOF_VOID_P EQUAL 4 )
  515. message( FATAL_ERROR "unexpected architecture (CMAKE_SIZEOF_VOID_P is ${CMAKE_SIZEOF_VOID_P})" )
  516. endif()
  517. list( LENGTH TARGET_LIST _LEN )
  518. if( _LEN EQUAL 0 )
  519. message( FATAL_ERROR "no targets available" )
  520. endif()
  521. message( STATUS "Available targets:" )
  522. foreach( _TARGET IN ITEMS ${TARGET_LIST} )
  523. message( STATUS "\t${_TARGET}" )
  524. endforeach()