facebookexperimental / facebookexperimental/libunifex

`std::coroutines` in INTERFACE_LINK_LIBRARIES breaks cmake packages that consume libunifex

Open
#399 4 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C++
Stars
1.7k
Forks
210
PR merge metrics
No merged PRs in 30d

Description

The CMake config file installed with unifex (_e.g._, `/usr/local/cmake/lib/unifexConfig.cmake`) contains the following:
```
set_target_properties(unifex::unifex PROPERTIES
INTERFACE_COMPILE_FEATURES "cxx_std_17"
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
INTERFACE_LINK_LIBRARIES "std::coroutines"
)
```
Having std::coroutines in `INTERFACE_LINK_LIBRARIES` means a package that declares a dependency on unifex also depends on std::coroutines. (This happens because std::coroutines is declared with the `INTERFACE` keyword, in `libunifex/cmake/FindCoroutines.cmake`.) But a definition for std::coroutines itself isn't published, so the consuming project will fail to configure, with
```
CMake Error at CMakeLists.txt:33 (add_executable):
Target "myproject_mytarget" links to target "std::coroutines" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
```
I asked [a cmake expert](https://github.com/friendlyanon/), who said:

> Enabling coroutines for older compilers is a project level concern that's done by setting flags in a toolchain/the command-line. Best course of action would be reporting the broken install interface and suggesting removing that find module altogether.

_**I hereby so report and suggest.**_

They also suggested a workaround for the consuming package to `include()` in its CMakeLists.txt,

> In the meantime, you can use a find module to proxy the package discovery and remove the faulty bits:

```
# Findunifex.cmake

find_package(unifex NO_MODULE)

if(unifex_FOUND)
get_target_property(link_libs unifex::unifex INTERFACE_LINK_LIBRARIES)
list(REMOVE_ITEM link_libs std::coroutines)
set_property(TARGET unifex::unifex PROPERTY INTERFACE_LINK_LIBRARIES "${link_libs}")
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(unifex CONFIG_MODE)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.