CMakeLists.txt 21 KB

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