Skip to content

[CMake] Including as add_subdirectory does not declare the alias target ryml::ryml #173

@cschreib

Description

@cschreib

In CMake, the find_package(ryml) command defines the target ryml::ryml, which is (afaik) the expected format for an imported target. It is good practice to make the library accessible with this name regardless of the method that was used to create the target, so that downstream CMake code does not need to worry about how the target was created/imported; the name should always be ryml::ryml.

Currently, this is not true if rapidyaml is included as a submodule and then add_subdirectory(). This only creates the target ryml. This causes issues:

if (BUILD_RYML)
    add_subdirectory(extern/ryml)
    # defines target 'ryml'
else()
    find_package(ryml)
    # defines target 'ryml::ryml`
endif()

To fix this, I have to add to my own CMake scripts:

add_subdirectory(extern/ryml)
add_library(ryml::ryml ALIAS ryml) # this line needs adding

I believe this should be done by rapidyaml's root CMake file.

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