open-dis / open-dis-cpp

C++ implementation of the IEEE-1278.1 Distributed Interactive Simulation (DIS) application protocol v6 and v7
BSD 2-Clause "Simplified" License
90 stars 65 forks source link

Alias targets set in config file cause cmake error when package is found more than once #90

Closed interistaadastra closed 8 months ago

interistaadastra commented 8 months ago

In my application, it's perfectly reasonable for, say, two different calls to find_dependency(OpenDIS) to be made, which in turn causes OpenDISConfig.cmake to be included twice. This is a bit of a problem, since then

## Add target aliases
add_library(OpenDIS::DIS6 ALIAS OpenDIS::OpenDIS6)
add_library(OpenDIS::DIS7 ALIAS OpenDIS::OpenDIS7)

## These are deprecated target names. All new references to the targets
## should utilize the new namespace wrapped version
add_library(OpenDIS6 ALIAS OpenDIS::OpenDIS6)
add_library(OpenDIS7 ALIAS OpenDIS::OpenDIS7)

gets run twice. The proposed fix is very straightforward, merely checking whether each target exists before creating it:

## Add target aliases
if (NOT TARGET OpenDIS::DIS6)
  add_library(OpenDIS::DIS6 ALIAS OpenDIS::OpenDIS6)
endif()
if (NOT TARGET OpenDIS::DIS7)
  add_library(OpenDIS::DIS7 ALIAS OpenDIS::OpenDIS7)
endif()

## These are deprecated target names. All new references to the targets
## should utilize the new namespace wrapped version
if (NOT TARGET OpenDIS6)
  add_library(OpenDIS6 ALIAS OpenDIS::OpenDIS6)
endif()
if (NOT TARGET OpenDIS7)
  add_library(OpenDIS7 ALIAS OpenDIS::OpenDIS7)
endif()
leif81 commented 8 months ago

Thanks @a7marchesini

Your suggestion makes sense to me. Could you submit the change as a pull request, it'll make it easier for the maintainers to review and merge.

interistaadastra commented 8 months ago

@leif81 I can make an MR if you'd like. However I tried pushing a branch and github rejected me. Do I need additional permissions for that?

leif81 commented 8 months ago

You'll need to fork the project, try this

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork

interistaadastra commented 8 months ago

@leif81 Sorry for the delay. Fork created, branch made, pull request created (as noted by the UI above this message)