CMakeLists.txt 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. FetchContent_MakeAvailable(grpc)
  79. # libsodium requires special handling as it uses autotools
  80. FetchContent_GetProperties(libsodium)
  81. if(NOT libsodium_POPULATED)
  82. FetchContent_Populate(libsodium)
  83. # Build libsodium using autotools
  84. execute_process(
  85. COMMAND ${libsodium_SOURCE_DIR}/configure
  86. --prefix=${libsodium_BINARY_DIR}/install
  87. --disable-shared
  88. --enable-static
  89. WORKING_DIRECTORY ${libsodium_SOURCE_DIR}
  90. RESULT_VARIABLE SODIUM_CONFIGURE_RESULT
  91. )
  92. if(NOT SODIUM_CONFIGURE_RESULT EQUAL 0)
  93. message(WARNING "libsodium configure failed, will try system libsodium")
  94. find_package(PkgConfig REQUIRED)
  95. pkg_check_modules(SODIUM REQUIRED libsodium)
  96. else()
  97. execute_process(
  98. COMMAND make -j${CMAKE_BUILD_PARALLEL_LEVEL}
  99. WORKING_DIRECTORY ${libsodium_SOURCE_DIR}
  100. )
  101. execute_process(
  102. COMMAND make install
  103. WORKING_DIRECTORY ${libsodium_SOURCE_DIR}
  104. )
  105. set(SODIUM_INCLUDE_DIRS ${libsodium_BINARY_DIR}/install/include)
  106. set(SODIUM_LIBRARY_DIRS ${libsodium_BINARY_DIR}/install/lib)
  107. set(SODIUM_LIBRARIES sodium)
  108. endif()
  109. endif()
  110. # Create imported target for libsodium
  111. add_library(sodium STATIC IMPORTED GLOBAL)
  112. set_target_properties(sodium PROPERTIES
  113. IMPORTED_LOCATION ${SODIUM_LIBRARY_DIRS}/libsodium.a
  114. INTERFACE_INCLUDE_DIRECTORIES ${SODIUM_INCLUDE_DIRS}
  115. )
  116. # ============================================================================
  117. # Project Subdirectories
  118. # ============================================================================
  119. add_subdirectory(common)
  120. add_subdirectory(proto)
  121. add_subdirectory(database)
  122. add_subdirectory(webserver)
  123. add_subdirectory(webui)
  124. if(BUILD_TESTING)
  125. add_subdirectory(tests)
  126. endif()
  127. # ============================================================================
  128. # Summary
  129. # ============================================================================
  130. message(STATUS "")
  131. message(STATUS "SmartBotic CRM Configuration Summary")
  132. message(STATUS "=====================================")
  133. message(STATUS "Version: ${PROJECT_VERSION}")
  134. message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
  135. message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
  136. message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
  137. message(STATUS "Build Testing: ${BUILD_TESTING}")
  138. message(STATUS "Sanitizers: ${ENABLE_SANITIZERS}")
  139. message(STATUS "")