CMakeLists.txt 23 KB

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