question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[question] PUBLIC / PRIVATE Link Libraries Separation

See original GitHub issue

Let’s take following simplified example:

find_package(Boost REQUIRED)
find_package(OpenSSL REQUIRED)

add_library(Foo)

target_link_libraries(${PROJECT_NAME}
	PUBLIC
		Boost::Boost
	PRIVATE
		OpenSSL::OpenSSL
)

#...
include(CMakePackageConfigHelpers)
configure_package_config_file(...)
install(...)

Now, let’s assume we want to consume Foo:

find_package(Foo REQUIRED)

add_executable(App)

target_link_libraries(${PROJECT_NAME}
    PRIVATE
        Foo::Foo
)

Now, having OpenSSL defined as a private dependency of Foo means that App can link against it, but cannot include any API of it. Instead, in case of Boost, App can use it within the application.

CMake, when generating the Package Configuration Files, uses $<LINK_ONLY:...> to specify private link dependencies without other usage requirements.

My question is, how can I describe the PUBLIC / PRIVATE separation within package_info()?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
memshardedcommented, Nov 3, 2021

Hi @lucabonifacio

at the moment (Conan 1.X), all requires are by default public, and linkage requirements are propagated to the consumers. This is because Conan graph model has requires and build_requires```, but there is nothing inside requires`` that allows to define the visibility of the transitive requirements.

Conan 2.0 introduces a new model that does exactly this. Check this Tribe 2.0 proposal: https://github.com/conan-io/tribe/pull/26

1reaction
memshardedcommented, Nov 9, 2021

Hi @dornbirndevelops

Please don’t use undocumented things in your recipe code, those will easily break, and if you do it, it is at your own risk. Specifically this one has already been removed in the new model, it will not exist via the self.dependencies model

Read more comments on GitHub >

github_iconTop Results From Across the Web

cmake target_link_libraries PRIVATE or PUBLIC on CuteLogger
PUBLIC linkage affects both on ${library_target} target and targets linked with it. Non-keyword variant of target_link_libraries has no exact ...
Read more >
Modern CMake is like inheritance - Kuba Sejdak
This means, that if other libraries call only target_link_libraries() to both get include paths and link with library, then no private header ...
Read more >
3. Shared Libraries - The Linux Documentation Project
The key to managing shared libraries is the separation of these names. Programs, when they internally list the shared libraries they need, should...
Read more >
CMake: Public VS Private VS Interface - Lei Mao's Log Book
CMake Include and Link Keywords from the Perspective of Inheritance. ... apple_size by PUBLIC or PRIVATE linking with the apple library.
Read more >
Enhanced source file handling with target_sources() - Crascit -
If you want to take full advantage of the PUBLIC, PRIVATE and ... and any target that links to it also needs to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found