CMakeLists.txt 22 KB

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