123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- set(PROJECT_NAME "proto")
- cmake_minimum_required(VERSION 3.16)
- PROJECT( ${PROJECT_NAME} )
- option(USE_TCP "build with tcp" ON)
- option(USE_SSL "build with ssl" OFF)
- option(USE_WS "build with websocket over http" OFF)
- option(USE_WSS "build with websocket over https" OFF)
- option(USE_SQLITE3 "build with sqlite3" ON)
- option(USE_ALL_SQLITE3 "build with sqlite3" OFF)
- option(USE_RAPIDJSON "build json by rapidjson" ON)
- option(USE_OPENSSL "build openssl" ON)
- IF(${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
- message(STATUS "build by wasm")
- SET(USE_WASM ON)
- set(USE_TCP OFF)
- set(USE_SSL OFF)
- set(USE_WS OFF)
- set(USE_WSS OFF)
- set(USE_SQLITE3 ON)
- set(USE_ALL_SQLITE3 OFF)
- add_definitions(-DUSE_WASM -D__linux__)
- ELSE()
- SET(USE_WASM OFF)
- ENDIF()
- IF(NOT USE_SQLITE3)
- SET(USE_ALL_SQLITE3 OFF)
- ENDIF()
- string(TIMESTAMP COMPILE_DATE %Y%m%d)
- string(TIMESTAMP COMPILE_TIME %H%M%S)
- SET(BUILD_DATE ${COMPILE_DATE})
- SET(BUILD_TIME ${COMPILE_TIME})
- message(STATUS "Building with ${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION} on ${CMAKE_SYSTEM}")
- INCLUDE(cmake/MSVCVer.cmake)
- INCLUDE(cmake/Utils.cmake)
- IF(MSVC)
- set(CMAKE_GENERATOR_PLATFORM x64)
- SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
- SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
- SET(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
- set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
- SET(ENABLE_MSVC_MP ON)
- MARK_AS_ADVANCED(WIN32_USE_MP)
- IF(WIN32_USE_MP)
- SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
- ENDIF(WIN32_USE_MP)
- ELSE()
- 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")
- set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -DDEBUG -O0 -g3")
- set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -DNDEBUG -O2 -g")
- set(CMAKE_POSITION_INDEPENDENT_CODE ON)
- ENDIF()
- set(CMAKE_INCLUDE_CURRENT_DIR ON)
- SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
- set(CMAKE_CONFIGURATION_TYPES "Debug;Release;")
- set(CMAKE_CXX_STANDARD 14)
- set(CMAKE_CXX_STANDARD_REQUIRED ON)
- set(CMAKE_CXX_EXTENSIONS OFF)
- SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin/${SYS})
- SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin/${SYS})
- SET(INCDIR ${PROJECT_SOURCE_DIR}/inc)
- if(WIN32)
- add_compile_options(/wd4251)
- add_compile_options(/wd4275)
- #add_definitions(-DNOMINMAX)
- if(MSVC)
- add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
- endif()
- endif()
- include_directories(${PROJECT_SOURCE_DIR}/inc)
- configure_file(${PROJECT_SOURCE_DIR}/inc/MqttBuildInfo.h.in
- ${PROJECT_SOURCE_DIR}/inc/MqttBuildInfo.h)
- add_definitions(-DSQLITE_HAS_CODEC
- -DSQLITE_ENABLE_COLUMN_METADATA
- -DSQLITE_TEMP_STORE=2
- )
- IF(USE_OPENSSL)
- add_subdirectory(src/libressl)
- set(OPENSSL_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/src/libressl/include)
- ELSE()
- add_subdirectory(src/crypt)
- set(OPENSSL_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/src/crypt/include)
- ENDIF()
- if(USE_SQLITE3)
- add_subdirectory(src/sqlcipher)
- endif()
- add_subdirectory(src/protobuf)
- add_subdirectory(src/proto)
- IF(NOT USE_WASM)
- add_subdirectory(src/MqttClient)
- add_subdirectory(tests)
- ENDIF()
|