CMakeLists.txt 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 - applied only to project targets, not dependencies
  17. set(SMARTBOTIC_CXX_WARNINGS
  18. -Wall
  19. -Wextra
  20. -Wpedantic
  21. -Werror
  22. -Wno-unused-parameter
  23. -Wno-dangling-reference # False positive in spdlog's bundled fmt with GCC 13+
  24. )
  25. # Sanitizers for debug builds
  26. if(ENABLE_SANITIZERS)
  27. add_compile_options(-fsanitize=address,undefined)
  28. add_link_options(-fsanitize=address,undefined)
  29. endif()
  30. # Include FetchContent module
  31. include(FetchContent)
  32. # ============================================================================
  33. # External Dependencies via FetchContent
  34. # ============================================================================
  35. # spdlog - Fast C++ logging library
  36. FetchContent_Declare(
  37. spdlog
  38. GIT_REPOSITORY https://github.com/gabime/spdlog.git
  39. GIT_TAG v1.13.0
  40. )
  41. # nlohmann_json - JSON for Modern C++
  42. FetchContent_Declare(
  43. nlohmann_json
  44. GIT_REPOSITORY https://github.com/nlohmann/json.git
  45. GIT_TAG v3.11.3
  46. )
  47. # gRPC and Protobuf
  48. FetchContent_Declare(
  49. grpc
  50. GIT_REPOSITORY https://github.com/grpc/grpc.git
  51. GIT_TAG v1.60.0
  52. GIT_SHALLOW TRUE
  53. )
  54. # libsodium - Cryptography library
  55. FetchContent_Declare(
  56. libsodium
  57. GIT_REPOSITORY https://github.com/jedisct1/libsodium.git
  58. GIT_TAG 1.0.19
  59. )
  60. # Make dependencies available
  61. message(STATUS "Fetching spdlog...")
  62. FetchContent_MakeAvailable(spdlog)
  63. message(STATUS "Fetching nlohmann_json...")
  64. FetchContent_MakeAvailable(nlohmann_json)
  65. message(STATUS "Fetching gRPC (this may take a while)...")
  66. set(gRPC_BUILD_TESTS OFF CACHE BOOL "" FORCE)
  67. set(gRPC_INSTALL OFF CACHE BOOL "" FORCE)
  68. set(gRPC_BUILD_GRPC_CSHARP_PLUGIN OFF CACHE BOOL "" FORCE)
  69. set(gRPC_BUILD_GRPC_NODE_PLUGIN OFF CACHE BOOL "" FORCE)
  70. set(gRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN OFF CACHE BOOL "" FORCE)
  71. set(gRPC_BUILD_GRPC_PHP_PLUGIN OFF CACHE BOOL "" FORCE)
  72. set(gRPC_BUILD_GRPC_PYTHON_PLUGIN OFF CACHE BOOL "" FORCE)
  73. set(gRPC_BUILD_GRPC_RUBY_PLUGIN OFF CACHE BOOL "" FORCE)
  74. set(ABSL_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
  75. set(ABSL_PROPAGATE_CXX_STD ON CACHE BOOL "" FORCE)
  76. set(protobuf_INSTALL OFF CACHE BOOL "" FORCE)
  77. set(utf8_range_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
  78. # Disable -Werror for gRPC and its dependencies (abseil uses __int128 which triggers -Wpedantic)
  79. set(CMAKE_CXX_FLAGS_BACKUP "${CMAKE_CXX_FLAGS}")
  80. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-pedantic -Wno-overflow -Wno-error")
  81. FetchContent_MakeAvailable(grpc)
  82. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_BACKUP}")
  83. # libsodium requires special handling as it uses autotools
  84. FetchContent_GetProperties(libsodium)
  85. if(NOT libsodium_POPULATED)
  86. FetchContent_Populate(libsodium)
  87. # Build libsodium using autotools
  88. execute_process(
  89. COMMAND ${libsodium_SOURCE_DIR}/configure
  90. --prefix=${libsodium_BINARY_DIR}/install
  91. --disable-shared
  92. --enable-static
  93. WORKING_DIRECTORY ${libsodium_SOURCE_DIR}
  94. RESULT_VARIABLE SODIUM_CONFIGURE_RESULT
  95. )
  96. if(NOT SODIUM_CONFIGURE_RESULT EQUAL 0)
  97. message(WARNING "libsodium configure failed, will try system libsodium")
  98. find_package(PkgConfig REQUIRED)
  99. pkg_check_modules(SODIUM REQUIRED libsodium)
  100. else()
  101. execute_process(
  102. COMMAND make -j${CMAKE_BUILD_PARALLEL_LEVEL}
  103. WORKING_DIRECTORY ${libsodium_SOURCE_DIR}
  104. )
  105. execute_process(
  106. COMMAND make install
  107. WORKING_DIRECTORY ${libsodium_SOURCE_DIR}
  108. )
  109. set(SODIUM_INCLUDE_DIRS ${libsodium_BINARY_DIR}/install/include)
  110. set(SODIUM_LIBRARY_DIRS ${libsodium_BINARY_DIR}/install/lib)
  111. set(SODIUM_LIBRARIES sodium)
  112. endif()
  113. endif()
  114. # Create imported target for libsodium
  115. add_library(sodium STATIC IMPORTED GLOBAL)
  116. set_target_properties(sodium PROPERTIES
  117. IMPORTED_LOCATION ${SODIUM_LIBRARY_DIRS}/libsodium.a
  118. INTERFACE_INCLUDE_DIRECTORIES ${SODIUM_INCLUDE_DIRS}
  119. )
  120. # ============================================================================
  121. # Project Subdirectories
  122. # ============================================================================
  123. add_subdirectory(common)
  124. add_subdirectory(proto)
  125. add_subdirectory(database)
  126. add_subdirectory(webserver)
  127. add_subdirectory(webui)
  128. if(BUILD_TESTING)
  129. add_subdirectory(tests)
  130. endif()
  131. # ============================================================================
  132. # Summary
  133. # ============================================================================
  134. message(STATUS "")
  135. message(STATUS "SmartBotic CRM Configuration Summary")
  136. message(STATUS "=====================================")
  137. message(STATUS "Version: ${PROJECT_VERSION}")
  138. message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
  139. message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
  140. message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
  141. message(STATUS "Build Testing: ${BUILD_TESTING}")
  142. message(STATUS "Sanitizers: ${ENABLE_SANITIZERS}")
  143. message(STATUS "")