CMakeLists.txt 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. set(PROJECT_NAME "proto")
  2. cmake_minimum_required(VERSION 3.16)
  3. PROJECT( ${PROJECT_NAME} )
  4. option(USE_TCP "build with tcp" ON)
  5. option(USE_SSL "build with ssl" OFF)
  6. option(USE_WS "build with websocket over http" OFF)
  7. option(USE_WSS "build with websocket over https" OFF)
  8. option(USE_SQLITE3 "build with sqlite3" ON)
  9. option(USE_ALL_SQLITE3 "build with sqlite3" OFF)
  10. option(USE_RAPIDJSON "build json by rapidjson" ON)
  11. option(USE_OPENSSL "build openssl" ON)
  12. IF(${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
  13. message(STATUS "build by wasm")
  14. SET(USE_WASM ON)
  15. set(USE_TCP OFF)
  16. set(USE_SSL OFF)
  17. set(USE_WS OFF)
  18. set(USE_WSS OFF)
  19. set(USE_SQLITE3 OFF)
  20. set(USE_ALL_SQLITE3 OFF)
  21. add_definitions(-DUSE_WASM -D__linux__)
  22. ELSE()
  23. SET(USE_WASM OFF)
  24. ENDIF()
  25. IF(NOT USE_SQLITE3)
  26. SET(USE_ALL_SQLITE3 OFF)
  27. ENDIF()
  28. string(TIMESTAMP COMPILE_DATE %Y%m%d)
  29. string(TIMESTAMP COMPILE_TIME %H%M%S)
  30. SET(BUILD_DATE ${COMPILE_DATE})
  31. SET(BUILD_TIME ${COMPILE_TIME})
  32. message(STATUS "Building with ${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION} on ${CMAKE_SYSTEM}")
  33. INCLUDE(cmake/MSVCVer.cmake)
  34. INCLUDE(cmake/Utils.cmake)
  35. IF(MSVC)
  36. set(CMAKE_GENERATOR_PLATFORM x64)
  37. SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
  38. SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
  39. SET(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
  40. set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
  41. SET(ENABLE_MSVC_MP ON)
  42. MARK_AS_ADVANCED(WIN32_USE_MP)
  43. IF(WIN32_USE_MP)
  44. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
  45. ENDIF(WIN32_USE_MP)
  46. ELSE()
  47. set(CMAKE_C_FLAGS "$ENV{CFLAGS} -Wall -Wextra -Wno-sign-compare -Wno-missing-field-initializers -Wundef -Wuninitialized -Wunused -Wno-unused-parameter -Wwrite-strings -Wchar-subscripts -funsigned-char")
  48. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -DDEBUG -O0 -g3")
  49. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -DNDEBUG -O2 -g")
  50. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  51. ENDIF()
  52. set(CMAKE_INCLUDE_CURRENT_DIR ON)
  53. SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
  54. set(CMAKE_CONFIGURATION_TYPES "Debug;Release;")
  55. set(CMAKE_CXX_STANDARD 14)
  56. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  57. set(CMAKE_CXX_EXTENSIONS OFF)
  58. SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin/${SYS})
  59. SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin/${SYS})
  60. SET(INCDIR ${PROJECT_SOURCE_DIR}/inc)
  61. if(WIN32)
  62. add_compile_options(/wd4251)
  63. add_compile_options(/wd4275)
  64. #add_definitions(-DNOMINMAX)
  65. if(MSVC)
  66. add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
  67. endif()
  68. endif()
  69. include_directories(${PROJECT_SOURCE_DIR}/inc)
  70. configure_file(${PROJECT_SOURCE_DIR}/inc/MqttBuildInfo.h.in
  71. ${PROJECT_SOURCE_DIR}/inc/MqttBuildInfo.h)
  72. add_definitions(-DSQLITE_HAS_CODEC
  73. -DSQLITE_ENABLE_COLUMN_METADATA
  74. -DSQLITE_TEMP_STORE=2
  75. )
  76. IF(USE_OPENSSL)
  77. add_subdirectory(src/libressl)
  78. set(OPENSSL_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/src/libressl/include)
  79. ELSE()
  80. add_subdirectory(src/crypt)
  81. set(OPENSSL_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/src/crypt/include)
  82. ENDIF()
  83. if(USE_SQLITE3)
  84. add_subdirectory(src/sqlcipher)
  85. endif()
  86. add_subdirectory(src/protobuf)
  87. add_subdirectory(src/proto)
  88. add_subdirectory(src/zlib)
  89. IF(NOT USE_WASM)
  90. add_subdirectory(src/MqttClient)
  91. add_subdirectory(tests)
  92. ENDIF()