CMakeLists.txt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. cmake_minimum_required(VERSION 3.22)
  2. project(smartbotic-crm
  3. VERSION 0.1.0
  4. DESCRIPTION "SmartBotic CRM System"
  5. LANGUAGES CXX
  6. )
  7. # C++20 standard
  8. set(CMAKE_CXX_STANDARD 20)
  9. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  10. set(CMAKE_CXX_EXTENSIONS OFF)
  11. # Export compile commands for tooling
  12. set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
  13. # Build options
  14. option(BUILD_TESTING "Build tests" ON)
  15. option(ENABLE_SANITIZERS "Enable address and undefined behavior sanitizers" OFF)
  16. # Compiler warnings
  17. add_compile_options(
  18. -Wall
  19. -Wextra
  20. -Wpedantic
  21. -Werror
  22. -Wno-unused-parameter
  23. )
  24. # Sanitizers for debug builds
  25. if(ENABLE_SANITIZERS)
  26. add_compile_options(-fsanitize=address,undefined)
  27. add_link_options(-fsanitize=address,undefined)
  28. endif()
  29. # Include FetchContent module
  30. include(FetchContent)
  31. # ============================================================================
  32. # External Dependencies via FetchContent
  33. # ============================================================================
  34. # spdlog - Fast C++ logging library
  35. FetchContent_Declare(
  36. spdlog
  37. GIT_REPOSITORY https://github.com/gabime/spdlog.git
  38. GIT_TAG v1.13.0
  39. )
  40. # nlohmann_json - JSON for Modern C++
  41. FetchContent_Declare(
  42. nlohmann_json
  43. GIT_REPOSITORY https://github.com/nlohmann/json.git
  44. GIT_TAG v3.11.3
  45. )
  46. # gRPC and Protobuf
  47. FetchContent_Declare(
  48. grpc
  49. GIT_REPOSITORY https://github.com/grpc/grpc.git
  50. GIT_TAG v1.60.0
  51. GIT_SHALLOW TRUE
  52. )
  53. # libsodium - Cryptography library
  54. FetchContent_Declare(
  55. libsodium
  56. GIT_REPOSITORY https://github.com/jedisct1/libsodium.git
  57. GIT_TAG 1.0.19
  58. )
  59. # Make dependencies available
  60. message(STATUS "Fetching spdlog...")
  61. FetchContent_MakeAvailable(spdlog)
  62. message(STATUS "Fetching nlohmann_json...")
  63. FetchContent_MakeAvailable(nlohmann_json)
  64. message(STATUS "Fetching gRPC (this may take a while)...")
  65. set(gRPC_BUILD_TESTS OFF CACHE BOOL "" FORCE)
  66. set(gRPC_INSTALL OFF CACHE BOOL "" FORCE)
  67. set(ABSL_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
  68. set(ABSL_PROPAGATE_CXX_STD ON CACHE BOOL "" FORCE)
  69. FetchContent_MakeAvailable(grpc)
  70. # libsodium requires special handling as it uses autotools
  71. FetchContent_GetProperties(libsodium)
  72. if(NOT libsodium_POPULATED)
  73. FetchContent_Populate(libsodium)
  74. # Build libsodium using autotools
  75. execute_process(
  76. COMMAND ${libsodium_SOURCE_DIR}/configure
  77. --prefix=${libsodium_BINARY_DIR}/install
  78. --disable-shared
  79. --enable-static
  80. WORKING_DIRECTORY ${libsodium_SOURCE_DIR}
  81. RESULT_VARIABLE SODIUM_CONFIGURE_RESULT
  82. )
  83. if(NOT SODIUM_CONFIGURE_RESULT EQUAL 0)
  84. message(WARNING "libsodium configure failed, will try system libsodium")
  85. find_package(PkgConfig REQUIRED)
  86. pkg_check_modules(SODIUM REQUIRED libsodium)
  87. else()
  88. execute_process(
  89. COMMAND make -j${CMAKE_BUILD_PARALLEL_LEVEL}
  90. WORKING_DIRECTORY ${libsodium_SOURCE_DIR}
  91. )
  92. execute_process(
  93. COMMAND make install
  94. WORKING_DIRECTORY ${libsodium_SOURCE_DIR}
  95. )
  96. set(SODIUM_INCLUDE_DIRS ${libsodium_BINARY_DIR}/install/include)
  97. set(SODIUM_LIBRARY_DIRS ${libsodium_BINARY_DIR}/install/lib)
  98. set(SODIUM_LIBRARIES sodium)
  99. endif()
  100. endif()
  101. # Create imported target for libsodium
  102. add_library(sodium STATIC IMPORTED GLOBAL)
  103. set_target_properties(sodium PROPERTIES
  104. IMPORTED_LOCATION ${SODIUM_LIBRARY_DIRS}/libsodium.a
  105. INTERFACE_INCLUDE_DIRECTORIES ${SODIUM_INCLUDE_DIRS}
  106. )
  107. # ============================================================================
  108. # Project Subdirectories
  109. # ============================================================================
  110. add_subdirectory(common)
  111. add_subdirectory(proto)
  112. add_subdirectory(database)
  113. add_subdirectory(webserver)
  114. add_subdirectory(webui)
  115. # ============================================================================
  116. # Summary
  117. # ============================================================================
  118. message(STATUS "")
  119. message(STATUS "SmartBotic CRM Configuration Summary")
  120. message(STATUS "=====================================")
  121. message(STATUS "Version: ${PROJECT_VERSION}")
  122. message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
  123. message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
  124. message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
  125. message(STATUS "Build Testing: ${BUILD_TESTING}")
  126. message(STATUS "Sanitizers: ${ENABLE_SANITIZERS}")
  127. message(STATUS "")