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

[BUG] CMake plugin: creating a target on every call find_package() #128

Closed
baarmaley opened this issue Feb 10, 2021 · 3 comments · Fixed by #131
Closed

[BUG] CMake plugin: creating a target on every call find_package() #128

baarmaley opened this issue Feb 10, 2021 · 3 comments · Fixed by #131
Labels
bug Something isn't working

Comments

@baarmaley
Copy link

Describe the bug
If two packages depend on another package, the build will fail.
or
Call find_package() more than once for the same package

To Reproduce
Steps to reproduce the behavior:

  1. export library from vcpkg:
    ./vcpkg install boost-endian:arm-android boost-endian:arm64-android boost-endian:x86-android boost-endian:x64-android
    ./vcpkg export --triplet x64-android boost-endian --prefab --prefab-maven --prefab-debug
    add implementation 'com.vcpkg.ndk.support:boost-endian:1.75.0' in app/build.gradle
  2. click build in android studio

or

  1. CMakeLists.txt
find_package(asio CONFIG REQUIRED)
find_package(asio CONFIG REQUIRED)
  1. click build in android studio

Expected behavior
Build success.

Logs

> Task :app:generateJsonModelDebug FAILED
Execution failed for task ':app:generateJsonModelDebug'.
> /mnt/local/.../app/src/main/cpp/CMakeLists.txt : C/C   debug|armeabi-v7a : CMake Error at /mnt/local/.../app/.cxx/cmake/debug/prefab/armeabi-v7a/prefab/lib/arm-linux-androideabi/cmake/boost-compatibility/boost-compatibilityConfig.cmake:1 (add_library):
    add_library cannot create imported target
    "boost-compatibility::boost-compatibility" because another target with the
    same name already exists.
  Call Stack (most recent call first):
    /mnt/local/.../app/.cxx/cmake/debug/prefab/armeabi-v7a/prefab/lib/arm-linux-androideabi/cmake/boost-config/boost-configConfig.cmake:1 (find_package)
    /mnt/local/.../app/.cxx/cmake/debug/prefab/armeabi-v7a/prefab/lib/arm-linux-androideabi/cmake/boost-core/boost-coreConfig.cmake:1 (find_package)
    /mnt/local/.../app/.cxx/cmake/debug/prefab/armeabi-v7a/prefab/lib/arm-linux-androideabi/cmake/boost-endian/boost-endianConfig.cmake:3 (find_package)
    .../CMakeLists.txt:11 (find_package)

Environment:
Prefab version: 1.1.2

Additional context
In generated * Config.cmake needs target guard.
eg

if(NOT TARGET $target)
    add_library($target ...)
    set_target_properties($target ...)
endif()
@baarmaley baarmaley added the bug Something isn't working label Feb 10, 2021
@DanAlbert
Copy link
Member

Thanks for the report. Unsure when I'll be able to find the time, but looks like it should be an easy fix. Will get a release out to fix it as soon as I can.

DanAlbert added a commit to DanAlbert/prefab that referenced this issue Mar 12, 2021
Protects against duplicate definition errors when a package is
included multiple times in CMake.

No change needed for ndk-build because it handles this internally.

Fixes google#128
@DanAlbert
Copy link
Member

#131 fixes this. Going to try to bundle it with another fix or two in the next week and will push out a release with them.

DanAlbert added a commit that referenced this issue Mar 13, 2021
Protects against duplicate definition errors when a package is
included multiple times in CMake.

No change needed for ndk-build because it handles this internally.

Fixes #128
@DanAlbert
Copy link
Member

https://github.com/google/prefab/releases/tag/v1.1.3

(android.prefabVersion=1.1.3 in your gradle.properties file)

msatranjr pushed a commit to msft-mirror-aosp/platform.prebuilts.tools that referenced this issue Feb 8, 2023
Test: presubmit
Bug: google/prefab#128
Bug: google/prefab#132
Change-Id: I00ef7bf7a03b9ec5cfeadad06480310303de3934
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants