CMakeLists.txt 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. cmake_minimum_required(VERSION 3.22)
  2. cmake_policy(SET CMP0135 NEW)
  3. project(smartbotic-crm
  4. VERSION 0.1.0
  5. DESCRIPTION "SmartBotic CRM System"
  6. LANGUAGES CXX
  7. )
  8. # C++20 standard
  9. set(CMAKE_CXX_STANDARD 20)
  10. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  11. set(CMAKE_CXX_EXTENSIONS OFF)
  12. # Export compile commands for tooling
  13. set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
  14. # Build options
  15. option(BUILD_TESTING "Build tests" ON)
  16. option(ENABLE_SANITIZERS "Enable address and undefined behavior sanitizers" OFF)
  17. # Compiler warnings - applied only to project targets, not dependencies
  18. set(SMARTBOTIC_CXX_WARNINGS
  19. -Wall
  20. -Wextra
  21. -Wpedantic
  22. -Werror
  23. -Wno-unused-parameter
  24. -Wno-dangling-reference # False positive in spdlog's bundled fmt with GCC 13+
  25. )
  26. # Sanitizers for debug builds
  27. if(ENABLE_SANITIZERS)
  28. add_compile_options(-fsanitize=address,undefined)
  29. add_link_options(-fsanitize=address,undefined)
  30. endif()
  31. # Include FetchContent module
  32. include(FetchContent)
  33. # ============================================================================
  34. # External Dependencies via FetchContent
  35. # ============================================================================
  36. # spdlog - Fast C++ logging library
  37. FetchContent_Declare(
  38. spdlog
  39. GIT_REPOSITORY https://github.com/gabime/spdlog.git
  40. GIT_TAG v1.13.0
  41. )
  42. # nlohmann_json - JSON for Modern C++
  43. FetchContent_Declare(
  44. nlohmann_json
  45. GIT_REPOSITORY https://github.com/nlohmann/json.git
  46. GIT_TAG v3.11.3
  47. )
  48. # cpp-httplib - Header-only HTTP library
  49. FetchContent_Declare(
  50. httplib
  51. GIT_REPOSITORY https://github.com/yhirose/cpp-httplib.git
  52. GIT_TAG v0.30.1
  53. )
  54. # jwt-cpp - Header-only JWT library
  55. FetchContent_Declare(
  56. jwt-cpp
  57. GIT_REPOSITORY https://github.com/Thalhammer/jwt-cpp.git
  58. GIT_TAG v0.7.0
  59. )
  60. # gRPC and Protobuf
  61. FetchContent_Declare(
  62. grpc
  63. GIT_REPOSITORY https://github.com/grpc/grpc.git
  64. GIT_TAG v1.60.0
  65. GIT_SHALLOW TRUE
  66. )
  67. # libsodium - Cryptography library
  68. FetchContent_Declare(
  69. libsodium
  70. GIT_REPOSITORY https://github.com/jedisct1/libsodium.git
  71. GIT_TAG 1.0.19
  72. )
  73. # Make dependencies available
  74. message(STATUS "Fetching spdlog...")
  75. FetchContent_MakeAvailable(spdlog)
  76. message(STATUS "Fetching nlohmann_json...")
  77. FetchContent_MakeAvailable(nlohmann_json)
  78. message(STATUS "Fetching cpp-httplib...")
  79. set(HTTPLIB_REQUIRE_OPENSSL ON CACHE BOOL "" FORCE)
  80. set(HTTPLIB_COMPILE OFF CACHE BOOL "" FORCE) # Header-only mode
  81. FetchContent_MakeAvailable(httplib)
  82. message(STATUS "Fetching jwt-cpp...")
  83. set(JWT_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
  84. set(JWT_BUILD_TESTS OFF CACHE BOOL "" FORCE)
  85. set(JWT_EXTERNAL_PICOJSON OFF CACHE BOOL "" FORCE) # Use bundled picojson
  86. FetchContent_MakeAvailable(jwt-cpp)
  87. message(STATUS "Fetching gRPC (this may take a while)...")
  88. set(gRPC_BUILD_TESTS OFF CACHE BOOL "" FORCE)
  89. set(gRPC_INSTALL OFF CACHE BOOL "" FORCE)
  90. set(gRPC_BUILD_GRPC_CSHARP_PLUGIN OFF CACHE BOOL "" FORCE)
  91. set(gRPC_BUILD_GRPC_NODE_PLUGIN OFF CACHE BOOL "" FORCE)
  92. set(gRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN OFF CACHE BOOL "" FORCE)
  93. set(gRPC_BUILD_GRPC_PHP_PLUGIN OFF CACHE BOOL "" FORCE)
  94. set(gRPC_BUILD_GRPC_PYTHON_PLUGIN OFF CACHE BOOL "" FORCE)
  95. set(gRPC_BUILD_GRPC_RUBY_PLUGIN OFF CACHE BOOL "" FORCE)
  96. set(ABSL_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
  97. set(ABSL_PROPAGATE_CXX_STD ON CACHE BOOL "" FORCE)
  98. set(protobuf_INSTALL OFF CACHE BOOL "" FORCE)
  99. set(utf8_range_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
  100. # Disable -Werror for gRPC and its dependencies (abseil uses __int128 which triggers -Wpedantic)
  101. set(CMAKE_CXX_FLAGS_BACKUP "${CMAKE_CXX_FLAGS}")
  102. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-pedantic -Wno-overflow -Wno-error")
  103. FetchContent_MakeAvailable(grpc)
  104. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_BACKUP}")
  105. # libwebsockets via pkg-config (system library)
  106. find_package(PkgConfig REQUIRED)
  107. pkg_check_modules(LWS REQUIRED IMPORTED_TARGET libwebsockets)
  108. # OpenSSL for HTTPS support
  109. find_package(OpenSSL REQUIRED)
  110. # libsodium requires special handling as it uses autotools
  111. FetchContent_GetProperties(libsodium)
  112. if(NOT libsodium_POPULATED)
  113. FetchContent_Populate(libsodium)
  114. # Build libsodium using autotools
  115. execute_process(
  116. COMMAND ${libsodium_SOURCE_DIR}/configure
  117. --prefix=${libsodium_BINARY_DIR}/install
  118. --disable-shared
  119. --enable-static
  120. WORKING_DIRECTORY ${libsodium_SOURCE_DIR}
  121. RESULT_VARIABLE SODIUM_CONFIGURE_RESULT
  122. )
  123. if(NOT SODIUM_CONFIGURE_RESULT EQUAL 0)
  124. message(WARNING "libsodium configure failed, will try system libsodium")
  125. find_package(PkgConfig REQUIRED)
  126. pkg_check_modules(SODIUM REQUIRED libsodium)
  127. else()
  128. execute_process(
  129. COMMAND make -j${CMAKE_BUILD_PARALLEL_LEVEL}
  130. WORKING_DIRECTORY ${libsodium_SOURCE_DIR}
  131. )
  132. execute_process(
  133. COMMAND make install
  134. WORKING_DIRECTORY ${libsodium_SOURCE_DIR}
  135. )
  136. set(SODIUM_INCLUDE_DIRS ${libsodium_BINARY_DIR}/install/include)
  137. set(SODIUM_LIBRARY_DIRS ${libsodium_BINARY_DIR}/install/lib)
  138. set(SODIUM_LIBRARIES sodium)
  139. endif()
  140. endif()
  141. # Create imported target for libsodium
  142. add_library(sodium STATIC IMPORTED GLOBAL)
  143. set_target_properties(sodium PROPERTIES
  144. IMPORTED_LOCATION ${SODIUM_LIBRARY_DIRS}/libsodium.a
  145. INTERFACE_INCLUDE_DIRECTORIES ${SODIUM_INCLUDE_DIRS}
  146. )
  147. # ============================================================================
  148. # Project Subdirectories
  149. # ============================================================================
  150. add_subdirectory(common)
  151. add_subdirectory(proto)
  152. add_subdirectory(database)
  153. add_subdirectory(webserver)
  154. add_subdirectory(webui)
  155. if(BUILD_TESTING)
  156. add_subdirectory(tests)
  157. endif()
  158. # ============================================================================
  159. # Summary
  160. # ============================================================================
  161. message(STATUS "")
  162. message(STATUS "SmartBotic CRM Configuration Summary")
  163. message(STATUS "=====================================")
  164. message(STATUS "Version: ${PROJECT_VERSION}")
  165. message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
  166. message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
  167. message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
  168. message(STATUS "Build Testing: ${BUILD_TESTING}")
  169. message(STATUS "Sanitizers: ${ENABLE_SANITIZERS}")
  170. message(STATUS "")