leleliu008 / ndk-pkg

A package builder/manager for Android NDK to build projects written in C, C++, Rust, Golang, etc.
http://blog.fpliu.com/project/ndk-pkg
Apache License 2.0
88 stars 14 forks source link

cmake can't find package #29

Closed eSKond closed 3 weeks ago

eSKond commented 1 month ago

I'm sorry but i don't understand how to use ndk-pkg installed packages in cmake projects. And yes, i have read documentation hundred times, moreover i have read instructions shown in terminal on ndk-pkg deploy. I added all suggested to build.gradle, i added all suggested to CMakeLists.txt but building says:

CMake Error at CMakeLists.txt:188 (find_package): Could not find a package configuration file provided by "somelib" with any of the following names:

somelibConfig.cmake somelib-config.cmake

Add the installation prefix of "somelib" to CMAKE_PREFIX_PATH or set "somelib_DIR" to a directory containing one of the above files. If "somelib" provides a separate development package or SDK, be sure it has been installed.

What do i do wrong?

leleliu008 commented 1 month ago

could you show me :

  1. the ndk-pkg commands you run
  2. your build.gradle
  3. your CMakeLists.txt
eSKond commented 1 month ago
  1. ./ndk-pkg deploy android-34-arm64-v8a/libssh --ndk-home=/Users/sergey/Library/Android/sdk/ndk/25.2.9519653
  2. 
    buildscript {
    repositories {
        google()
        mavenCentral()
        mavenLocal()
    }
    
    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.1'
    }
    }

repositories { google() mavenCentral() mavenLocal() }

apply plugin: 'com.android.application'

dependencies { implementation fileTree(dir: 'libs', include: ['.jar', '.aar']) implementation 'androidx.core:core:1.10.1' implementation 'com.fpliu.ndk.pkg.prefab.android.34:libssh:0.10.6@aar' }

android { /***

project(myapp VERSION 0.1 LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)

qt_standard_project_setup(REQUIRES 6.5)

...

libssh

find_package(libssh REQUIRED CONFIG)

qt_add_executable(appmyapp main.cpp ... MANUAL_FINALIZATION )

qt_add_qml_module(appmyapp URI myapp VERSION 1.0 QML_FILES Main.qml MainPage.qml ... RESOURCES android/AndroidManifest.xml android/build.gradle android/res/values/libs.xml android/res/values/strings.xml android/res/xml/qtprovider_paths.xml android/gradle/wrapper/gradle-wrapper.jar android/gradle/wrapper/gradle-wrapper.properties android/gradle.properties android/gradlew android/gradlew.bat SOURCES ... )

Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.

If you are developing for iOS or macOS you should consider setting an

explicit, fixed bundle identifier manually though.

set_target_properties(appmyapp PROPERTIES

MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appmyapp

MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE

)

set_property(TARGET appmyapp APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/android )

target_include_directories(appmyapp PRIVATE ${SOME_INCLUDE_DIRS}) target_link_libraries(appmyapp PRIVATE Qt6::Quick ... libssh::libssh.a )

include(GNUInstallDirs) install(TARGETS appmyapp BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )

qt_finalize_executable(appmyapp)

leleliu008 commented 1 month ago

libssh's dependencies are also should be deploied by yourself.

./ndk-pkg deploy android-34-arm64-v8a/openssl-dev
./ndk-pkg deploy android-34-arm64-v8a/libz
./ndk-pkg deploy android-34-arm64-v8a/libssh
implementation 'com.fpliu.ndk.pkg.prefab.android.34:openssl-dev:3.3.0@aar'
implementation 'com.fpliu.ndk.pkg.prefab.android.34:libz:1.3.1@aar'
implementation 'com.fpliu.ndk.pkg.prefab.android.34:libssh:0.10.6@aar'
find_package(openssl-dev REQUIRED CONFIG)
find_package(libz REQUIRED CONFIG)
find_package(libssh REQUIRED CONFIG)

target_link_libraries(app libssh::libssh.so)
target_link_libraries(app libz::libz.so)
target_link_libraries(app openssl-dev::libcrypto.so)
eSKond commented 1 month ago

i just tried link openssl-dev and it have same error:

CMake Error at CMakeLists.txt:192 (find_package):
  Could not find a package configuration file provided by "openssl-dev" with
  any of the following names:

    openssl-devConfig.cmake
    openssl-dev-config.cmake

  Add the installation prefix of "openssl-dev" to CMAKE_PREFIX_PATH or set
  "openssl-dev_DIR" to a directory containing one of the above files.  If
  "openssl-dev" provides a separate development package or SDK, be sure it
  has been installed.

Could you explain how cmake should find package if there is no any path to ndp-pkg or maven repository in CMakeLists.txt?

eSKond commented 1 month ago

btw i can link all libraries with something like:

set(NDK_PKG_HOME_DIR /Users/sergey/.ndk-pkg)
add_library(
        libssh
        STATIC
        IMPORTED
)
set_target_properties(
        libssh
        PROPERTIES IMPORTED_LOCATION
        ${NDK_PKG_HOME_DIR}/installed/android-34-arm64-v8a/libssh/lib/libssh.a
)

but perhaps it's not expected way of using ndk-pkg, right?

leleliu008 commented 1 month ago

i just tried link openssl-dev and it have same error:

CMake Error at CMakeLists.txt:192 (find_package):
  Could not find a package configuration file provided by "openssl-dev" with
  any of the following names:

    openssl-devConfig.cmake
    openssl-dev-config.cmake

  Add the installation prefix of "openssl-dev" to CMAKE_PREFIX_PATH or set
  "openssl-dev_DIR" to a directory containing one of the above files.  If
  "openssl-dev" provides a separate development package or SDK, be sure it
  has been installed.

Could you explain how cmake should find package if there is no any path to ndp-pkg or maven repository in CMakeLists.txt?

I tried locally, it works for me.

leleliu008 commented 1 month ago

btw i can link all libraries with something like:

set(NDK_PKG_HOME_DIR /Users/sergey/.ndk-pkg)
add_library(
        libssh
        STATIC
        IMPORTED
)
set_target_properties(
        libssh
        PROPERTIES IMPORTED_LOCATION
        ${NDK_PKG_HOME_DIR}/installed/android-34-arm64-v8a/libssh/lib/libssh.a
)

but perhaps it's not expected way of using ndk-pkg, right?

It works but not a normal way.

leleliu008 commented 1 month ago
find_package(openssl-dev REQUIRED CONFIG)
find_package(libz REQUIRED CONFIG)
find_package(libssh REQUIRED CONFIG)

target_link_libraries(app libssh::libssh.so)
target_link_libraries(app libz::libz.so)
target_link_libraries(app openssl-dev::libcrypto.so)
leleliu008 commented 1 month ago

or

find_package(openssl-dev REQUIRED CONFIG)
find_package(libz REQUIRED CONFIG)
find_package(libssh REQUIRED CONFIG)

target_link_libraries(app libssh::libssh.a)
target_link_libraries(app libz::libz.a)
target_link_libraries(app openssl-dev::libcrypto.a)
eSKond commented 1 month ago

see my message above - i tried link only libz or openssl-dev - same problem - cmake can't find package. It may be related with some macos individual issues, i don't know. Btw, now, after few attempts uninstall/reinstall/install it started ignore --static and installs libssh.so without libssh.a, but after few more reinstallation (including ndk-pkg) it stopped install (can't find formulae) any library. So i'm sorry for boring you, i'm going to stop attempts to use ndk-pkg in my project, so let close this thread.

leleliu008 commented 1 month ago

I'm sorry. my local test works well. This is a example https://github.com/leleliu008/android-calendar-for-the-aged , but it use Kotlin script not Groovy script.

leleliu008 commented 1 month ago

btw i can link all libraries with something like:

set(NDK_PKG_HOME_DIR /Users/sergey/.ndk-pkg)
add_library(
        libssh
        STATIC
        IMPORTED
)
set_target_properties(
        libssh
        PROPERTIES IMPORTED_LOCATION
        ${NDK_PKG_HOME_DIR}/installed/android-34-arm64-v8a/libssh/lib/libssh.a
)

but perhaps it's not expected way of using ndk-pkg, right?

This is actually what the Android Gradle Plugin doing.

AGP generates app/.cxx/RelWithDebInfo/3g645a1v/prefab/arm64-v8a/prefab/lib/aarch64-linux-android/cmake/openssl-dev/openssl-devConfig.cmake

if(NOT TARGET openssl-dev::headers)
add_library(openssl-dev::headers INTERFACE IMPORTED)
set_target_properties(openssl-dev::headers PROPERTIES
    INTERFACE_INCLUDE_DIRECTORIES "/home/leleliu008/.gradle/caches/transforms-3/fde0bd0333cf75f28a02aa4fabb6221d/transformed/openssl-dev-3.3.0/prefab/modules/headers/include"
    INTERFACE_LINK_LIBRARIES ""
)
endif()

if(NOT TARGET openssl-dev::libcrypto.a)
add_library(openssl-dev::libcrypto.a STATIC IMPORTED)
set_target_properties(openssl-dev::libcrypto.a PROPERTIES
    IMPORTED_LOCATION "/home/leleliu008/.gradle/caches/transforms-3/fde0bd0333cf75f28a02aa4fabb6221d/transformed/openssl-dev-3.3.0/prefab/modules/libcrypto.a/libs/android.arm64-v8a/libcrypto.a"
    INTERFACE_INCLUDE_DIRECTORIES "/home/leleliu008/.gradle/caches/transforms-3/fde0bd0333cf75f28a02aa4fabb6221d/transformed/openssl-dev-3.3.0/prefab/modules/libcrypto.a/libs/android.arm64-v8a/include"
    INTERFACE_LINK_LIBRARIES ""
)
endif()

if(NOT TARGET openssl-dev::libcrypto.so)
add_library(openssl-dev::libcrypto.so SHARED IMPORTED)
set_target_properties(openssl-dev::libcrypto.so PROPERTIES
    IMPORTED_LOCATION "/home/leleliu008/.gradle/caches/transforms-3/fde0bd0333cf75f28a02aa4fabb6221d/transformed/openssl-dev-3.3.0/prefab/modules/libcrypto.so/libs/android.arm64-v8a/libcrypto.so"
    INTERFACE_INCLUDE_DIRECTORIES "/home/leleliu008/.gradle/caches/transforms-3/fde0bd0333cf75f28a02aa4fabb6221d/transformed/openssl-dev-3.3.0/prefab/modules/libcrypto.so/libs/android.arm64-v8a/include"
    INTERFACE_LINK_LIBRARIES ""
)
endif()

if(NOT TARGET openssl-dev::libssl.a)
add_library(openssl-dev::libssl.a STATIC IMPORTED)
set_target_properties(openssl-dev::libssl.a PROPERTIES
    IMPORTED_LOCATION "/home/leleliu008/.gradle/caches/transforms-3/fde0bd0333cf75f28a02aa4fabb6221d/transformed/openssl-dev-3.3.0/prefab/modules/libssl.a/libs/android.arm64-v8a/libssl.a"
    INTERFACE_INCLUDE_DIRECTORIES "/home/leleliu008/.gradle/caches/transforms-3/fde0bd0333cf75f28a02aa4fabb6221d/transformed/openssl-dev-3.3.0/prefab/modules/libssl.a/libs/android.arm64-v8a/include"
    INTERFACE_LINK_LIBRARIES ""
)
endif()

if(NOT TARGET openssl-dev::libssl.so)
add_library(openssl-dev::libssl.so SHARED IMPORTED)
set_target_properties(openssl-dev::libssl.so PROPERTIES
    IMPORTED_LOCATION "/home/leleliu008/.gradle/caches/transforms-3/fde0bd0333cf75f28a02aa4fabb6221d/transformed/openssl-dev-3.3.0/prefab/modules/libssl.so/libs/android.arm64-v8a/libssl.so"
    INTERFACE_INCLUDE_DIRECTORIES "/home/leleliu008/.gradle/caches/transforms-3/fde0bd0333cf75f28a02aa4fabb6221d/transformed/openssl-dev-3.3.0/prefab/modules/libssl.so/libs/android.arm64-v8a/include"
    INTERFACE_LINK_LIBRARIES ""
)
endif()