[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cmake
Subject:    Re: [CMake] OBJECT libraries and INTERFACE_SOURCES
From:       Stephen Kelly <steveire () gmail ! com>
Date:       2016-12-08 21:56:12
Message-ID: o2cktn$goq$1 () blaine ! gmane ! org
[Download RAW message or body]

Giovanni Funchal wrote:

> Hi,
> 
> The help page [1] mentions that:
> 
> > Although object libraries may not be named directly in calls to the
> > target_link_libraries() command, they can be "linked" indirectly by
> > using an Interface Library whose INTERFACE_SOURCES target property
> > is set to name $<TARGET_OBJECTS:objlib>.
> 
> However, I was unable to get this to work. Doing this:
> 
> add_library(lib-obj OBJECT test.cpp)
> add_library(lib INTERFACE)
> add_dependencies(lib lib-obj)
> set_target_properties(lib PROPERTIES INTERFACE_SOURCES
> $<TARGET_OBJECTS:lib-obj>)
> 
> And then trying to specify lib in link_libraries of an executable yields
> an error message "Cannot find source file: ... Tried extensions:... ".
> 
> Am I doing something wrong?

This works for me:

    cmake_minimum_required(VERSION 3.3)

    project(testit CXX)

    add_library(lib-obj OBJECT foo.cpp)
    add_library(lib-iface INTERFACE)
    set_target_properties(lib-iface PROPERTIES
      INTERFACE_SOURCES $<TARGET_OBJECTS:lib-obj>
    )
    add_executable(main foo-user.cpp)
    target_link_libraries(main lib-iface)


Thanks,

Steve.


-- 

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:
http://public.kitware.com/mailman/listinfo/cmake


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic