CMakeLists.txt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. cmake_minimum_required(VERSION 3.11)
  2. project(rAthena)
  3. # Configure CMake Modules
  4. list(APPEND CMAKE_MODULE_PATH
  5. "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/cmake"
  6. "${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake")
  7. # options
  8. set(PACKETVER 20211103 CACHE STRING "Sets the PACKETVER define of the servers (see src/common/mmo.hpp)")
  9. set(MAXCONN CACHE STRING "Sets the MAXCONN define of the servers. (see src/common/socket.hpp)")
  10. option(ENABLE_PRERENEWAL "Whether or not to enable Pre-renewal (default=OFF)" OFF)
  11. option(ENABLE_WEB_SERVER "Build web-server (default=ON)" ON)
  12. option(ENABLE_RDTSC "Enable RDTSC instruction as a timing source (default=OFF)" OFF)
  13. option(ENABLE_EXTRA_DEBUG_CODE "Enable extra debug code (default=OFF)" OFF)
  14. option(ENABLE_MEMMGR "Enable memory manager (default=ON)" ON)
  15. # TODO(vstumpf): If no one uses this, we can just remove it
  16. # set(ENABLE_MEMORY "system" CACHE STRING "Enable memory library (default=system)")
  17. option(ENABLE_PROFILER "Enable profiler (default=OFF)" OFF)
  18. option(ENABLE_EXTRA_BUILDBOT_CODE "Enable extra buildbot code (default=OFF)" OFF)
  19. option(ENABLE_EPOLL "Use epoll instead of select (default=OFF)" OFF)
  20. option(ENABLE_VIP "Enable VIP system (default=OFF)" OFF)
  21. # Set a default build type if none was specified
  22. set(default_build_type "Release")
  23. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  24. set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
  25. STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel" FORCE)
  26. message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
  27. endif()
  28. if(CMAKE_GENERATOR MATCHES "Visual Studio")
  29. set(ENABLE_MSVC_PARALLEL ON CACHE STRING "\
  30. Enables /MP flag for parallel builds using MSVC. Specify an integer value to control \
  31. the number of threads used (Only works on versions of Visual Studio). Setting to ON \
  32. lets the toolchain decide how many threads to use. Set to OFF to disable /MP completely." )
  33. if(ENABLE_MSVC_PARALLEL)
  34. if(ENABLE_MSVC_PARALLEL GREATER 0)
  35. string(APPEND CMAKE_C_FLAGS " /MP${ENABLE_MSVC_PARALLEL}")
  36. string(APPEND CMAKE_CXX_FLAGS " /MP${ENABLE_MSVC_PARALLEL}")
  37. else()
  38. string(APPEND CMAKE_C_FLAGS " /MP")
  39. string(APPEND CMAKE_CXX_FLAGS " /MP")
  40. endif()
  41. endif()
  42. endif()
  43. #
  44. # Prevent building in the source directory by default
  45. #
  46. if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
  47. message( FATAL_ERROR
  48. "Do not use the source directory to build your files, instead delete CMakeCache.txt, create a separate folder and build there.\n"
  49. "Example: (build in subdir 'build' and install to source dir)\n"
  50. " rm -f CMakeCache.txt\n"
  51. " mkdir build\n"
  52. " cd build\n"
  53. " cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..\n"
  54. " make install\n"
  55. " cd ..\n"
  56. " rm -rf build\n")
  57. endif()
  58. if(WIN32)
  59. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  60. endif()
  61. # Configure C++ Standard
  62. set(CMAKE_CXX_STANDARD 17)
  63. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  64. # Set build directories
  65. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib/${suffixInstallStr})
  66. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib/${suffixInstallStr})
  67. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  68. if(WIN32)
  69. set(RuntimeOutputDir "${CMAKE_BINARY_DIR}/..")
  70. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${RuntimeOutputDir})
  71. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${RuntimeOutputDir})
  72. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${RuntimeOutputDir})
  73. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${RuntimeOutputDir})
  74. if (MSVC AND NOT MSVC_VERSION VERSION_LESS 142)
  75. add_link_options($<$<CONFIG:Debug>:/INCREMENTAL>)
  76. add_compile_options($<$<CONFIG:Debug>:/ZI>)
  77. endif()
  78. add_compile_definitions($<$<CONFIG:DEBUG>:_ITERATOR_DEBUG_LEVEL=0>)
  79. endif()
  80. add_subdirectory(db)
  81. add_subdirectory(conf)
  82. add_subdirectory(3rdparty)
  83. add_subdirectory(src)
  84. add_subdirectory(tools)
  85. add_custom_target(server
  86. DEPENDS login-server char-server map-server web-server scripts
  87. )