CMAKE - How to properly copy static library's header file into /usr/include?

前端 未结 4 1505
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-12 20:26

I\'m getting into CMAKE usage with C and actually I\'m creating two very small static libraries.

My goal is:

  1. The libraries are compiled and linked into
4条回答
  •  难免孤独
    2020-12-12 21:10

    In addition to the accepted answer, if you are creating a lot of libraries and the set_property syntax throws you off. You could wrap it in a very simple macro, such as:

    # File: target_public_headers.cmake
    macro(target_public_headers TARGET)
      set_target_properties(${TARGET} PROPERTIES PUBLIC_HEADER "${ARGN}")
    endmacro()
    

    Then you can use it like:

    project(myproject)
    
    include(target_public_headers)
    
    add_library(mylib some.c another.c)
    target_public_headers(mylib some.h another.h) # <<<<<
    
    # If you're exporting this library then you need to tell
    # CMake how to include the "installed" version of the headers.
    target_include_directories(mylib
      PUBLIC $
      PUBLIC $
    )
    
    INSTALL(TARGETS mylib 
            LIBRARY DESTINATION some/libpath
            PUBLIC_HEADER DESTINATION some/includepath
    )
    

提交回复
热议问题