这是indexloc提供的服务,不要输入任何密码
Skip to content

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

@baarmaley

Description

@baarmaley

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions