How to set an alias for a target imported by find_package?

When I create my own library target with add_library, it has an ALIAS option. However, I cannot find similar for libraries imported via find_package.
In my case, I import OpenMP with

find_package(OpenMP COMPONENTS CXX REQUIRED)

and then link it with my library as

target_link_libraries(myLib PRIVATE OpenMP::OpenMP_CXX)

When I generate the dependency graph among the CMake targets, it appears as OpenMP::OpenMP_CXX. This is verbose, I would like OpenMP to appear as OpenMP in the graph. Is it possible?

You can create an alias for an imported target as well (with a recent CMake):

```cmake

find_package(OpenMP COMPONENTS CXX REQUIRED)

if(TARGET OpenMP::OpenMP_CXX AND NOT TARGET OpenMP)

add_library(OpenMP ALIAS OpenMP::OpenMP_CXX)

endif()

target_link_libraries(myLib PRIVATE OpenMP)

```

That gives you the shorter spelling in your own CMake code. It does not rename the imported target, though, so the Graphviz generator may still label the node `OpenMP::OpenMP_CXX`; if the shorter label is essential, post-process the `.dot` output (or filter it with `CMakeGraphVizOptions.cmake`). Also keep the alias in a scope where the imported target is visible.

Thank you. For me, the abbreviation is needed only for the .dot output.

post-process the .dot output

I will do that if necessary, but I hope it is simpler with CMakeGraphVizOptions.cmake.

filter it with CMakeGraphVizOptions.cmake

I already use the CMakeGraphVizOptions.cmake file, but I didn’t find in the documentation how to modify the node name of a target.

Also keep the alias in a scope where the imported target is visible.

What do you mean by that?