CMakeLists.txt 23 KB

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