CMakeLists.txt 22 KB

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