CMakeLists.txt 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
  2. file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/src/oatpp/core/base/Environment.hpp" OATPP_VERSION_MACRO REGEX "#define OATPP_VERSION \"[0-9]+.[0-9]+.[0-9]+\"$")
  3. string(REGEX REPLACE "#define OATPP_VERSION \"([0-9]+.[0-9]+.[0-9]+)\"$" "\\1" oatpp_VERSION "${OATPP_VERSION_MACRO}")
  4. ###################################################################################################
  5. ## These variables are passed to oatpp-module-install.cmake script
  6. ## use these variables to configure module installation
  7. set(OATPP_THIS_MODULE_NAME oatpp) ## name of the module (also name of folders in installation dirs)
  8. set(OATPP_THIS_MODULE_VERSION ${oatpp_VERSION}) ## version of the module (also sufix of folders in installation dirs)
  9. set(OATPP_THIS_MODULE_LIBRARIES oatpp oatpp-test) ## list of libraries to find when find_package is called
  10. set(OATPP_THIS_MODULE_TARGETS oatpp oatpp-test) ## list of targets to install
  11. set(OATPP_THIS_MODULE_DIRECTORIES oatpp oatpp-test) ## list of directories to install
  12. ###################################################################################################
  13. project(oatpp VERSION ${OATPP_THIS_MODULE_VERSION} LANGUAGES CXX)
  14. option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
  15. option(OATPP_INSTALL "Create installation target for oat++" ON)
  16. option(OATPP_BUILD_TESTS "Create test target for oat++" ON)
  17. option(OATPP_LINK_ATOMIC "Link atomic library for other platform than MSVC|MINGW|APPLE|FreeBSD" ON)
  18. option(OATPP_MSVC_LINK_STATIC_RUNTIME "MSVC: Link with static runtime (/MT and /MTd)." OFF)
  19. ###################################################################################################
  20. ## COMPILATION CONFIG #############################################################################
  21. ###################################################################################################
  22. option(OATPP_DISABLE_ENV_OBJECT_COUNTERS "Disable object counting for Release builds for better performance" OFF)
  23. option(OATPP_DISABLE_POOL_ALLOCATIONS "This will make oatpp::base::memory::MemoryPool, method obtain and free call new and delete directly" OFF)
  24. set(OATPP_THREAD_HARDWARE_CONCURRENCY "AUTO" CACHE STRING "Predefined value for function oatpp::concurrency::Thread::getHardwareConcurrency()")
  25. set(OATPP_THREAD_DISTRIBUTED_MEM_POOL_SHARDS_COUNT "10" CACHE STRING "Number of shards of ThreadDistributedMemoryPool")
  26. option(OATPP_COMPAT_BUILD_NO_THREAD_LOCAL "Disable 'thread_local' feature" OFF)
  27. option(OATPP_COMPAT_BUILD_NO_SET_AFFINITY "No 'pthread_setaffinity_np' method" OFF)
  28. option(OATPP_DISABLE_LOGV "DISABLE logs priority V" OFF)
  29. option(OATPP_DISABLE_LOGD "DISABLE logs priority D" OFF)
  30. option(OATPP_DISABLE_LOGI "DISABLE logs priority I" OFF)
  31. option(OATPP_DISABLE_LOGW "DISABLE logs priority W" OFF)
  32. option(OATPP_DISABLE_LOGE "DISABLE logs priority E" OFF)
  33. ## Print config ##################################################################################
  34. message("\n############################################################################")
  35. message("## oatpp module compilation config:\n")
  36. message("OATPP_DISABLE_ENV_OBJECT_COUNTERS=${OATPP_DISABLE_ENV_OBJECT_COUNTERS}")
  37. message("OATPP_DISABLE_POOL_ALLOCATIONS=${OATPP_DISABLE_POOL_ALLOCATIONS}")
  38. message("OATPP_THREAD_HARDWARE_CONCURRENCY=${OATPP_THREAD_HARDWARE_CONCURRENCY}")
  39. message("OATPP_THREAD_DISTRIBUTED_MEM_POOL_SHARDS_COUNT=${OATPP_THREAD_DISTRIBUTED_MEM_POOL_SHARDS_COUNT}")
  40. message("OATPP_COMPAT_BUILD_NO_THREAD_LOCAL=${OATPP_COMPAT_BUILD_NO_THREAD_LOCAL}")
  41. ## Set definitions ###############################################################################
  42. if(OATPP_DISABLE_ENV_OBJECT_COUNTERS)
  43. add_definitions(-DOATPP_DISABLE_ENV_OBJECT_COUNTERS)
  44. endif()
  45. if(OATPP_DISABLE_POOL_ALLOCATIONS)
  46. add_definitions (-DOATPP_DISABLE_POOL_ALLOCATIONS)
  47. endif()
  48. set(AUTO_VALUE AUTO)
  49. if(NOT OATPP_THREAD_HARDWARE_CONCURRENCY STREQUAL AUTO_VALUE)
  50. add_definitions (-DOATPP_THREAD_HARDWARE_CONCURRENCY=${OATPP_THREAD_HARDWARE_CONCURRENCY})
  51. endif()
  52. add_definitions (
  53. -DOATPP_THREAD_DISTRIBUTED_MEM_POOL_SHARDS_COUNT=${OATPP_THREAD_DISTRIBUTED_MEM_POOL_SHARDS_COUNT}
  54. )
  55. if(OATPP_COMPAT_BUILD_NO_THREAD_LOCAL)
  56. add_definitions(-DOATPP_COMPAT_BUILD_NO_THREAD_LOCAL)
  57. endif()
  58. if(OATPP_COMPAT_BUILD_NO_SET_AFFINITY)
  59. add_definitions(-DOATPP_COMPAT_BUILD_NO_SET_AFFINITY)
  60. endif()
  61. if(OATPP_DISABLE_LOGV)
  62. add_definitions(-DOATPP_DISABLE_LOGV)
  63. endif()
  64. if(OATPP_DISABLE_LOGD)
  65. add_definitions(-DOATPP_DISABLE_LOGD)
  66. endif()
  67. if(OATPP_DISABLE_LOGI)
  68. add_definitions(-DOATPP_DISABLE_LOGI)
  69. endif()
  70. if(OATPP_DISABLE_LOGW)
  71. add_definitions(-DOATPP_DISABLE_LOGW)
  72. endif()
  73. if(OATPP_DISABLE_LOGE)
  74. add_definitions(-DOATPP_DISABLE_LOGE)
  75. endif()
  76. if(CMAKE_COMPILER_IS_GNUCXX AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 5.0)
  77. add_definitions(-DOATPP_DISABLE_STD_PUT_TIME)
  78. endif()
  79. message("\n############################################################################\n")
  80. ###################################################################################################
  81. message("oatpp version: '${OATPP_THIS_MODULE_VERSION}'")
  82. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
  83. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
  84. include(cmake/msvc-runtime.cmake)
  85. configure_msvc_runtime()
  86. add_subdirectory(src)
  87. if(OATPP_BUILD_TESTS)
  88. enable_testing()
  89. add_subdirectory(test)
  90. endif()