Rolling up Object libraries into a final product

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Rolling up Object libraries into a final product

Cameron Palmer
I’m using object libraries to put together a project composed of numerous modules. When putting together the static library (deliverable) at the end I have used libtool to assemble final product. I’ve been trying to adopt the use of OBJECT type libraries to avoid the libtool call and it mostly works with the exception that OpenSSL and Boost static libraries are not included in the result. This means I’ll still need libtool to add them to the archive.

1) Does this look like I’m using this correctly? 
2) Can the .a files be handled by CMake in a better way than using libtool? It is a collection of objects after all.

When this is built, other libraries will add this library in the 

target_link_libraries( another_interface INTERFACE common )

### Library - objects
add_library( common_objects OBJECT
        ${SOURCE_FILES} )
set_target_properties( common_objects PROPERTIES POSITION_INDEPENDENT_CODE on )
target_include_directories( common_objects
            ${BOOST_INCLUDE_DIR} )

### Library - dependencies
add_library( common_interface INTERFACE )
target_link_libraries( common_interface INTERFACE prefs ${BOOST_STATIC_LIBS} )
target_include_directories( common_interface 
         $<INSTALL_INTERFACE:include> )

### Library - interface
add_library( common INTERFACE )
target_sources( common INTERFACE $<TARGET_OBJECTS:common_objects> )
target_link_libraries( common INTERFACE common_interface )

### Library is assembled into static and shared as well

    add_library( common_static STATIC "" )
    set_target_properties( common_static
                OUTPUT_NAME common )
    target_link_libraries( common_static PRIVATE common )

    add_library( common_shared SHARED "" )
    set_target_properties( common_shared
                OUTPUT_NAME common )
    target_link_libraries( common_shared PRIVATE common )


Powered by

Please keep messages on-topic and check the CMake FAQ at:

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support:
CMake Consulting:
CMake Training Courses:

Visit other Kitware open-source projects at

Follow this link to subscribe/unsubscribe: