CMakeLists.txt 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  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. # 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. # Test for big endian
  205. #
  206. TEST_BIG_ENDIAN( BIG_ENDIAN )
  207. if( NOT DEFINED BIG_ENDIAN )
  208. message( WARNING "unable to determine endianess, only LITTLE ENDIAN is supported" )
  209. elseif( BIG_ENDIAN )
  210. message( FATAL_ERROR "bigendian is not supported" )
  211. endif()
  212. #
  213. # Test monotonic clock
  214. #
  215. # CLOCK_MONOTONIC clock for clock_gettime
  216. # Normally defines _POSIX_TIMERS > 0 and _POSIX_MONOTONIC_CLOCK (for posix
  217. # compliant systems) and __FreeBSD_cc_version >= 500005 (for FreeBSD
  218. # >= 5.1.0, which does not have the posix defines (ref. r11983)) would be
  219. # checked but some systems define them even when they do not support it
  220. # (ref. bugreport:1003).
  221. #
  222. message( STATUS "Check for monotonic clock" )
  223. find_library( RT_LIBRARY rt )# (optional, rt on Debian)
  224. mark_as_advanced( RT_LIBRARY )
  225. set( CMAKE_REQUIRED_LIBRARIES ${GLOBAL_LIBRARIES} ${RT_LIBRARY} )
  226. file( READ "${CMAKE_SOURCE_DIR}/3rdparty/cmake/tests/HAVE_MONOTONIC_CLOCK.c" _SOURCE )
  227. CHECK_C_SOURCE_RUNS( "${_SOURCE}" HAVE_MONOTONIC_CLOCK )
  228. if( HAVE_MONOTONIC_CLOCK )
  229. message( STATUS "Check for monotonic clock - yes" )
  230. set_property( CACHE GLOBAL_LIBRARIES PROPERTY VALUE ${GLOBAL_LIBRARIES} ${RT_LIBRARY} )
  231. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DHAVE_MONOTONIC_CLOCK" )
  232. else()
  233. message( STATUS "Check for monotonic clock - no" )
  234. endif()
  235. #
  236. # Test if function exists:
  237. # setrlimit - used to set the socket limit
  238. # strnlen - string length with upper scan bound
  239. # getpid - process id
  240. # gettid - thread id
  241. #
  242. CHECK_FUNCTION_EXISTS( setrlimit HAVE_SETRLIMIT )
  243. CHECK_FUNCTION_EXISTS( strnlen HAVE_STRNLEN )
  244. CHECK_FUNCTION_EXISTS( getpid HAVE_GETPID )
  245. CHECK_FUNCTION_EXISTS( gettid HAVE_GETTID )
  246. foreach( define HAVE_SETRLIMIT HAVE_STRNLEN HAVE_GETPID HAVE_GETTID )
  247. if( ${define} )
  248. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -D${define}" )
  249. endif()
  250. endforeach()
  251. #
  252. # Use RDTSC instruction as a timing source (time stamp counter on x86 since Pentium) (default=OFF)
  253. #
  254. # Enable it when you've timing issues. (ex: in conjunction with XEN or Other Virtualization mechanisms)
  255. # Please ensure that you've disabled dynamic CPU-Frequencys, such as power saving options.
  256. # (On the most modern Dedicated Servers cpufreq is preconfigured, see your distribution's manual how to disable it)
  257. #
  258. option( ENABLE_RDTSC "use RDTSC instruction as a timing source (default=OFF)" OFF )
  259. if( ENABLE_RDTSC )
  260. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DENABLE_RDTSC" )
  261. message( STATUS "Enabled RDTSC as a timing source" )
  262. endif()
  263. #
  264. # Enable extra debug code (default=OFF)
  265. #
  266. option( ENABLE_EXTRA_DEBUG_CODE "enable extra debug code (default=OFF)" OFF )
  267. if( ENABLE_EXTRA_DEBUG_CODE )
  268. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DDEBUG" )
  269. message( STATUS "Enabled extra DEBUG code" )
  270. endif()
  271. #
  272. # Enable builtin memory manager (default=default)
  273. #
  274. set( MEMMGR_OPTIONS "default;yes;no" )
  275. set( ENABLE_MEMMGR "default" CACHE STRING "enable builtin memory manager: ${MEMMGR_OPTIONS} (default=default)" )
  276. set_property( CACHE ENABLE_MEMMGR PROPERTY STRINGS ${MEMMGR_OPTIONS} )
  277. if( ENABLE_MEMMGR STREQUAL "default" )
  278. # use source code default
  279. elseif( ENABLE_MEMMGR STREQUAL "yes" )
  280. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DUSE_MEMMGR" )
  281. message( STATUS "Enabled the builtin memory manager" )
  282. elseif( ENABLE_MEMMGR STREQUAL "no" )
  283. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DNO_MEMMGR" )
  284. message( STATUS "Disabled the builtin memory manager" )
  285. else()
  286. message( FATAL_ERROR "invalid option ENABLE_MEMMGR=${ENABLE_MEMMGR} (valid options: ${MEMMGR_OPTIONS})" )
  287. endif()
  288. #
  289. # Enable memory library (default=system)
  290. #
  291. set( MEMORY_OPTIONS "system;memwatch;dmalloc;gcollect" )
  292. set( ENABLE_MEMORY "system" CACHE STRING "enable memory library: ${MEMORY_OPTIONS} (default=system)" )
  293. set_property( CACHE ENABLE_MEMORY PROPERTY STRINGS ${MEMORY_OPTIONS} )
  294. if( ENABLE_MEMORY STREQUAL "system" )
  295. # use system functions
  296. elseif( ENABLE_MEMORY STREQUAL "memwatch" )
  297. CHECK_INCLUDE_FILE( memwatch.h HAVE_MEMWATCH_H )
  298. find_library( MEMWATCH_LIBRARY memwatch )
  299. mark_as_advanced( MEMWATCH_LIBRARY )
  300. if( HAVE_MEMWATCH_H AND MEMWATCH_LIBRARY )
  301. message( STATUS "Adding global library: ${MEMWATCH_LIBRARY}" )
  302. set_property( CACHE GLOBAL_LIBRARIES PROPERTY VALUE ${GLOBAL_LIBRARIES} ${MEMWATCH_LIBRARY} )
  303. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DMEMWATCH" )
  304. message( STATUS "Enabled the memory library memwatch" )
  305. else()
  306. message( FATAL_ERROR "Failed to enable the memory library memwatch" )
  307. endif()
  308. elseif( ENABLE_MEMORY STREQUAL "dmalloc" )
  309. CHECK_INCLUDE_FILE( dmalloc.h HAVE_DMALLOC_H )
  310. find_library( DMALLOC_LIBRARY dmalloc )
  311. mark_as_advanced( DMALLOC_LIBRARY )
  312. if( HAVE_DMALLOC_H AND DMALLOC_LIBRARY )
  313. message( STATUS "Adding global library: ${DMALLOC_LIBRARY}" )
  314. set_property( CACHE GLOBAL_LIBRARIES PROPERTY VALUE ${GLOBAL_LIBRARIES} ${DMALLOC_LIBRARY} )
  315. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DDMALLOC -DDMALLOC_FUNC_CHECK" )
  316. message( STATUS "Enabled the memory library dmalloc" )
  317. else()
  318. message( FATAL_ERROR "Failed to enable the memory library dmalloc" )
  319. endif()
  320. elseif( ENABLE_MEMORY STREQUAL "gcollect" )
  321. CHECK_INCLUDE_FILE( gc.h HAVE_GC_H )
  322. find_library( GC_LIBRARY gc )
  323. mark_as_advanced( GC_LIBRARY )
  324. if( HAVE_GC_H AND GC_LIBRARY )
  325. message( STATUS "Adding global library: ${GC_LIBRARY}" )
  326. set_property( CACHE GLOBAL_LIBRARIES PROPERTY VALUE ${GLOBAL_LIBRARIES} ${GC_LIBRARY} )
  327. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DGCOLLECT" )
  328. message( STATUS "Enabled the memory library gcollect" )
  329. else()
  330. message( FATAL_ERROR "Failed to enable the memory library gcollect" )
  331. endif()
  332. else()
  333. message( FATAL_ERROR "invalid option ENABLE_MEMORY=${ENABLE_MEMORY} (valid options: ${MEMORY_OPTIONS})" )
  334. endif()
  335. #
  336. # Enable profiler (default=none)
  337. #
  338. set( PROFILER_OPTIONS "none;gprof" )
  339. set( ENABLE_PROFILER "none" CACHE STRING "enable profiler: ${PROFILER_OPTIONS} (default=none)" )
  340. set_property( CACHE ENABLE_PROFILER PROPERTY STRINGS ${PROFILER_OPTIONS} )
  341. if( ENABLE_PROFILER STREQUAL "none" )
  342. # no profiler
  343. elseif( ENABLE_PROFILER STREQUAL "gprof" )
  344. if( CMAKE_C_COMPILER_ID STREQUAL "GNU" )
  345. if( NOT HAVE_GPROF_FLAGS )
  346. set_property( CACHE CMAKE_C_FLAGS PROPERTY VALUE "${CMAKE_C_FLAGS} -pg" )
  347. set_property( CACHE CMAKE_EXE_LINKER_FLAGS PROPERTY VALUE "${CMAKE_EXE_LINKER_FLAGS} -pg" )
  348. set( HAVE_GPROF_FLAGS ON CACHE INTERNAL "" )
  349. endif()
  350. message( STATUS "Enabled the profiler gprof" )
  351. else()
  352. message( FATAL_ERROR "Failed to enable the profiler gprof - not GNU" )
  353. endif()
  354. else()
  355. message( FATAL_ERROR "invalid option ENABLE_PROFILER=${ENABLE_PROFILER} (valid options: ${PROFILER_OPTIONS})" )
  356. endif()
  357. #
  358. # Enable extra buildbot code (default=OFF)
  359. #
  360. option( ENABLE_EXTRA_BUILDBOT_CODE "enable extra buildbot code (default=OFF)" OFF )
  361. if( ENABLE_EXTRA_BUILDBOT_CODE )
  362. set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -DBUILDBOT" )
  363. message( STATUS "Enabled extra BUILDBOT code" )
  364. endif()
  365. #####################################################################
  366. # package stuff
  367. #
  368. set( CPACK_PACKAGE_NAME "rAthena" )
  369. set( CPACK_PACKAGE_DESCRIPTION_SUMMARY "MMORPG server package" )
  370. set( CPACK_PACKAGE_VERSION ${SVNVERSION} )
  371. set( CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE )
  372. #set( CPACK_MONOLITHIC_INSTALL ON )
  373. include( CPACK OPTIONAL RESULT_VARIABLE HAVE_CPACK )
  374. if( HAVE_CPACK )
  375. option( WITH_CPACK "enable building packages with CPack ('package' target)" ON )
  376. endif()
  377. if( NOT WITH_CPACK )
  378. # empty replacements
  379. macro( cpack_add_component_group )
  380. endmacro()
  381. macro( cpack_add_component )
  382. endmacro()
  383. message( STATUS "Disabled package creation" )
  384. endif()
  385. set( Runtime "Runtime files" CACHE INTERNAL "" )
  386. set( Runtime_base "configurations, dbs, npcs, docs, ..." CACHE INTERNAL "" )
  387. set( Runtime_templates "conf/import and save (generated from conf/import-tmpl and save-tmpl)" CACHE INTERNAL "" )
  388. cpack_add_component_group( Runtime DESCRIPTION ${Runtime} DISPLAY_NAME "Runtime" )
  389. cpack_add_component( Runtime_base DESCRIPTION ${Runtime_base} DISPLAY_NAME "Base files" GROUP Runtime )
  390. cpack_add_component( Runtime_templates DESCRIPTION ${Runtime_templates} DISPLAY_NAME "Base templates" GROUP Runtime )
  391. set( Development "Development files" CACHE INTERNAL "" )
  392. set( Development_base "projects, 3rdparty, sources, templates" CACHE INTERNAL "" )
  393. cpack_add_component_group( Development DESCRIPTION ${Development} DISPLAY_NAME "Development" )
  394. cpack_add_component( Development_base DESCRIPTION ${Development_base} DISPLAY_NAME "Base files" GROUP Development )
  395. #
  396. # install stuff
  397. #
  398. option( INSTALL_COMPONENT_RUNTIME "install/package files needed to run the project" ON )
  399. option( INSTALL_COMPONENT_DEVELOPMENT "install/package files needed to build the project" OFF )
  400. option( INSTALL_TO_PATH "copy files to INSTALL_PATH" OFF )
  401. option( INSTALL_TO_SOURCE "copy files to source directory, skips what is already there (${CMAKE_CURRENT_SOURCE_DIR})" OFF )
  402. option( INSTALL_TO_SUBDIR "copy files to subdirectory (${CMAKE_CURRENT_BINARY_DIR}/install)" OFF )
  403. set( INSTALL_PATH "${CMAKE_INSTALL_PREFIX}" CACHE STRING "install path (only used when INSTALL_TO_PATH is set)" )
  404. mark_as_advanced( CMAKE_INSTALL_PREFIX )
  405. if( INSTALL_TO_PATH AND NOT ("${INSTALL_TO}" STREQUAL "path") )# changed to path
  406. set_property( CACHE INSTALL_TO_SOURCE INSTALL_TO_SUBDIR PROPERTY VALUE OFF )
  407. elseif( INSTALL_TO_SOURCE AND NOT ("${INSTALL_TO}" STREQUAL "source") )# changed to source
  408. set_property( CACHE INSTALL_TO_PATH INSTALL_TO_SUBDIR PROPERTY VALUE OFF )
  409. elseif( INSTALL_TO_SUBDIR AND NOT ("${INSTALL_TO}" STREQUAL "subdir") )# changed to subdir
  410. set_property( CACHE INSTALL_TO_PATH INSTALL_TO_SOURCE PROPERTY VALUE OFF )
  411. elseif( NOT INSTALL_TO_PATH AND NOT INSTALL_TO_SOURCE AND NOT INSTALL_TO_SUBDIR )# default
  412. set_property( CACHE INSTALL_TO_SUBDIR PROPERTY VALUE ON )
  413. endif()
  414. if( INSTALL_TO_PATH )
  415. set( INSTALL_TO "path" CACHE INTERNAL "" )
  416. set_property( CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "${INSTALL_PATH}" )
  417. elseif( INSTALL_TO_SOURCE )
  418. set( INSTALL_TO "source" CACHE INTERNAL "" )
  419. set_property( CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "${CMAKE_CURRENT_SOURCE_DIR}" )
  420. elseif( INSTALL_TO_SUBDIR )
  421. set( INSTALL_TO "subdir" CACHE INTERNAL "" )
  422. set_property( CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "${CMAKE_CURRENT_BINARY_DIR}/install" )
  423. endif()
  424. set( SVN_FOLDER_PATTERN "[\\.]svn" CACHE STRING "pattern of svn folder that we exclude from instalations" )
  425. mark_as_advanced( SVN_FOLDER_PATTERN )
  426. set( DEVELOPMENT_FILES
  427. "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt"
  428. "${CMAKE_CURRENT_SOURCE_DIR}/configure"
  429. "${CMAKE_CURRENT_SOURCE_DIR}/configure.in"
  430. "${CMAKE_CURRENT_SOURCE_DIR}/rAthena.sln"
  431. )
  432. set( DEVELOPMENT_DIRECTORIES
  433. "3rdparty"
  434. "conf/import-tmpl"
  435. "conf/msg_conf/import-tmpl"
  436. "db/import-tmpl"
  437. "src"
  438. )
  439. set( RUNTIME_FILES
  440. "${CMAKE_CURRENT_SOURCE_DIR}/athena-start"
  441. "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE"
  442. "${CMAKE_CURRENT_SOURCE_DIR}/README.md"
  443. )
  444. if (WIN32)
  445. set (RUNTIME_FILES
  446. ${RUNTIME_FILES}
  447. "${CMAKE_CURRENT_SOURCE_DIR}/dbghelp.dll"
  448. "${CMAKE_CURRENT_SOURCE_DIR}/libmysql.dll"
  449. "${CMAKE_CURRENT_SOURCE_DIR}/pcre3.dll"
  450. "${CMAKE_CURRENT_SOURCE_DIR}/zlib1.dll"
  451. "${CMAKE_CURRENT_SOURCE_DIR}/tools/charserv.bat"
  452. "${CMAKE_CURRENT_SOURCE_DIR}/tools/logserv.bat"
  453. "${CMAKE_CURRENT_SOURCE_DIR}/tools/mapserv.bat"
  454. "${CMAKE_CURRENT_SOURCE_DIR}/tools/runserver.bat"
  455. "${CMAKE_CURRENT_SOURCE_DIR}/tools/serv.bat"
  456. )
  457. endif(WIN32)
  458. set( RUNTIME_DIRECTORIES
  459. "conf"
  460. "db"
  461. "doc"
  462. "log"
  463. "npc"
  464. "sql-files"
  465. "tools"
  466. )
  467. if( INSTALL_TO_SOURCE )# skip, already in the source dir
  468. else()
  469. if( INSTALL_COMPONENT_RUNTIME )
  470. install( FILES ${RUNTIME_FILES}
  471. DESTINATION "."
  472. COMPONENT Runtime_base )
  473. foreach( DIR IN ITEMS ${RUNTIME_DIRECTORIES} )
  474. if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${DIR}/" )
  475. install( DIRECTORY "${DIR}/"
  476. DESTINATION "${DIR}"
  477. COMPONENT Runtime_base
  478. PATTERN ${SVN_FOLDER_PATTERN} EXCLUDE
  479. PATTERN "conf/import-tmpl" EXCLUDE )
  480. else()
  481. # create empty directory
  482. install( CODE "file(MAKE_DIRECTORY \"\${ENV}\${CMAKE_INSTALL_PREFIX}/${DIR}\")"
  483. COMPONENT Runtime_base )
  484. endif()
  485. endforeach()
  486. endif( INSTALL_COMPONENT_RUNTIME )
  487. if( INSTALL_COMPONENT_DEVELOPMENT )
  488. install( FILES ${DEVELOPMENT_FILES}
  489. DESTINATION "."
  490. COMPONENT Development_base )
  491. foreach( DIR IN ITEMS ${DEVELOPMENT_DIRECTORIES} )
  492. install( DIRECTORY "${DIR}/"
  493. DESTINATION "${DIR}"
  494. COMPONENT Development_base
  495. PATTERN ${SVN_FOLDER_PATTERN} EXCLUDE )
  496. endforeach()
  497. endif( INSTALL_COMPONENT_DEVELOPMENT )
  498. endif()
  499. if( INSTALL_COMPONENT_RUNTIME )
  500. # templates
  501. set( _TEMPLATES
  502. "conf/import-tmpl" "conf/import"
  503. "conf/msg_conf/import-tmpl" "conf/msg_conf/import"
  504. "db/import-tmpl" "db/import"
  505. )
  506. set( INSTALL_TEMPLATES_FILE "${CMAKE_CURRENT_BINARY_DIR}/InstallTemplates.cmake" )
  507. file( WRITE "${INSTALL_TEMPLATES_FILE}"
  508. "macro( INSTALL_TEMPLATE _SRC _DST )\n"
  509. " set( SRC \"${CMAKE_CURRENT_SOURCE_DIR}/\${_SRC}\" )\n"
  510. " set( DST \"\${CMAKE_INSTALL_PREFIX}/\${_DST}\" )\n"
  511. " if( EXISTS \"\${DST}\" )\n"
  512. " message( \"-- Already exists: \${DST}\" )\n"
  513. " else()\n"
  514. " message( \"-- Installing template: \${DST}\" )\n"
  515. " execute_process( COMMAND \"${CMAKE_COMMAND}\" -E copy \"\${SRC}\" \"\${DST}\" )\n"
  516. " endif()\n"
  517. "endmacro()\n"
  518. )
  519. while( _TEMPLATES )
  520. list( GET _TEMPLATES 0 _SRC )
  521. list( GET _TEMPLATES 1 _DST )
  522. list( REMOVE_AT _TEMPLATES 0 1 )
  523. if( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_SRC}" )
  524. file( GLOB _PATHS "${CMAKE_CURRENT_SOURCE_DIR}/${_SRC}/*" )
  525. foreach( _PATH IN ITEMS ${_PATHS} )
  526. string( REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/${_SRC}/" "" _PATH "${_PATH}" )
  527. if( NOT "${_PATH}" MATCHES "${SVN_FOLDER_PATTERN}" )
  528. list( APPEND _TEMPLATES "${_SRC}/${_PATH}" "${_DST}/${_PATH}" )
  529. endif()
  530. endforeach()
  531. else()
  532. file( APPEND "${INSTALL_TEMPLATES_FILE}" "INSTALL_TEMPLATE( \"${_SRC}\" \"${_DST}\" )\n" )
  533. endif()
  534. endwhile()
  535. install( SCRIPT "${INSTALL_TEMPLATES_FILE}"
  536. COMPONENT Runtime_templates )
  537. endif( INSTALL_COMPONENT_RUNTIME )
  538. #
  539. # sources
  540. #
  541. set( TARGET_LIST CACHE INTERNAL "" )
  542. add_subdirectory( 3rdparty )
  543. add_subdirectory( src )
  544. #####################################################################
  545. # final checks and warnings
  546. #
  547. list( LENGTH TARGET_LIST _LEN )
  548. if( _LEN EQUAL 0 )
  549. message( FATAL_ERROR "no targets available" )
  550. endif()
  551. message( STATUS "Available targets:" )
  552. foreach( _TARGET IN ITEMS ${TARGET_LIST} )
  553. message( STATUS "\t${_TARGET}" )
  554. endforeach()