CMakeLists.txt 5.6 KB

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