1 Star 0 Fork 225

bluhuang/distributeddatamgr_kv_store

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
CMakeLists.txt 10.40 KB
一键复制 编辑 原始数据 按行查看 历史
bluhuang 提交于 2023-11-15 09:31 . add macro for multi ver
cmake_minimum_required(VERSION 3.2)
project(distributed_ut VERSION 1.0.0)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++17 -pthread")
add_compile_options(-Werror=sign-compare)
add_compile_options(-Wno-conversion-null)
add_compile_options(-Wuninitialized)
add_compile_options(-Wformat)
add_compile_options(-Wno-deprecated-declarations)
# Address Sanitizer
option(USE_ASAN "Compile with address sanitiser" OFF)
if (USE_ASAN)
message(STATUS "Compile with address sanitiser ${USE_ASAN}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer -O1")
endif()
function(download_repo repo_name repo_url)
execute_process(
COMMAND [ -d ${repo_name} ]
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party
RESULT_VARIABLE REPO_EXISTS
)
message(STATUS "check ${repo_name} exists result: ${REPO_EXISTS}")
if (NOT (${REPO_EXISTS} EQUAL 0))
message(STATUS "Downloading ${repo_name} from ${repo_url}")
execute_process(
COMMAND git clone ${repo_url}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party
)
message(STATUS "Download ${repo_name} finished")
endif()
endfunction(download_repo)
# create third_party directory
execute_process(
COMMAND mkdir -p ${PROJECT_SOURCE_DIR}/third_party
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
# Download dependencies
download_repo("third_party_jsoncpp" "https://gitee.com/openharmony/third_party_jsoncpp.git")
download_repo("third_party_googletest" "https://gitee.com/openharmony/third_party_googletest.git")
download_repo("third_party_openssl" "https://gitee.com/openharmony/third_party_openssl.git")
download_repo("third_party_zlib" "https://gitee.com/openharmony/third_party_zlib.git")
download_repo("third_party_sqlite" "https://gitee.com/openharmony/third_party_sqlite.git")
download_repo("utils_native" "https://gitee.com/openharmony/utils_native.git")
download_repo("kate" "https://gitee.com/lianhuix/kate.git")
download_repo("third_party_cJSON" "https://gitee.com/openharmony/third_party_cJSON.git")
function(build_repo repo_name script_path)
execute_process(
COMMAND [ -f ${repo_name}/Makefile ]
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party
RESULT_VARIABLE SCRIPT_EXISTS
)
if (NOT (${SCRIPT_EXISTS} EQUAL 0))
message(STATUS "Copy build script ${script_path}/Makefile to repo ${repo_name}")
execute_process(
COMMAND cp third_party/kate/${script_path}/Makefile third_party/${repo_name} -f
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
message(STATUS "Build ${repo_name}")
execute_process(
COMMAND make -j9
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name}
)
message(STATUS "Build finished")
endif()
endfunction(build_repo)
function(cmake_repo repo_name)
execute_process(
COMMAND [ -d ${repo_name}/build ]
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party
RESULT_VARIABLE BUILD_FINISHED
)
if (NOT (${BUILD_FINISHED} EQUAL 0))
message(STATUS "compile repo ${repo_name}")
execute_process(
COMMAND mkdir -p build
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name}
)
execute_process(
COMMAND cmake ..
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name}/build
)
execute_process(
COMMAND make -j9
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name}/build
)
endif()
endfunction(cmake_repo)
function(build_openssl repo_name)
execute_process(
COMMAND [ -f Makefile ]
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name}
RESULT_VARIABLE BUILD_FINISHED
)
if (NOT (${BUILD_FINISHED} EQUAL 0))
message(STATUS "compile repo ${repo_name}")
execute_process(
COMMAND chmod +x ./config
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name}
)
execute_process(
COMMAND ./config
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name}
)
execute_process(
COMMAND make -j9
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name}
)
endif()
endfunction(build_openssl)
# build openssl Makefile
build_openssl("third_party_openssl")
# build securec
build_repo("utils_native" "securec")
# build sqlite
build_repo("third_party_sqlite" "sqlite")
# build jsoncpp
cmake_repo("third_party_jsoncpp")
# build zlib
cmake_repo("third_party_zlib")
# build cJSON
cmake_repo("third_party_cJSON" "cJSON")
#build googletest
execute_process(
COMMAND sed -i /Wshadow/d internal_utils.cmake
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/third_party_googletest/googletest/cmake
)
execute_process(
COMMAND sed -i "s%testing::GTEST_FLAG(output)%// testing::GTEST_FLAG(output)%g" googlemock/src/gmock_main.cc
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/third_party_googletest
)
execute_process(
COMMAND sed -i "s%testing::GTEST_FLAG(output)%// testing::GTEST_FLAG(output)%g" googletest/src/gtest_main.cc
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/third_party_googletest
)
cmake_repo("third_party_googletest")
# add_definitions(-Wno-format)
add_definitions(-DSQLITE_ENABLE_SNAPSHOT)
add_definitions(-D_LARGEFILE64_SOURCE)
add_definitions(-D_FILE_OFFSET_BITS=64)
add_definitions(-DSQLITE_HAS_CODEC)
add_definitions(-DSQLITE_ENABLE_JSON1)
add_definitions(-DUSING_HILOG_LOGGER)
# add_definitions(-DUSE_SQLITE_SYMBOLS)
add_definitions(-DUSING_DB_JSON_EXTRACT_AUTOMATICALLY)
add_definitions(-DJSONCPP_USE_BUILDER)
add_definitions(-DOMIT_FLATBUFFER)
add_definitions(-DUSE_PRINT)
add_definitions(-DRELATIONAL_STORE)
add_definitions(-DMANNUAL_SYNC_AND_CLEAN_CLOUD_DATA)
# add_definitions(-DSQLITE3_HW_EXPORT_SYMBOLS)
add_definitions(-DTEST_DB)
add_definitions(-DDB_DEBUG_ENV)
add_definitions(-DTESTCASES_USING_GTEST_EXT)
add_definitions(-DSQLITE_DISTRIBUTE_RELATIONAL)
add_definitions(-DSQLITE_ENABLE_DROPTABLE_CALLBACK)
add_definitions(-DRUNNING_ON_TESTCASE)
add_definitions(-DOMIT_MULTI_VER)
# build cJSON
#cmake_repo("third_party_cJSON" "cJSON")
add_definitions(-DDB_DEBUG_ENV)
find_package(Threads)
enable_testing()
set(DB_PATH ${PROJECT_SOURCE_DIR}/frameworks/libs/distributeddb)
include_directories(
${DB_PATH}/common/include
${DB_PATH}/common/include/relational
${DB_PATH}/common/include/cloud
${DB_PATH}/common/src
${DB_PATH}/common/src/evloop/include
${DB_PATH}/common/src/evloop/src
${DB_PATH}/common/src/cloud
${DB_PATH}/communicator/include
${DB_PATH}/communicator/src
${DB_PATH}/include
${DB_PATH}/interfaces/include
${DB_PATH}/interfaces/include/cloud
${DB_PATH}/interfaces/include/relational
${DB_PATH}/interfaces/src
${DB_PATH}/interfaces/src/relational
${DB_PATH}/storage/include
${DB_PATH}/storage/src
${DB_PATH}/storage/src/multiver
${DB_PATH}/storage/src/operation
${DB_PATH}/storage/src/sqlite
${DB_PATH}/storage/src/naturalbase_lite
${DB_PATH}/storage/src/sqlite/relational
${DB_PATH}/storage/src/upgrader
${DB_PATH}/storage/src/gaussdb_rd
${DB_PATH}/syncer/include
${DB_PATH}/syncer/src
${DB_PATH}/syncer/src/cloud
${DB_PATH}/test/unittest/common/common
${DB_PATH}/test/unittest/common/communicator
${DB_PATH}/test/unittest/common/interfaces
${DB_PATH}/test/unittest/common/storage
${DB_PATH}/test/unittest/common/syncer
${DB_PATH}/test/unittest/common/syncer/cloud
)
include_directories(
${PROJECT_SOURCE_DIR}/third_party/third_party_cJSON
${PROJECT_SOURCE_DIR}/third_party/third_party_googletest/googletest/include
${PROJECT_SOURCE_DIR}/third_party/third_party_googletest/googlemock/include
${PROJECT_SOURCE_DIR}/third_party/third_party_jsoncpp/include
${PROJECT_SOURCE_DIR}/third_party/third_party_sqlite/include
${PROJECT_SOURCE_DIR}/third_party/utils_native/base/include
${PROJECT_SOURCE_DIR}/third_party/utils_native/base/src/securec
${PROJECT_SOURCE_DIR}/third_party/third_party_openssl/include
${PROJECT_SOURCE_DIR}/third_party/third_party_zlib
${PROJECT_SOURCE_DIR}/third_party/kate/log/include
)
link_directories(
${PROJECT_SOURCE_DIR}/third_party/third_party_googletest/build/lib
${PROJECT_SOURCE_DIR}/third_party/third_party_jsoncpp/build/lib
${PROJECT_SOURCE_DIR}/third_party/third_party_openssl
${PROJECT_SOURCE_DIR}/third_party/third_party_zlib/build
${PROJECT_SOURCE_DIR}/third_party/third_party_sqlite
${PROJECT_SOURCE_DIR}/third_party/utils_native
${PROJECT_SOURCE_DIR}/third_party/third_party_cJSON/build
)
message("DB_PATH = ${DB_PATH}")
file(GLOB_RECURSE DISTRIBUTEDDB_SRC "${DB_PATH}/*.cpp")
list(REMOVE_ITEM DISTRIBUTEDDB_SRC "${DB_PATH}/test/unittest/common/storage/distributeddb_storage_encrypt_test.cpp")
file(GLOB_RECURSE RD_SRC "${DB_PATH}/gaussdb_rd/*.cpp")
list(REMOVE_ITEM DISTRIBUTEDDB_SRC ${RD_SRC})
foreach (ITR ${DISTRIBUTEDDB_SRC})
if ("${ITR}" MATCHES "(.*)moduletest(.*)")
# message(STATUS"Remove Item from List:${ITR}")
list (REMOVE_ITEM DISTRIBUTEDDB_SRC ${ITR})
endif ("${ITR}" MATCHES "(.*)moduletest(.*)")
endforeach(ITR)
file(GLOB_RECURSE FUZZTEST_SRC "${DB_PATH}/test/fuzztest/*.cpp")
if(FUZZTEST_SRC)
list(REMOVE_ITEM DISTRIBUTEDDB_SRC ${FUZZTEST_SRC})
endif()
set(DB_PATH ${PROJECT_SOURCE_DIR}/frameworks/libs/distributeddb)
add_executable(distributed_ut ${DISTRIBUTEDDB_SRC} ${SECUREC_SRC} ${SQLITE_SRC})
target_include_directories(distributed_ut PUBLIC
${DB_PATH}/gaussdb_rd/include
${DB_PATH}/gaussdb_rd/include/grd_base
${DB_PATH}/gaussdb_rd/include/grd_document
${DB_PATH}/gaussdb_rd/include/grd_kv )
target_link_libraries(
distributed_ut
pthread
${CMAKE_THREAD_LIBS_INIT}
${PROJECT_SOURCE_DIR}/frameworks/libs/distributeddb/gaussdb_rd/build/libdocument_rd.a
securec
jsoncpp
ssl
crypto
sqlite3
z
gtest
gtest_main
cjson
gmock
gmock_main
dl
gcov
)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/bluhuang/distributeddatamgr_kv_store.git
git@gitee.com:bluhuang/distributeddatamgr_kv_store.git
bluhuang
distributeddatamgr_kv_store
distributeddatamgr_kv_store
trunk

搜索帮助