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. #####################################################################
  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( eAthena 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} eAthena )
  110. if( eAthena_WC_URL )
  111. string( REGEX MATCH "[^/]+$" BRANCH ${eAthena_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 typecast to union
  175. #
  176. message( STATUS "Check for typecast to union" )
  177. set( SOURCECODE
  178. "typedef union Foonion{\n"
  179. " int i;\n"
  180. " unsigned int ui;\n"
  181. " const char* s;\n"
  182. "} Foonion;\n"
  183. "int get_i(Foonion onion){ return onion.i; }\n"
  184. "int main(int argc, char** argv){\n"
  185. " int i = 0;\n"
  186. " return get_i(((Foonion)(int)i));\n"
  187. "}\n"
  188. )
  189. CHECK_C_SOURCE_COMPILES( "${SOURCECODE}" HAVE_TYPECAST_TO_UNION )
  190. if( HAVE_TYPECAST_TO_UNION )
  191. message( STATUS "Check for typecast to union - yes" )
  192. else()
  193. message( STATUS "Check for typecast to union - no" )
  194. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DDB_MANUAL_CAST_TO_UNION" )
  195. endif()
  196. #
  197. # Test monotonic clock
  198. #
  199. # CLOCK_MONOTONIC clock for clock_gettime
  200. # Normally defines _POSIX_TIMERS > 0 and _POSIX_MONOTONIC_CLOCK (for posix
  201. # compliant systems) and __FreeBSD_cc_version >= 500005 (for FreeBSD
  202. # >= 5.1.0, which does not have the posix defines (ref. r11983)) would be
  203. # checked but some systems define them even when they do not support it
  204. # (ref. bugreport:1003).
  205. #
  206. message( STATUS "Check for monotonic clock" )
  207. set( SOURCECODE
  208. "#include <sys/time.h>\n"
  209. "#include <time.h>\n"
  210. "#include <unistd.h>\n"
  211. "int main(int argc, char** argv){\n"
  212. " struct timespec tval;\n"
  213. " return clock_gettime(CLOCK_MONOTONIC, &tval);\n"
  214. "}\n"
  215. )
  216. find_library( RT_LIBRARY rt )# (optional, rt on Debian)
  217. mark_as_advanced( RT_LIBRARY )
  218. set( CMAKE_REQUIRED_LIBRARIES ${GLOBAL_LIBRARIES} ${RT_LIBRARY} )
  219. CHECK_C_SOURCE_RUNS( "${SOURCECODE}" 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. # package stuff
  351. #
  352. set( CPACK_PACKAGE_NAME "eAthena" )
  353. set( CPACK_PACKAGE_DESCRIPTION_SUMMARY "MMORPG server package" )
  354. set( CPACK_PACKAGE_VERSION ${SVNVERSION} )
  355. set( CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE )
  356. #set( CPACK_MONOLITHIC_INSTALL ON )
  357. include( CPACK OPTIONAL RESULT_VARIABLE HAVE_CPACK )
  358. if( HAVE_CPACK )
  359. option( WITH_CPACK "enable building packages with CPack ('package' target)" ON )
  360. endif()
  361. if( NOT WITH_CPACK )
  362. # empty replacements
  363. macro( cpack_add_component_group )
  364. endmacro()
  365. macro( cpack_add_component )
  366. endmacro()
  367. message( STATUS "Disabled package creation" )
  368. endif()
  369. set( Runtime "Runtime files" CACHE INTERNAL "" )
  370. set( Runtime_base "configurations, dbs, npcs, docs, ..." CACHE INTERNAL "" )
  371. set( Runtime_templates "conf/import and save (generated from conf/import-tmpl and save-tmpl)" CACHE INTERNAL "" )
  372. cpack_add_component_group( Runtime DESCRIPTION ${Runtime} DISPLAY_NAME "Runtime" )
  373. cpack_add_component( Runtime_base DESCRIPTION ${Runtime_base} DISPLAY_NAME "Base files" GROUP Runtime )
  374. cpack_add_component( Runtime_templates DESCRIPTION ${Runtime_templates} DISPLAY_NAME "Base templates" GROUP Runtime )
  375. set( Development "Development files" CACHE INTERNAL "" )
  376. set( Development_base "projects, 3rdparty, sources, templates" CACHE INTERNAL "" )
  377. cpack_add_component_group( Development DESCRIPTION ${Development} DISPLAY_NAME "Development" )
  378. cpack_add_component( Development_base DESCRIPTION ${Development_base} DISPLAY_NAME "Base files" GROUP Development )
  379. #
  380. # install stuff
  381. #
  382. option( INSTALL_COMPONENT_RUNTIME "install/package files needed to run the project" ON )
  383. option( INSTALL_COMPONENT_DEVELOPMENT "install/package files needed to build the project" OFF )
  384. option( INSTALL_TO_PATH "copy files to INSTALL_PATH" OFF )
  385. option( INSTALL_TO_SOURCE "copy files to source directory, skips what is already there (${CMAKE_CURRENT_SOURCE_DIR})" OFF )
  386. option( INSTALL_TO_SUBDIR "copy files to subdirectory (${CMAKE_CURRENT_BINARY_DIR}/install)" OFF )
  387. set( INSTALL_PATH "${CMAKE_INSTALL_PREFIX}" CACHE STRING "install path (only used when INSTALL_TO_PATH is set)" )
  388. mark_as_advanced( CMAKE_INSTALL_PREFIX )
  389. if( INSTALL_TO_PATH AND NOT ("${INSTALL_TO}" STREQUAL "path") )# changed to path
  390. set_property( CACHE INSTALL_TO_SOURCE INSTALL_TO_SUBDIR PROPERTY VALUE OFF )
  391. elseif( INSTALL_TO_SOURCE AND NOT ("${INSTALL_TO}" STREQUAL "source") )# changed to source
  392. set_property( CACHE INSTALL_TO_PATH INSTALL_TO_SUBDIR PROPERTY VALUE OFF )
  393. elseif( INSTALL_TO_SUBDIR AND NOT ("${INSTALL_TO}" STREQUAL "subdir") )# changed to subdir
  394. set_property( CACHE INSTALL_TO_PATH INSTALL_TO_SOURCE PROPERTY VALUE OFF )
  395. elseif( NOT INSTALL_TO_PATH AND NOT INSTALL_TO_SOURCE AND NOT INSTALL_TO_SUBDIR )# default
  396. set_property( CACHE INSTALL_TO_SUBDIR PROPERTY VALUE ON )
  397. endif()
  398. if( INSTALL_TO_PATH )
  399. set( INSTALL_TO "path" CACHE INTERNAL "" )
  400. set_property( CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "${INSTALL_PATH}" )
  401. elseif( INSTALL_TO_SOURCE )
  402. set( INSTALL_TO "source" CACHE INTERNAL "" )
  403. set_property( CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "${CMAKE_CURRENT_SOURCE_DIR}" )
  404. elseif( INSTALL_TO_SUBDIR )
  405. set( INSTALL_TO "subdir" CACHE INTERNAL "" )
  406. set_property( CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "${CMAKE_CURRENT_BINARY_DIR}/install" )
  407. endif()
  408. set( SVN_FOLDER_PATTERN "[\\.]svn" CACHE STRING "pattern of svn folder that we exclude from instalations" )
  409. mark_as_advanced( SVN_FOLDER_PATTERN )
  410. set( DEVELOPMENT_FILES
  411. "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt"
  412. "${CMAKE_CURRENT_SOURCE_DIR}/configure"
  413. "${CMAKE_CURRENT_SOURCE_DIR}/configure.in"
  414. "${CMAKE_CURRENT_SOURCE_DIR}/eAthena-6.dsw"
  415. "${CMAKE_CURRENT_SOURCE_DIR}/eAthena-7.1.sln"
  416. "${CMAKE_CURRENT_SOURCE_DIR}/eAthena-8.sln"
  417. "${CMAKE_CURRENT_SOURCE_DIR}/eAthena-9.sln"
  418. "${CMAKE_CURRENT_SOURCE_DIR}/eAthena-10.sln"
  419. )
  420. set( DEVELOPMENT_DIRECTORIES
  421. "3rdparty"
  422. "conf/import-tmpl"
  423. "save-tmpl"
  424. "src"
  425. "vcproj-6"
  426. "vcproj-7.1"
  427. "vcproj-8"
  428. "vcproj-9"
  429. "vcproj-10"
  430. )
  431. set( RUNTIME_FILES
  432. "${CMAKE_CURRENT_SOURCE_DIR}/athena-start"
  433. "${CMAKE_CURRENT_SOURCE_DIR}/Changelog-Trunk.txt"
  434. "${CMAKE_CURRENT_SOURCE_DIR}/char-server.sh"
  435. "${CMAKE_CURRENT_SOURCE_DIR}/charserv-sql.bat"
  436. "${CMAKE_CURRENT_SOURCE_DIR}/charserv.bat"
  437. "${CMAKE_CURRENT_SOURCE_DIR}/dbghelp.dll"
  438. "${CMAKE_CURRENT_SOURCE_DIR}/libmysql.dll"
  439. "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE"
  440. "${CMAKE_CURRENT_SOURCE_DIR}/login-server.sh"
  441. "${CMAKE_CURRENT_SOURCE_DIR}/logserv-sql.bat"
  442. "${CMAKE_CURRENT_SOURCE_DIR}/logserv.bat"
  443. "${CMAKE_CURRENT_SOURCE_DIR}/map-server.sh"
  444. "${CMAKE_CURRENT_SOURCE_DIR}/mapserv-sql.bat"
  445. "${CMAKE_CURRENT_SOURCE_DIR}/mapserv.bat"
  446. "${CMAKE_CURRENT_SOURCE_DIR}/notice.txt"
  447. "${CMAKE_CURRENT_SOURCE_DIR}/pcre3.dll"
  448. "${CMAKE_CURRENT_SOURCE_DIR}/readme.html"
  449. "${CMAKE_CURRENT_SOURCE_DIR}/runserver-sql.bat"
  450. "${CMAKE_CURRENT_SOURCE_DIR}/runserver.bat"
  451. "${CMAKE_CURRENT_SOURCE_DIR}/serv.bat"
  452. "${CMAKE_CURRENT_SOURCE_DIR}/start"
  453. "${CMAKE_CURRENT_SOURCE_DIR}/zlib1.dll"
  454. )
  455. set( RUNTIME_DIRECTORIES
  456. "conf"
  457. "db"
  458. "doc"
  459. "log"
  460. "npc"
  461. "plugins"
  462. "readme"
  463. "sql-files"
  464. "tools"
  465. )
  466. if( INSTALL_TO_SOURCE )# skip, already in the source dir
  467. else()
  468. if( INSTALL_COMPONENT_RUNTIME )
  469. install( FILES ${RUNTIME_FILES}
  470. DESTINATION "."
  471. COMPONENT Runtime_base )
  472. foreach( DIR IN ITEMS ${RUNTIME_DIRECTORIES} )
  473. install( DIRECTORY "${DIR}/"
  474. DESTINATION "${DIR}"
  475. COMPONENT Runtime_base
  476. PATTERN ${SVN_FOLDER_PATTERN} EXCLUDE
  477. PATTERN "conf/import-tmpl" EXCLUDE )
  478. endforeach()
  479. endif( INSTALL_COMPONENT_RUNTIME )
  480. if( INSTALL_COMPONENT_DEVELOPMENT )
  481. install( FILES ${DEVELOPMENT_FILES}
  482. DESTINATION "."
  483. COMPONENT Development_base )
  484. foreach( DIR IN ITEMS ${DEVELOPMENT_DIRECTORIES} )
  485. install( DIRECTORY "${DIR}/"
  486. DESTINATION "${DIR}"
  487. COMPONENT Development_base
  488. PATTERN ${SVN_FOLDER_PATTERN} EXCLUDE )
  489. endforeach()
  490. endif( INSTALL_COMPONENT_DEVELOPMENT )
  491. endif()
  492. if( INSTALL_COMPONENT_RUNTIME )
  493. # templates
  494. set( _TEMPLATES
  495. "save-tmpl" "save"
  496. "conf/import-tmpl" "conf/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( src )
  535. #####################################################################
  536. # final checks and warnings
  537. #
  538. if( CMAKE_SIZEOF_VOID_P EQUAL 8 )
  539. message( WARNING "64bit should work, but is not recommended." )
  540. elseif( NOT CMAKE_SIZEOF_VOID_P EQUAL 4 )
  541. message( FATAL_ERROR "unexpected architecture (CMAKE_SIZEOF_VOID_P is ${CMAKE_SIZEOF_VOID_P})" )
  542. endif()
  543. list( LENGTH TARGET_LIST _LEN )
  544. if( _LEN EQUAL 0 )
  545. message( FATAL_ERROR "no targets available" )
  546. endif()
  547. message( STATUS "Available targets:" )
  548. foreach( _TARGET IN ITEMS ${TARGET_LIST} )
  549. message( STATUS "\t${_TARGET}" )
  550. endforeach()