Why add header files into ADD_LIBRARY/ADD_EXECUTABLE command in CMake

后端 未结 1 956
深忆病人
深忆病人 2020-12-07 17:08

I had a project which uses CMake as build tool and made a simple template for me and my collegues to use. As I searched for best and easy to use practices online, I\'ve came

1条回答
  •  抹茶落季
    2020-12-07 17:23

    In our projects we use a "simple" way of yours - add_library with both headers and sources.

    If you add only sources, then you won't see headers in IDE-generated project.

    However, when installing, we have to do it like that, using two install commands:

    install(TARGETS library_name
            LIBRARY DESTINATION lib)
    
    install(FILES ${PUBLIC_HEADERS} 
            DESTINATION include/library_name)
    

    If you want to do it as a single command, you can use set_target_properties with PUBLIC_HEADER, as you suggested. Then, this kind of install is possible:

    install(TARGETS library_name
            LIBRARY DESTINATION lib
            PUBLIC_HEADER DESTINATION include/library_name)
    

    Choose the one you like the most and stick to it.

    0 讨论(0)
提交回复
热议问题