From c7050c6de600bc5d2f3bee0d1b00d12bbb71be85 Mon Sep 17 00:00:00 2001 From: Yulin Li Date: Fri, 13 Jan 2023 17:08:06 +0800 Subject: [PATCH 1/3] update scripts/cmake files to imporve shared lib build propcess --- build-gtest.sh | 4 ++-- build-tests.sh | 3 ++- build.sh | 3 ++- lib/CMakeLists.txt | 4 +++- tests/functests/CMakeLists.txt | 9 +++++---- tests/unittests/CMakeLists.txt | 9 +++++---- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/build-gtest.sh b/build-gtest.sh index c92c0f2dc..6243f112f 100755 --- a/build-gtest.sh +++ b/build-gtest.sh @@ -27,8 +27,8 @@ fi echo "Add ios and arm64 build steps for googletest" cat > $GTEST_PATH/CMakeLists_temp.txt << EOF # If building for iOS, set all the iOS options -if(BUILD_IOS) - set(TARGET_ARCH "APPLE") +if(BUILD_IOS) + set(TARGET_ARCH "APPLE") set(IOS True) set(APPLE True) set(CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment target for iOS" FORCE) diff --git a/build-tests.sh b/build-tests.sh index 15b07fed6..7bf7886fa 100755 --- a/build-tests.sh +++ b/build-tests.sh @@ -1,8 +1,9 @@ #!/bin/sh cd "${0%/*}" SKU=${1:-release} +LIBRARY=${2:-static} echo Building and running $SKU tests... -./build.sh ${SKU} +./build.sh ${SKU} -l ${LIBRARY} # Fail on test errors set -e cd out diff --git a/build.sh b/build.sh index bafcd00ef..75760243a 100755 --- a/build.sh +++ b/build.sh @@ -21,6 +21,7 @@ fi if [ "$1" == "release" ] || [ "$2" == "release" ] || [ "$3" == "release" ]; then BUILD_TYPE="Release" + shift; else BUILD_TYPE="Debug" fi @@ -162,7 +163,7 @@ make package # Install newly generated package if [ -f /usr/bin/dpkg ]; then - # Ubuntu / Debian / Raspbian + # Ubuntu / Debian / Raspbian [[ -z "$NOROOT" ]] && sudo dpkg -i *.deb || echo "No root: skipping package deployment." elif [ -f /usr/bin/rpmbuild ]; then # Redhat / Centos diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 1055d8ec1..a18ffea00 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -248,7 +248,9 @@ if(BUILD_SHARED_LIBS STREQUAL "ON") # Prefer shared libraries for sqlite3 and zlib add_library(sqlite3 SHARED IMPORTED GLOBAL) add_library(z SHARED IMPORTED GLOBAL) - target_link_libraries(mat PUBLIC sqlite3 PUBLIC z ${LIBS} "${CMAKE_THREAD_LIBS_INIT}" "${CMAKE_DL_LIBS}" "${CMAKE_REQUIRED_LIBRARIES}") + find_package(SQLite3 REQUIRED) + find_package(ZLIB REQUIRED) + target_link_libraries(mat PUBLIC SQLite::SQLite3 PUBLIC ZLIB::ZLIB ${LIBS} "${CMAKE_THREAD_LIBS_INIT}" "${CMAKE_DL_LIBS}" "${CMAKE_REQUIRED_LIBRARIES}") endif() # target_link_libraries(mat PUBLIC libsqlite3 libcurl.a libz.a libssl.a libcrypto.a "${SQLITE_LIBRARY}" "${CMAKE_THREAD_LIBS_INIT}" "${CMAKE_DL_LIBS}" ) diff --git a/tests/functests/CMakeLists.txt b/tests/functests/CMakeLists.txt index ba0e524e7..824cf32c0 100644 --- a/tests/functests/CMakeLists.txt +++ b/tests/functests/CMakeLists.txt @@ -49,10 +49,10 @@ if(PAL_IMPLEMENTATION STREQUAL "WIN32") # Link against prebuilt libraries on Windows message("--- WIN32: Linking against prebuilt libraries") message("--- WIN32: ... ${CMAKE_BINARY_DIR}/gtest") - message("--- WIN32: ... ${CMAKE_BINARY_DIR}/gmock") + message("--- WIN32: ... ${CMAKE_BINARY_DIR}/gmock") message("--- WIN32: ... ${CMAKE_BINARY_DIR}/zlib") message("--- WIN32: ... ${CMAKE_BINARY_DIR}/sqlite") - # link_directories(${CMAKE_BINARY_DIR}/gtest/ ${CMAKE_BINARY_DIR}/gmock/ ${CMAKE_BINARY_DIR}/zlib/ ${CMAKE_BINARY_DIR}/sqlite/) + # link_directories(${CMAKE_BINARY_DIR}/gtest/ ${CMAKE_BINARY_DIR}/gmock/ ${CMAKE_BINARY_DIR}/zlib/ ${CMAKE_BINARY_DIR}/sqlite/) include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../../zlib ) target_link_libraries(FuncTests mat @@ -70,7 +70,8 @@ else() elseif(EXISTS "/usr/local/opt/sqlite/lib/libsqlite3.a") set (SQLITE3_LIB "/usr/local/opt/sqlite/lib/libsqlite3.a") else() - set (SQLITE3_LIB "sqlite3") + find_package(SQLite3 REQUIRED) + set (SQLITE3_LIB SQLite::SQLite3) endif() # Find zlib @@ -110,7 +111,7 @@ else() ${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/googletest/build/lib/ ) - target_link_libraries(FuncTests + target_link_libraries(FuncTests ${LIBGTEST} ${LIBGMOCK} mat diff --git a/tests/unittests/CMakeLists.txt b/tests/unittests/CMakeLists.txt index 37a7ed388..ea33faf58 100644 --- a/tests/unittests/CMakeLists.txt +++ b/tests/unittests/CMakeLists.txt @@ -60,12 +60,12 @@ endif() if (EXISTS ${CMAKE_SOURCE_DIR}/lib/modules/exp/tests) list(APPEND SRCS - ${CMAKE_SOURCE_DIR}/lib/modules/exp/tests/unittests/ECSConfigCacheTests.cpp + ${CMAKE_SOURCE_DIR}/lib/modules/exp/tests/unittests/ECSConfigCacheTests.cpp ${CMAKE_SOURCE_DIR}/lib/modules/exp/tests/unittests/ECSClientUtilsTests.cpp ${CMAKE_SOURCE_DIR}/lib/modules/exp/tests/unittests/ECSClientTests.cpp ) endif() - + if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/modules/privacyguard/ AND BUILD_PRIVACYGUARD) add_definitions(-DHAVE_MAT_PRIVACYGUARD) list(APPEND SRCS @@ -114,7 +114,8 @@ else() elseif(EXISTS "/usr/local/opt/sqlite/lib/libsqlite3.a") set (SQLITE3_LIB "/usr/local/opt/sqlite/lib/libsqlite3.a") else() - set (SQLITE3_LIB "sqlite3") + find_package(SQLite3 REQUIRED) + set (SQLITE3_LIB SQLite::SQLite3) endif() # Find zlib @@ -154,7 +155,7 @@ else() ${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/googletest/build/lib/ ) - target_link_libraries(UnitTests + target_link_libraries(UnitTests ${LIBGTEST} ${LIBGMOCK} mat From 673c5ca070c536e5819e76237b417fc941e21b29 Mon Sep 17 00:00:00 2001 From: Yulin Li Date: Sat, 21 Jan 2023 16:21:30 +0800 Subject: [PATCH 2/3] revert --- build-tests.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build-tests.sh b/build-tests.sh index 7bf7886fa..15b07fed6 100755 --- a/build-tests.sh +++ b/build-tests.sh @@ -1,9 +1,8 @@ #!/bin/sh cd "${0%/*}" SKU=${1:-release} -LIBRARY=${2:-static} echo Building and running $SKU tests... -./build.sh ${SKU} -l ${LIBRARY} +./build.sh ${SKU} # Fail on test errors set -e cd out From e8389d752ca1dfcfaf47ce3f2420a4eeff0c07e0 Mon Sep 17 00:00:00 2001 From: Yulin Li Date: Sat, 21 Jan 2023 16:22:39 +0800 Subject: [PATCH 3/3] revert --- build.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/build.sh b/build.sh index 75760243a..2d61b0902 100755 --- a/build.sh +++ b/build.sh @@ -21,7 +21,6 @@ fi if [ "$1" == "release" ] || [ "$2" == "release" ] || [ "$3" == "release" ]; then BUILD_TYPE="Release" - shift; else BUILD_TYPE="Debug" fi