Closed ClausKlein closed 3 years ago
The problem seems to be that the fmt
library does not provide an installable target by default. This appears to be solved by setting the additional option FMT_INSTALL
when adding the library.
CPMAddPackage(
NAME fmt
GIT_TAG 7.1.3
GITHUB_REPOSITORY fmtlib/fmt
OPTIONS "FMT_INSTALL YES"
)
The problem seems to be that the
fmt
library does not provide an installable target by default. This appears to be solved by setting the additional optionFMT_INSTALL
when adding the library.It is a different way they use: as a master project, the install option is ON.
But as subproject the option is OFF, what it is with fetchcontents
module
I know a lot of projects doing it in this way.
spdlog, span, cereal, tomlplusplus, ...
It is a different way they use: as a master project, the install option is ON.
Yeah, in master project the option is set on by default, but it's still overridable. By adding the FMT_INSTALL YES
option as described above the fmt target is now installable. Imo it's a good idea to install any targets that your library uses, even if they're header-only at the moment. For one if one of your headers includes the fmt library then users will need the library themselves anyways. Also if the library does ever change to a compiled library in a future version, you wouldn't run into any issues upgrading.
That said, if you've added the library using CPM.cmake, you can probably simply include the header directory to skip installation issues: target_include_directories(MyTarget ${fmt_SOURCE_DIR}/include)
.
That said, if you've added the library using CPM.cmake, you can probably simply include the header directory to skip installation issues:
target_include_directories(MyTarget ${fmt_SOURCE_DIR}/include)
.
I think this does not help if you want install your own project. Cmake will not generate the project with the error msg above.
I just tested using
CPMAddPackage(
NAME fmt
GIT_TAG 7.1.3
GITHUB_REPOSITORY fmtlib/fmt
)
[...]
target_include_directories(MyTarget PRIVATE ${fmt_SOURCE_DIR}/include)
and could install the project without issues. As said before I still recommend using FMT_INSTALL
, but it does seem to work without it.
it is a CMAKE feature (with existing workaround)
target_link_libraries(Greeter PRIVATE $<BUILD_INTERFACE:fmt::fmt-header-only>)
helps. see too https://gitlab.kitware.com/cmake/cmake/-/issues/15415
after adding a new build dependency I get this error: