How to configure CMakeLists.txt to install public headers of a shared library?

后端 未结 2 839
天涯浪人
天涯浪人 2020-12-18 00:48

I want to use cmake to install my library edv but when I execute:

cmake --build . --target install

It installs but it only cre

2条回答
  •  醉酒成梦
    2020-12-18 01:23

    CMake cannot deduce the set of header files to be installed from the target. This makes sense, as the target may contain both private and public header files, but CMake does not differentiate between those. As a consequence, you have to list the header files explicitly in an INSTALL(FILES ...) command:

    install(FILES ${MY_HEADER_FILES} DESTINATION include)
    

    The PUBLIC_HEADER field that you stumbled upon is related to the OSX framework mechanism, which is its very own can of worms. I suggest you stay clear of it, unless you actually want to deploy your library as a .framework on OSX.

    Take special note of the INCLUDES DESTINATION option to the INSTALL(TARGET ...) command. While this does not actually copy any files itself, it allows the include directory to be added to the imported target provided by the config package script automatically. If you intend to provide a package config script to your users (which you probably should, at least if you expect your users to also use CMake), you probably want to set this option.

    Since the install mechanism is quite complicated overall, I have a small github project of mine where you can observe all the elements in action.

提交回复
热议问题