ulib/3party/rpc_core/CMakeLists.txt
tqcq c3b5a29da2
All checks were successful
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Successful in 1m6s
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Successful in 1m9s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Successful in 1m17s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Successful in 1m22s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Successful in 1m39s
linux-mips64-gcc / linux-gcc-mips64el (push) Successful in 1m48s
linux-x64-gcc / linux-gcc (push) Successful in 2m3s
feat add rpc_core
2024-01-21 16:05:01 +08:00

55 lines
2.1 KiB
CMake

cmake_minimum_required(VERSION 3.5)
project(rpc_core CXX)
option(RPC_CORE_BUILD_TEST "" OFF)
option(RPC_CORE_TEST_PLUGIN "" OFF)
option(RPC_CORE_TEST_LINK_PTHREAD "" OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(RPC_CORE_BUILD_TEST ON)
endif ()
set(CMAKE_CXX_STANDARD 11)
add_compile_options(-Wall -Wunused-parameter)
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE include)
if (RPC_CORE_BUILD_TEST)
set(EXAMPLE_COMPILE_DEFINE
ANDROID_STANDALONE
RPC_CORE_LOG_SHOW_DEBUG
# RPC_CORE_LOG_SHOW_VERBOSE
)
set(TARGET_NAME ${PROJECT_NAME}_test)
file(GLOB SRCS test/main.cpp test/test_rpc.cpp test/test_serialize.cpp test/test_data_packer.cpp)
add_executable(${TARGET_NAME})
if (RPC_CORE_TEST_LINK_PTHREAD)
# some linux platform need link -pthread for std::future api
set(LIBRARIES -pthread)
endif ()
target_link_libraries(${TARGET_NAME} ${PROJECT_NAME} ${LIBRARIES})
target_compile_definitions(${TARGET_NAME} PRIVATE ${EXAMPLE_COMPILE_DEFINE})
if (RPC_CORE_TEST_PLUGIN)
list(APPEND SRCS test/test_plugin.cpp)
target_compile_definitions(${TARGET_NAME} PRIVATE "RPC_CORE_TEST_PLUGIN")
add_custom_target(${TARGET_NAME}_init
# clear dir
COMMAND rm -rf ${CMAKE_CURRENT_LIST_DIR}/thirdparty
# json
COMMAND mkdir -p ${CMAKE_CURRENT_LIST_DIR}/thirdparty/nlohmann
COMMAND curl -L -o ${CMAKE_CURRENT_LIST_DIR}/thirdparty/nlohmann/json.hpp https://github.com/nlohmann/json/releases/download/v3.11.2/json.hpp
# flatbuffers
COMMAND git clone https://github.com/google/flatbuffers.git --depth=1 --branch=v23.1.21 ${CMAKE_CURRENT_LIST_DIR}/thirdparty/flatbuffers
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)
target_include_directories(${TARGET_NAME} PRIVATE thirdparty)
target_include_directories(${TARGET_NAME} PRIVATE thirdparty/flatbuffers/include)
endif ()
target_sources(${TARGET_NAME} PRIVATE ${SRCS})
endif ()