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

cmake: think in CMake targets #23

Merged
merged 4 commits into from
Nov 2, 2022
Merged

Conversation

madebr
Copy link
Contributor

@madebr madebr commented Oct 19, 2022

This is the yder equivalent of babelouest/orcania#30
When downloading dependencies, this has a HARD requirement on babelouest/orcania#30.

The reason for the hard requirement is as follows:
The exported yder targets link to orcania targets. At export time, CMake checks whether all targets are being exported.
Because upstream orcania currently does not export any target, this fails.

These errors look as follows:

CMake Error: install(EXPORT "YderExports" ...) includes target "yder_static" which requires target "orcania" that is not in any export set.
CMake Error: install(EXPORT "YderExports" ...) includes target "yder" which requires target "orcania" that is not in any export set.

I fixed the hard requirement by using imported targets instead of ALIAS'es.

After this pr, an install prefix looks as follows:

prefix
├── include
│   ├── yder-cfg.h
│   └── yder.h
├── lib64
│   ├── cmake
│   │   └── Yder
│   │       ├── FindSystemd.cmake
│   │       ├── YderConfig.cmake
│   │       ├── YderConfigVersion.cmake
│   │       ├── YderTargets.cmake
│   │       └── YderTargets-debug.cmake
│   ├── libyder.a
│   ├── libyder.so -> libyder.so.1.4
│   ├── libyder.so.1.4 -> libyder.so.1.4.18
│   ├── libyder.so.1.4.18
│   └── pkgconfig
│       └── libyder.pc
└── share
    └── doc
        └── yder
            ├── examples
            │   ├── log_callback.c
            │   ├── log_combined.c
            │   ├── log_console.c
            │   ├── log_file.c
            │   ├── log_journald.c
            │   ├── log_newline.c
            │   ├── log_syslog.c
            │   └── Makefile
            └── README.md

Also note that FindSystemd.cmake is installed as well.
This is because a static yder needs a systemd library, even when used by a consumer.

After this pr, a project can use yder by doing:

cmake_minimum_required(VERSION 3.0)
project(my_logger C)
find_package(Yder REQUIRED)

add_executable(my_static_logger my_logger.c)
target_link_libraries(my_static_logger PRIVATE Yder::Yder-static)

add_executable(my_logger my_logger.c)
target_link_libraries(my_logger PRIVATE Yder::Yder)

Note how the cmake script does not need to worry about linking to systemd/orcania.

Used by conan-io/conan-center-index#13614

@babelouest
Copy link
Owner

Hello @madebr ,

Is it possible to resolve the conflict? It seems that I'm missing some code if I do it manually...

I'd have the same request for babelouest/ulfius#242, if you don't mind

@madebr
Copy link
Contributor Author

madebr commented Nov 1, 2022

FYI, I only had to add -Wconversion to the new compile options.

@babelouest babelouest merged commit 99e36b8 into babelouest:master Nov 2, 2022
@madebr madebr deleted the cmake-targets branch November 2, 2022 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants