Skip to content

Calling find_package() to find CMSIS multiple times leads to errors #326

@Joaliasbarb

Description

@Joaliasbarb

Describe the bug
CMake errors are popping up when calling find_package multiple times.

CMake Error at C:/heig-vd/projects/stm32-cmake/stm32-cmake-multiple-find-package-calls/cmake/FindCMSIS.cmake:107 (add_custom_target):
  add_custom_target cannot create target "CMSIS_LD_F401CB" because another
  target with the same name already exists.  The existing target is a custom
  target created in source directory
  "C:/heig-vd/projects/stm32-cmake/stm32-cmake-multiple-find-package-calls/examples/blinky".
  See documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  C:/heig-vd/projects/stm32-cmake/stm32-cmake-multiple-find-package-calls/cmake/FindCMSIS.cmake:268 (cmsis_generate_default_linker_script)
  CMakeLists.txt:41 (find_package)


CMake Error at C:/heig-vd/projects/stm32-cmake/stm32-cmake-multiple-find-package-calls/cmake/FindCMSIS.cmake:266 (add_library):
  add_library cannot create imported target "CMSIS::STM32::F401CC" because
  another target with the same name already exists.
Call Stack (most recent call first):
  CMakeLists.txt:41 (find_package)


CMake Error at C:/heig-vd/projects/stm32-cmake/stm32-cmake-multiple-find-package-calls/cmake/FindCMSIS.cmake:107 (add_custom_target):
  add_custom_target cannot create target "CMSIS_LD_F401CC" because another
  target with the same name already exists.  The existing target is a custom
  target created in source directory
  "C:/heig-vd/projects/stm32-cmake/stm32-cmake-multiple-find-package-calls/examples/blinky".
  See documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  C:/heig-vd/projects/stm32-cmake/stm32-cmake-multiple-find-package-calls/cmake/FindCMSIS.cmake:268 (cmsis_generate_default_linker_script)
  CMakeLists.txt:41 (find_package)

Sources to reproduce
Please provide link to repository showing the problem.
link to the commit causing an issue

Steps to reproduce

  1. Add multiple calls to the find_package function for CMSIS.

Expected behavior
On the first find_package call, the behavior shall not change. On subsequent calls, already existing custom targets shall not be created again.

Environment :

  • OS: Windows
  • Compiler: arm-none-eabi-gcc (Arm GNU Toolchain 12.2.MPACBTI-Rel1 (Build arm-12-mpacbti.34)) 12.2.1 20230214
  • stm32-cmake: v2.1.0
  • cmake: 3.25.0
  • HAL/cube/CMSIS: stm32cubeF4 v1.27.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions