Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use find_packages in cmake files to for shared lib build #1084

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
6 changes: 3 additions & 3 deletions build-gtest.sh
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ fi

cd `dirname $0`
GTEST_PATH=third_party/googletest
if [ ! "$(ls -A $GTEST_PATH/CMakeLists.txt)" ]; then
if [ ! "$(ls -A $GTEST_PATH/CMakeLists.txt)" ]; then
echo Clone googletest from google/googletest:master ...
rm -rf ${GTEST_PATH} #delete just if empty directory exists
git clone --depth 1 --branch release-1.12.1 https://github.com/google/googletest $GTEST_PATH
@@ -32,10 +32,10 @@ if(BUILD_IOS)
message("-- CMAKE_OSX_DEPLOYMENT_TARGET \${CMAKE_OSX_DEPLOYMENT_TARGET}")
message("-- CMAKE_SYSTEM_NAME \${CMAKE_SYSTEM_NAME}")
message("-- CMAKE_OSX_ARCHITECTURES \${CMAKE_OSX_ARCHITECTURES}")
set(TARGET_ARCH "APPLE")
set(TARGET_ARCH "APPLE")
set(IOS True)
set(APPLE True)
set(CMAKE_SYSTEM_NAME iOS)
set(CMAKE_SYSTEM_NAME iOS)
set(CMAKE_OSX_DEPLOYMENT_TARGET "12.2" CACHE STRING "Force set of the deployment target for iOS" FORCE)
set(CMAKE_C_FLAGS "\${CMAKE_C_FLAGS} -miphoneos-version-min=10.0")
set(CMAKE_CXX_FLAGS "\${CMAKE_CXX_FLAGS} -miphoneos-version-min=10.0 -std=c++11")
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -193,7 +193,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
4 changes: 3 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -276,7 +276,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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find_package(SQLite3 REQUIRED)

Is there any scenario where the call to find_package(SQLite3 REQUIRED) is required? Assume the current hard-coded name still works, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the current hard-coded name still works. But I think the find_package is a preferred way by cmake, and it will report a clearer error if sqlite3 is not installed

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}" )
9 changes: 5 additions & 4 deletions tests/functests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -59,10 +59,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
@@ -80,7 +80,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
@@ -122,7 +123,7 @@ else()
${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/googletest/build/lib/
)

target_link_libraries(FuncTests
target_link_libraries(FuncTests
${LIBGTEST}
${LIBGMOCK}
mat
9 changes: 5 additions & 4 deletions tests/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -61,12 +61,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
@@ -119,7 +119,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
@@ -164,7 +165,7 @@ else()
message("GTEST: ${LIBGTEST}")
message("GMOCK: ${LIBGMOCK}")

target_link_libraries(UnitTests
target_link_libraries(UnitTests
${LIBGTEST}
${LIBGMOCK}
mat