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
        ${HEADER_FILES}
        ${SOURCE_FILES} )
set_target_properties( common_objects PROPERTIES POSITION_INDEPENDENT_CODE on )
target_include_directories( common_objects
        PUBLIC
            include
            iOS/include
            ${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
INTERFACE
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
           $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/iOS/include>
         $<BUILD_INTERFACE:${BOOST_INCLUDE_DIR}>
         $<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

if( BUILD_STATIC_LIB )
    add_library( common_static STATIC "" )
    set_target_properties( common_static
            PROPERTIES
                OUTPUT_NAME common )
    target_link_libraries( common_static PRIVATE common )
endif()

if( BUILD_SHARED_LIB )
    add_library( common_shared SHARED "" )
    set_target_properties( common_shared
            PROPERTIES
                OUTPUT_NAME common )
    target_link_libraries( common_shared PRIVATE common )
endif()
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

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

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

Reply via email to