I help package things for conda-forge, where lots of python code wraps lots of C/C++ code.
One package I deal with has three components (at least from our POV): a library, some associated binaries, and python bindings.
The upstream CMake file installs everything without creating export information that would be useful to have for consumers that just want to use find_package(foo)
for the library portion. Their code looks like:
install(TARGETS ${INSTALL_TARGETS}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
I wanted to change this to the following for the purposes of our packaging:
install(TARGETS ${BIN_TARGETS}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS ${LIB_TARGETS}
EXPORT fooTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(EXPORT fooTargets
FILE fooTargets.cmake
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/foo")
And this works as intended on linux/osx, but causes an error on windows
-- Configuring done
CMake Error: INSTALL(EXPORT) given unknown export "fooTargets"
I’m not sure if I’m doing something wrong, but the fact that it works as intended on unix but fails on windows is at the very least inconsistent, if not a bug.