CMakeLists.txt 22 KB

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