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 12 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions build-gtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}" )
Expand Down
9 changes: 5 additions & 4 deletions tests/functests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,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
Expand All @@ -73,7 +73,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
Expand Down Expand Up @@ -113,7 +114,7 @@ else()
${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/googletest/build/lib/
)

target_link_libraries(FuncTests
target_link_libraries(FuncTests
${LIBGTEST}
${LIBGMOCK}
mat
Expand Down
9 changes: 5 additions & 4 deletions tests/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -115,7 +115,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
Expand Down Expand Up @@ -155,7 +156,7 @@ else()
${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/googletest/build/lib/
)

target_link_libraries(UnitTests
target_link_libraries(UnitTests
${LIBGTEST}
${LIBGMOCK}
mat
Expand Down
Loading