Error: `INSTALL(EXPORT) given unknown export [...]` on windows, while working on unix

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.

1 Like

Very wild guess, but could LIB_TARGETS perhaps be empty on Windows, leading to some sort of confusion?

Good guess, and embarrassing for me! :sweat_smile:

I had double-checked this, but managed to overlook something. Thanks for the quick response!