CMakeLists.txt 21 KB

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