CMakeLists.txt 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  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. set( SOURCECODE
  188. "#include <sys/time.h>\n"
  189. "#include <time.h>\n"
  190. "#include <unistd.h>\n"
  191. "int main(int argc, char** argv){\n"
  192. " struct timespec tval;\n"
  193. " return clock_gettime(CLOCK_MONOTONIC, &tval);\n"
  194. "}\n"
  195. )
  196. find_library( RT_LIBRARY rt )# (optional, rt on Debian)
  197. mark_as_advanced( RT_LIBRARY )
  198. set( CMAKE_REQUIRED_LIBRARIES ${GLOBAL_LIBRARIES} ${RT_LIBRARY} )
  199. CHECK_C_SOURCE_RUNS( "${SOURCECODE}" HAVE_MONOTONIC_CLOCK )
  200. if( HAVE_MONOTONIC_CLOCK )
  201. message( STATUS "Check for monotonic clock - yes" )
  202. set_property( CACHE GLOBAL_LIBRARIES PROPERTY VALUE ${GLOBAL_LIBRARIES} ${RT_LIBRARY} )
  203. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DHAVE_MONOTONIC_CLOCK" )
  204. else()
  205. message( STATUS "Check for monotonic clock - no" )
  206. endif()
  207. #
  208. # Test if function exists:
  209. # setrlimit - used to set the socket limit
  210. # strnlen - string length with upper scan bound
  211. # getpid - process id
  212. # gettid - thread id
  213. #
  214. CHECK_FUNCTION_EXISTS( setrlimit HAVE_SETRLIMIT )
  215. CHECK_FUNCTION_EXISTS( strnlen HAVE_STRNLEN )
  216. CHECK_FUNCTION_EXISTS( getpid HAVE_GETPID )
  217. CHECK_FUNCTION_EXISTS( gettid HAVE_GETTID )
  218. foreach( define HAVE_SETRLIMIT HAVE_STRNLEN HAVE_GETPID HAVE_GETTID )
  219. if( ${define} )
  220. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -D${define}" )
  221. endif()
  222. endforeach()
  223. #
  224. # Use RDTSC instruction as a timing source (time stamp counter on x86 since Pentium) (default=OFF)
  225. #
  226. # Enable it when you've timing issues. (ex: in conjunction with XEN or Other Virtualization mechanisms)
  227. # Please ensure that you've disabled dynamic CPU-Frequencys, such as power saving options.
  228. # (On the most modern Dedicated Servers cpufreq is preconfigured, see your distribution's manual how to disable it)
  229. #
  230. option( ENABLE_RDTSC "use RDTSC instruction as a timing source (default=OFF)" OFF )
  231. if( ENABLE_RDTSC )
  232. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DENABLE_RDTSC" )
  233. message( STATUS "Enabled RDTSC as a timing source" )
  234. endif()
  235. #
  236. # Enable extra debug code (default=OFF)
  237. #
  238. option( ENABLE_EXTRA_DEBUG_CODE "enable extra debug code (default=OFF)" OFF )
  239. if( ENABLE_EXTRA_DEBUG_CODE )
  240. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DDEBUG" )
  241. message( STATUS "Enabled extra DEBUG code" )
  242. endif()
  243. #
  244. # Enable builtin memory manager (default=default)
  245. #
  246. set( MEMMGR_OPTIONS "default;yes;no" )
  247. set( ENABLE_MEMMGR "default" CACHE STRING "enable builtin memory manager: ${MEMMGR_OPTIONS} (default=default)" )
  248. set_property( CACHE ENABLE_MEMMGR PROPERTY STRINGS ${MEMMGR_OPTIONS} )
  249. if( ENABLE_MEMMGR STREQUAL "default" )
  250. # use source code default
  251. elseif( ENABLE_MEMMGR STREQUAL "yes" )
  252. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DUSE_MEMMGR" )
  253. message( STATUS "Enabled the builtin memory manager" )
  254. elseif( ENABLE_MEMMGR STREQUAL "no" )
  255. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DNO_MEMMGR" )
  256. message( STATUS "Disabled the builtin memory manager" )
  257. else()
  258. message( FATAL_ERROR "invalid option ENABLE_MEMMGR=${ENABLE_MEMMGR} (valid options: ${MEMMGR_OPTIONS})" )
  259. endif()
  260. #
  261. # Enable memory library (default=system)
  262. #
  263. set( MEMORY_OPTIONS "system;memwatch;dmalloc;gcollect" )
  264. set( ENABLE_MEMORY "system" CACHE STRING "enable memory library: ${MEMORY_OPTIONS} (default=system)" )
  265. set_property( CACHE ENABLE_MEMORY PROPERTY STRINGS ${MEMORY_OPTIONS} )
  266. if( ENABLE_MEMORY STREQUAL "system" )
  267. # use system functions
  268. elseif( ENABLE_MEMORY STREQUAL "memwatch" )
  269. CHECK_INCLUDE_FILE( memwatch.h HAVE_MEMWATCH_H )
  270. find_library( MEMWATCH_LIBRARY memwatch )
  271. mark_as_advanced( MEMWATCH_LIBRARY )
  272. if( HAVE_MEMWATCH_H AND MEMWATCH_LIBRARY )
  273. message( STATUS "Adding global library: ${MEMWATCH_LIBRARY}" )
  274. set_property( CACHE GLOBAL_LIBRARIES PROPERTY VALUE ${GLOBAL_LIBRARIES} ${MEMWATCH_LIBRARY} )
  275. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DMEMWATCH" )
  276. message( STATUS "Enabled the memory library memwatch" )
  277. else()
  278. message( FATAL_ERROR "Failed to enable the memory library memwatch" )
  279. endif()
  280. elseif( ENABLE_MEMORY STREQUAL "dmalloc" )
  281. CHECK_INCLUDE_FILE( dmalloc.h HAVE_DMALLOC_H )
  282. find_library( DMALLOC_LIBRARY dmalloc )
  283. mark_as_advanced( DMALLOC_LIBRARY )
  284. if( HAVE_DMALLOC_H AND DMALLOC_LIBRARY )
  285. message( STATUS "Adding global library: ${DMALLOC_LIBRARY}" )
  286. set_property( CACHE GLOBAL_LIBRARIES PROPERTY VALUE ${GLOBAL_LIBRARIES} ${DMALLOC_LIBRARY} )
  287. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DDMALLOC -DDMALLOC_FUNC_CHECK" )
  288. message( STATUS "Enabled the memory library dmalloc" )
  289. else()
  290. message( FATAL_ERROR "Failed to enable the memory library dmalloc" )
  291. endif()
  292. elseif( ENABLE_MEMORY STREQUAL "gcollect" )
  293. CHECK_INCLUDE_FILE( gc.h HAVE_GC_H )
  294. find_library( GC_LIBRARY gc )
  295. mark_as_advanced( GC_LIBRARY )
  296. if( HAVE_GC_H AND GC_LIBRARY )
  297. message( STATUS "Adding global library: ${GC_LIBRARY}" )
  298. set_property( CACHE GLOBAL_LIBRARIES PROPERTY VALUE ${GLOBAL_LIBRARIES} ${GC_LIBRARY} )
  299. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DGCOLLECT" )
  300. message( STATUS "Enabled the memory library gcollect" )
  301. else()
  302. message( FATAL_ERROR "Failed to enable the memory library gcollect" )
  303. endif()
  304. else()
  305. message( FATAL_ERROR "invalid option ENABLE_MEMORY=${ENABLE_MEMORY} (valid options: ${MEMORY_OPTIONS})" )
  306. endif()
  307. #
  308. # Enable profiler (default=none)
  309. #
  310. set( PROFILER_OPTIONS "none;gprof" )
  311. set( ENABLE_PROFILER "none" CACHE STRING "enable profiler: ${PROFILER_OPTIONS} (default=none)" )
  312. set_property( CACHE ENABLE_PROFILER PROPERTY STRINGS ${PROFILER_OPTIONS} )
  313. if( ENABLE_PROFILER STREQUAL "none" )
  314. # no profiler
  315. elseif( ENABLE_PROFILER STREQUAL "gprof" )
  316. if( CMAKE_C_COMPILER_ID STREQUAL "GNU" )
  317. if( NOT HAVE_GPROF_FLAGS )
  318. set_property( CACHE CMAKE_C_FLAGS PROPERTY VALUE "${CMAKE_C_FLAGS} -pg" )
  319. set_property( CACHE CMAKE_EXE_LINKER_FLAGS PROPERTY VALUE "${CMAKE_EXE_LINKER_FLAGS} -pg" )
  320. set( HAVE_GPROF_FLAGS ON CACHE INTERNAL "" )
  321. endif()
  322. message( STATUS "Enabled the profiler gprof" )
  323. else()
  324. message( FATAL_ERROR "Failed to enable the profiler gprof - not GNU" )
  325. endif()
  326. else()
  327. message( FATAL_ERROR "invalid option ENABLE_PROFILER=${ENABLE_PROFILER} (valid options: ${PROFILER_OPTIONS})" )
  328. endif()
  329. #
  330. # Enable extra buildbot code (default=OFF)
  331. #
  332. option( ENABLE_EXTRA_BUILDBOT_CODE "enable extra buildbot code (default=OFF)" OFF )
  333. if( ENABLE_EXTRA_BUILDBOT_CODE )
  334. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DBUILDBOT" )
  335. message( STATUS "Enabled extra BUILDBOT code" )
  336. endif()
  337. #####################################################################
  338. # package stuff
  339. #
  340. set( CPACK_PACKAGE_NAME "rAthena" )
  341. set( CPACK_PACKAGE_DESCRIPTION_SUMMARY "MMORPG server package" )
  342. set( CPACK_PACKAGE_VERSION ${SVNVERSION} )
  343. set( CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE )
  344. #set( CPACK_MONOLITHIC_INSTALL ON )
  345. include( CPACK OPTIONAL RESULT_VARIABLE HAVE_CPACK )
  346. if( HAVE_CPACK )
  347. option( WITH_CPACK "enable building packages with CPack ('package' target)" ON )
  348. endif()
  349. if( NOT WITH_CPACK )
  350. # empty replacements
  351. macro( cpack_add_component_group )
  352. endmacro()
  353. macro( cpack_add_component )
  354. endmacro()
  355. message( STATUS "Disabled package creation" )
  356. endif()
  357. set( Runtime "Runtime files" CACHE INTERNAL "" )
  358. set( Runtime_base "configurations, dbs, npcs, docs, ..." CACHE INTERNAL "" )
  359. set( Runtime_templates "conf/import and save (generated from conf/import-tmpl and save-tmpl)" CACHE INTERNAL "" )
  360. cpack_add_component_group( Runtime DESCRIPTION ${Runtime} DISPLAY_NAME "Runtime" )
  361. cpack_add_component( Runtime_base DESCRIPTION ${Runtime_base} DISPLAY_NAME "Base files" GROUP Runtime )
  362. cpack_add_component( Runtime_templates DESCRIPTION ${Runtime_templates} DISPLAY_NAME "Base templates" GROUP Runtime )
  363. set( Development "Development files" CACHE INTERNAL "" )
  364. set( Development_base "projects, 3rdparty, sources, templates" CACHE INTERNAL "" )
  365. cpack_add_component_group( Development DESCRIPTION ${Development} DISPLAY_NAME "Development" )
  366. cpack_add_component( Development_base DESCRIPTION ${Development_base} DISPLAY_NAME "Base files" GROUP Development )
  367. #
  368. # install stuff
  369. #
  370. option( INSTALL_COMPONENT_RUNTIME "install/package files needed to run the project" ON )
  371. option( INSTALL_COMPONENT_DEVELOPMENT "install/package files needed to build the project" OFF )
  372. option( INSTALL_TO_PATH "copy files to INSTALL_PATH" OFF )
  373. option( INSTALL_TO_SOURCE "copy files to source directory, skips what is already there (${CMAKE_CURRENT_SOURCE_DIR})" OFF )
  374. option( INSTALL_TO_SUBDIR "copy files to subdirectory (${CMAKE_CURRENT_BINARY_DIR}/install)" OFF )
  375. set( INSTALL_PATH "${CMAKE_INSTALL_PREFIX}" CACHE STRING "install path (only used when INSTALL_TO_PATH is set)" )
  376. mark_as_advanced( CMAKE_INSTALL_PREFIX )
  377. if( INSTALL_TO_PATH AND NOT ("${INSTALL_TO}" STREQUAL "path") )# changed to path
  378. set_property( CACHE INSTALL_TO_SOURCE INSTALL_TO_SUBDIR PROPERTY VALUE OFF )
  379. elseif( INSTALL_TO_SOURCE AND NOT ("${INSTALL_TO}" STREQUAL "source") )# changed to source
  380. set_property( CACHE INSTALL_TO_PATH INSTALL_TO_SUBDIR PROPERTY VALUE OFF )
  381. elseif( INSTALL_TO_SUBDIR AND NOT ("${INSTALL_TO}" STREQUAL "subdir") )# changed to subdir
  382. set_property( CACHE INSTALL_TO_PATH INSTALL_TO_SOURCE PROPERTY VALUE OFF )
  383. elseif( NOT INSTALL_TO_PATH AND NOT INSTALL_TO_SOURCE AND NOT INSTALL_TO_SUBDIR )# default
  384. set_property( CACHE INSTALL_TO_SUBDIR PROPERTY VALUE ON )
  385. endif()
  386. if( INSTALL_TO_PATH )
  387. set( INSTALL_TO "path" CACHE INTERNAL "" )
  388. set_property( CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "${INSTALL_PATH}" )
  389. elseif( INSTALL_TO_SOURCE )
  390. set( INSTALL_TO "source" CACHE INTERNAL "" )
  391. set_property( CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "${CMAKE_CURRENT_SOURCE_DIR}" )
  392. elseif( INSTALL_TO_SUBDIR )
  393. set( INSTALL_TO "subdir" CACHE INTERNAL "" )
  394. set_property( CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "${CMAKE_CURRENT_BINARY_DIR}/install" )
  395. endif()
  396. set( SVN_FOLDER_PATTERN "[\\.]svn" CACHE STRING "pattern of svn folder that we exclude from instalations" )
  397. mark_as_advanced( SVN_FOLDER_PATTERN )
  398. set( DEVELOPMENT_FILES
  399. "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt"
  400. "${CMAKE_CURRENT_SOURCE_DIR}/configure"
  401. "${CMAKE_CURRENT_SOURCE_DIR}/configure.in"
  402. "${CMAKE_CURRENT_SOURCE_DIR}/rAthena-9.sln"
  403. "${CMAKE_CURRENT_SOURCE_DIR}/rAthena-10.sln"
  404. )
  405. set( DEVELOPMENT_DIRECTORIES
  406. "3rdparty"
  407. "conf/import-tmpl"
  408. "src"
  409. "vcproj-9"
  410. "vcproj-10"
  411. )
  412. set( RUNTIME_FILES
  413. "${CMAKE_CURRENT_SOURCE_DIR}/athena-start"
  414. "${CMAKE_CURRENT_SOURCE_DIR}/char-server.sh"
  415. "${CMAKE_CURRENT_SOURCE_DIR}/charserv-sql.bat"
  416. "${CMAKE_CURRENT_SOURCE_DIR}/dbghelp.dll"
  417. "${CMAKE_CURRENT_SOURCE_DIR}/libmysql.dll"
  418. "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE"
  419. "${CMAKE_CURRENT_SOURCE_DIR}/login-server.sh"
  420. "${CMAKE_CURRENT_SOURCE_DIR}/logserv-sql.bat"
  421. "${CMAKE_CURRENT_SOURCE_DIR}/map-server.sh"
  422. "${CMAKE_CURRENT_SOURCE_DIR}/mapserv-sql.bat"
  423. "${CMAKE_CURRENT_SOURCE_DIR}/notice.txt"
  424. "${CMAKE_CURRENT_SOURCE_DIR}/pcre3.dll"
  425. "${CMAKE_CURRENT_SOURCE_DIR}/readme.html"
  426. "${CMAKE_CURRENT_SOURCE_DIR}/runserver-sql.bat"
  427. "${CMAKE_CURRENT_SOURCE_DIR}/serv.bat"
  428. "${CMAKE_CURRENT_SOURCE_DIR}/start"
  429. "${CMAKE_CURRENT_SOURCE_DIR}/zlib1.dll"
  430. )
  431. set( RUNTIME_DIRECTORIES
  432. "conf"
  433. "db"
  434. "doc"
  435. "log"
  436. "npc"
  437. "plugins"
  438. "readme"
  439. "sql-files"
  440. "tools"
  441. )
  442. if( INSTALL_TO_SOURCE )# skip, already in the source dir
  443. else()
  444. if( INSTALL_COMPONENT_RUNTIME )
  445. install( FILES ${RUNTIME_FILES}
  446. DESTINATION "."
  447. COMPONENT Runtime_base )
  448. foreach( DIR IN ITEMS ${RUNTIME_DIRECTORIES} )
  449. if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${DIR}/" )
  450. install( DIRECTORY "${DIR}/"
  451. DESTINATION "${DIR}"
  452. COMPONENT Runtime_base
  453. PATTERN ${SVN_FOLDER_PATTERN} EXCLUDE
  454. PATTERN "conf/import-tmpl" EXCLUDE )
  455. else()
  456. # create empty directory
  457. install( CODE "file(MAKE_DIRECTORY \"\${ENV}\${CMAKE_INSTALL_PREFIX}/${DIR}\")"
  458. COMPONENT Runtime_base )
  459. endif()
  460. endforeach()
  461. endif( INSTALL_COMPONENT_RUNTIME )
  462. if( INSTALL_COMPONENT_DEVELOPMENT )
  463. install( FILES ${DEVELOPMENT_FILES}
  464. DESTINATION "."
  465. COMPONENT Development_base )
  466. foreach( DIR IN ITEMS ${DEVELOPMENT_DIRECTORIES} )
  467. install( DIRECTORY "${DIR}/"
  468. DESTINATION "${DIR}"
  469. COMPONENT Development_base
  470. PATTERN ${SVN_FOLDER_PATTERN} EXCLUDE )
  471. endforeach()
  472. endif( INSTALL_COMPONENT_DEVELOPMENT )
  473. endif()
  474. if( INSTALL_COMPONENT_RUNTIME )
  475. # templates
  476. set( _TEMPLATES
  477. "conf/import-tmpl" "conf/import"
  478. )
  479. set( INSTALL_TEMPLATES_FILE "${CMAKE_CURRENT_BINARY_DIR}/InstallTemplates.cmake" )
  480. file( WRITE "${INSTALL_TEMPLATES_FILE}"
  481. "macro( INSTALL_TEMPLATE _SRC _DST )\n"
  482. " set( SRC \"${CMAKE_CURRENT_SOURCE_DIR}/\${_SRC}\" )\n"
  483. " set( DST \"\${CMAKE_INSTALL_PREFIX}/\${_DST}\" )\n"
  484. " if( EXISTS \"\${DST}\" )\n"
  485. " message( \"-- Already exists: \${DST}\" )\n"
  486. " else()\n"
  487. " message( \"-- Installing template: \${DST}\" )\n"
  488. " execute_process( COMMAND \"${CMAKE_COMMAND}\" -E copy \"\${SRC}\" \"\${DST}\" )\n"
  489. " endif()\n"
  490. "endmacro()\n"
  491. )
  492. while( _TEMPLATES )
  493. list( GET _TEMPLATES 0 _SRC )
  494. list( GET _TEMPLATES 1 _DST )
  495. list( REMOVE_AT _TEMPLATES 0 1 )
  496. if( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_SRC}" )
  497. file( GLOB _PATHS "${CMAKE_CURRENT_SOURCE_DIR}/${_SRC}/*" )
  498. foreach( _PATH IN ITEMS ${_PATHS} )
  499. string( REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/${_SRC}/" "" _PATH "${_PATH}" )
  500. if( NOT "${_PATH}" MATCHES "${SVN_FOLDER_PATTERN}" )
  501. list( APPEND _TEMPLATES "${_SRC}/${_PATH}" "${_DST}/${_PATH}" )
  502. endif()
  503. endforeach()
  504. else()
  505. file( APPEND "${INSTALL_TEMPLATES_FILE}" "INSTALL_TEMPLATE( \"${_SRC}\" \"${_DST}\" )\n" )
  506. endif()
  507. endwhile()
  508. install( SCRIPT "${INSTALL_TEMPLATES_FILE}"
  509. COMPONENT Runtime_templates )
  510. endif( INSTALL_COMPONENT_RUNTIME )
  511. #
  512. # sources
  513. #
  514. set( TARGET_LIST CACHE INTERNAL "" )
  515. add_subdirectory( 3rdparty )
  516. add_subdirectory( src )
  517. #####################################################################
  518. # final checks and warnings
  519. #
  520. if( CMAKE_SIZEOF_VOID_P EQUAL 8 )
  521. message( WARNING "64bit should work, but is not recommended." )
  522. elseif( NOT CMAKE_SIZEOF_VOID_P EQUAL 4 )
  523. message( FATAL_ERROR "unexpected architecture (CMAKE_SIZEOF_VOID_P is ${CMAKE_SIZEOF_VOID_P})" )
  524. endif()
  525. list( LENGTH TARGET_LIST _LEN )
  526. if( _LEN EQUAL 0 )
  527. message( FATAL_ERROR "no targets available" )
  528. endif()
  529. message( STATUS "Available targets:" )
  530. foreach( _TARGET IN ITEMS ${TARGET_LIST} )
  531. message( STATUS "\t${_TARGET}" )
  532. endforeach()