CMakeLists.txt 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. ###################################################################################################
  10. project(oatpp VERSION ${OATPP_THIS_MODULE_VERSION} LANGUAGES CXX)
  11. option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
  12. option(OATPP_INSTALL "Create installation target for oat++" ON)
  13. option(OATPP_BUILD_TESTS "Create test target for oat++" ON)
  14. option(OATPP_LINK_ATOMIC "Link atomic library for other platform than MSVC|MINGW|APPLE|FreeBSD" ON)
  15. option(OATPP_MSVC_LINK_STATIC_RUNTIME "MSVC: Link with static runtime (/MT and /MTd)." OFF)
  16. ###################################################################################################
  17. ## COMPILATION CONFIG #############################################################################
  18. ###################################################################################################
  19. if(OATPP_BUILD_TESTS)
  20. set(OATPP_THIS_MODULE_LIBRARIES oatpp oatpp-test) ## list of libraries to find when find_package is called
  21. set(OATPP_THIS_MODULE_TARGETS oatpp oatpp-test) ## list of targets to install
  22. set(OATPP_THIS_MODULE_DIRECTORIES oatpp oatpp-test) ## list of directories to install
  23. else()
  24. set(OATPP_THIS_MODULE_LIBRARIES oatpp) ## list of libraries to find when find_package is called
  25. set(OATPP_THIS_MODULE_TARGETS oatpp) ## list of targets to install
  26. set(OATPP_THIS_MODULE_DIRECTORIES oatpp) ## list of directories to install
  27. endif()
  28. option(OATPP_DISABLE_ENV_OBJECT_COUNTERS "Disable object counting for Release builds for better performance" OFF)
  29. option(OATPP_DISABLE_POOL_ALLOCATIONS "This will make oatpp::base::memory::MemoryPool, method obtain and free call new and delete directly" OFF)
  30. set(OATPP_THREAD_HARDWARE_CONCURRENCY "AUTO" CACHE STRING "Predefined value for function oatpp::concurrency::Thread::getHardwareConcurrency()")
  31. option(OATPP_COMPAT_BUILD_NO_THREAD_LOCAL "Disable 'thread_local' feature" OFF)
  32. option(OATPP_COMPAT_BUILD_NO_SET_AFFINITY "No 'pthread_setaffinity_np' method" OFF)
  33. option(OATPP_DISABLE_LOGV "DISABLE logs priority V" OFF)
  34. option(OATPP_DISABLE_LOGD "DISABLE logs priority D" OFF)
  35. option(OATPP_DISABLE_LOGI "DISABLE logs priority I" OFF)
  36. option(OATPP_DISABLE_LOGW "DISABLE logs priority W" OFF)
  37. option(OATPP_DISABLE_LOGE "DISABLE logs priority E" OFF)
  38. ## Print config ##################################################################################
  39. message("\n############################################################################")
  40. message("## oatpp module compilation config:\n")
  41. message("OATPP_DISABLE_ENV_OBJECT_COUNTERS=${OATPP_DISABLE_ENV_OBJECT_COUNTERS}")
  42. message("OATPP_THREAD_HARDWARE_CONCURRENCY=${OATPP_THREAD_HARDWARE_CONCURRENCY}")
  43. message("OATPP_COMPAT_BUILD_NO_THREAD_LOCAL=${OATPP_COMPAT_BUILD_NO_THREAD_LOCAL}")
  44. ## Set definitions ###############################################################################
  45. if(OATPP_DISABLE_ENV_OBJECT_COUNTERS)
  46. add_definitions(-DOATPP_DISABLE_ENV_OBJECT_COUNTERS)
  47. endif()
  48. if(OATPP_DISABLE_POOL_ALLOCATIONS)
  49. add_definitions (-DOATPP_DISABLE_POOL_ALLOCATIONS)
  50. message("WARNING: OATPP_DISABLE_POOL_ALLOCATIONS option is deprecated and has no effect.")
  51. endif()
  52. set(AUTO_VALUE AUTO)
  53. if(NOT OATPP_THREAD_HARDWARE_CONCURRENCY STREQUAL AUTO_VALUE)
  54. add_definitions (-DOATPP_THREAD_HARDWARE_CONCURRENCY=${OATPP_THREAD_HARDWARE_CONCURRENCY})
  55. endif()
  56. if(OATPP_THREAD_DISTRIBUTED_MEM_POOL_SHARDS_COUNT)
  57. add_definitions (-DOATPP_THREAD_DISTRIBUTED_MEM_POOL_SHARDS_COUNT=${OATPP_THREAD_DISTRIBUTED_MEM_POOL_SHARDS_COUNT})
  58. message("WARNING: OATPP_THREAD_DISTRIBUTED_MEM_POOL_SHARDS_COUNT option is deprecated and has no effect.")
  59. endif()
  60. if(OATPP_COMPAT_BUILD_NO_THREAD_LOCAL)
  61. add_definitions(-DOATPP_COMPAT_BUILD_NO_THREAD_LOCAL)
  62. endif()
  63. if(OATPP_COMPAT_BUILD_NO_SET_AFFINITY)
  64. add_definitions(-DOATPP_COMPAT_BUILD_NO_SET_AFFINITY)
  65. endif()
  66. if(OATPP_DISABLE_LOGV)
  67. add_definitions(-DOATPP_DISABLE_LOGV)
  68. endif()
  69. if(OATPP_DISABLE_LOGD)
  70. add_definitions(-DOATPP_DISABLE_LOGD)
  71. endif()
  72. if(OATPP_DISABLE_LOGI)
  73. add_definitions(-DOATPP_DISABLE_LOGI)
  74. endif()
  75. if(OATPP_DISABLE_LOGW)
  76. add_definitions(-DOATPP_DISABLE_LOGW)
  77. endif()
  78. if(OATPP_DISABLE_LOGE)
  79. add_definitions(-DOATPP_DISABLE_LOGE)
  80. endif()
  81. if(CMAKE_COMPILER_IS_GNUCXX AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 5.0)
  82. add_definitions(-DOATPP_DISABLE_STD_PUT_TIME)
  83. endif()
  84. message("\n############################################################################\n")
  85. ###################################################################################################
  86. message("oatpp version: '${OATPP_THIS_MODULE_VERSION}'")
  87. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
  88. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
  89. include(cmake/msvc-runtime.cmake)
  90. configure_msvc_runtime()
  91. add_subdirectory(src)
  92. if(OATPP_BUILD_TESTS)
  93. enable_testing()
  94. add_subdirectory(test)
  95. endif()
  96. include(cpack.cmake)
  97. # This must always be last!
  98. include( CPack )