1

I have a C++ library provided by a third party as pre-built binaries. The package contains .dll files, corresponding .lib files and API headers. Now I need to provide a CMakeList.txt file to install the library on a given path, and a find-foo.cmake helper, for other CMake projects to find and link against this library. However, it seems not possible to export imported libraries in CMake:

    cmake_minimum_required(VERSION 3.11)
    project(libfoo)

    add_library(libfoo SHARED IMPORTED)
    set_property(TARGET libfoo PROPERTY IMPORTED_LOCATION libfoo.dll)
    set_property(TARGET libfoo PROPERTY IMPORTED_IMPLIB   libfoo.lib)

    # This doesn't work:
    install(
        EXPORT libfoo
        NAMESPACE foo::
        FILE find-foo.cmake
        DESTINATION share/find-foo.cmake
    )

So basically what I am trying to do is to install a target as if it was built by CMake. Any workaround?

sorush-r
  • 10,490
  • 17
  • 89
  • 173
  • 1
    Does this answer your question? [Can I install shared imported library?](https://stackoverflow.com/questions/41175354/can-i-install-shared-imported-library) – Kevin Mar 13 '20 at 17:40
  • Well, install FILES does not solve the issue. It copies the files, but does not export... – sorush-r Mar 13 '20 at 18:23
  • @sorush-r What do you mean by "does not export"? Once the files are installed, the library should be found with find_package – eerorika Mar 13 '20 at 18:28
  • @eerorika Really? You mean there is no need for something like `FindFoo.cmake`? But then how CMake knows about linker flags? I means lets say there are foo, bar and zoo (three shared libs) then there user code should contain three `find_package` statements right? – sorush-r Mar 13 '20 at 18:39
  • @sorush-r Is that not what find-foo.cmake file does? – eerorika Mar 13 '20 at 18:53
  • @eerorika To my best knowledge, yes that information is inside find-foo.cmake and `install(EXPORT target ...` generates that file. Am I mistaken? – sorush-r Mar 13 '20 at 18:56
  • 1
    @sorush-r: You confuse `FindFoo.cmake` and `FooConfig.cmake` scripts. As a project's developer, you need to bother about `FooConfig.cmake` script, because it is your responsibility to provide that script with the **installation** of your project. But `FindFoo.cmake` script is created by someone else who want to use your project in case it does **not shipped** with `FooConfig.cmake` script. See [documentation](https://cmake.org/cmake/help/v3.16/manual/cmake-packages.7.html#using-packages) for more detailed description of these kind of scripts. – Tsyvarev Mar 13 '20 at 21:20

0 Answers0