Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add an alias so that the library can be used outside the build #9125

Closed
shavesha opened this issue Jun 20, 2021 · 2 comments
Closed

Comments

@shavesha
Copy link

My library is setup in a very similar manner to this:
modern cmake sample. I use an alias target in the top level CMakeLists file:

add_library(JSONUtils::jsonutils ALIAS jsonutils)

Then in the test folder CMakeLists I use the target:

target_link_libraries(json_utils_test gtest_main JSONUtils::jsonutils)

My question is given the above linked project as an example how can we apply modern cmake practices using conan. I am specifically interested in how to setup the tests folder CMakeLists to access the library through an alias.

@shavesha shavesha changed the title How to add an alias so that the library can be used out the build How to add an alias so that the library can be used outside the build Jun 21, 2021
@memsharded memsharded self-assigned this Jun 21, 2021
@memsharded
Copy link
Member

Hi @shavesha

There is the set_property() (https://docs.conan.io/en/latest/reference/conanfile/attributes.html?highlight=set_property#cpp-info), you can define in package_info() to inject your own build_module that could define an alias.

There is also some ongoing work to automate this a bit more: #8533, but the underlying tool will be that set_property with the "cmake_build_module".

In any case, I am not so sure that is a good practice. The non-namespaced jsonutils made sense to provide some kind of backwards compatibility to older findxxx.cmake scripts, but modern cmake packages define package::target targets, with namespace. I'd probably avoid that altogether, specially if you are going to consume the packages yourself.

@memsharded
Copy link
Member

Closing this ticket as staled, please re-open or create a new one if necessary.

@memsharded memsharded closed this as not planned Won't fix, can't repro, duplicate, stale Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants