[CMake] Is it possible for a dependee to use the dependency LINKER_FLAGS ?

Adrian M Negreanu groleo at gmail.com
Sun Aug 3 02:43:23 EDT 2014


I've tested this with vs 2013 but a few things makes me think
that using target_link_libraries is not for this type of usage.

First, for setup 1:
===== CMakeLists.txt ================
cmake_minimum_required(VERSION 3.0)
add_library(A a.cpp)
target_link_libraries(A INTERFACE -custom-flags)

add_executable(E e.cpp)
target_link_libraries(E A)
###################################

Cmake warns me:

  CMake Warning (dev) in CMakeLists.txt:
  Policy CMP0022 is not set: INTERFACE_LINK_LIBRARIES defines the link
  interface.  Run "cmake --help-policy CMP0022" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  Target "A" has an INTERFACE_LINK_LIBRARIES property.  This should be
  preferred as the source of the link interface for this library but because
  CMP0022 is not set CMake is ignoring the property and using the link
  implementation as the link interface instead.

  INTERFACE_LINK_LIBRARIES:

    /FORCE:multiple


For setup 2:
===== CMakeLists.txt ================
cmake_minimum_required(VERSION 3.0)
add_library(A a.cpp)
set_target_properties(A PROPERTIES INTERFACE_LINK_LIBRARIES
"/FORCE:multiple")

add_executable(E e.cpp)
target_link_libraries(E A)
###################################


Cmake works fine, _but_ "/FORCE:multiple" is seen as a file, which leads to
error:

1>------ Build started: Project: ZERO_CHECK, Configuration: Debug Win32
------
2>------ Build started: Project: A, Configuration: Debug Win32 ------
2>  A.vcxproj -> C:\Users\amnegrea\Debug\A.lib
3>------ Build started: Project: E, Configuration: Debug Win32 ------
3>LINK : fatal error LNK1104: cannot open file '\FORCE:multiple.obj'
4>------ Skipped Build: Project: ALL_BUILD, Configuration: Debug Win32
------
4>Project not selected to build for this solution configuration
========== Build: 2 succeeded, 1 failed, 0 up-to-date, 1 skipped ==========





On Sat, Aug 2, 2014 at 7:38 PM, Walter Gray <chrysalisx at gmail.com> wrote:

> Glen is correct. You should take a look at the docs for interface modules
> here:
>
>
> http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html#interface-libraries
>
> I also put up some examples of how to do this on github a while back.
>
> https://github.com/wal-rus/cmake-modules
>
> Hope that helps! Also for future googling the concept is called Usage
> Requirements.
>  On Aug 2, 2014 8:11 AM, "Glenn Coombs" <glenn.coombs at gmail.com> wrote:
>
>> I think that you can use the target_link_libraries command to do this:
>>
>> add_library(A a.cpp)
>> target_link_libraries(A INTERFACE -custom-flags)
>>
>> --
>> Glenn
>>
>>
>>
>> On 30 July 2014 16:51, Adrian M Negreanu <groleo at gmail.com> wrote:
>>
>>> Hi,
>>>
>>> Is it possible to attach a property on a target, and that property
>>> to be used whenever the target is used ?
>>>
>>> ex:
>>>
>>> add_library(A a.cpp)
>>> somehow_attach_LINK_FLAGS(A "--custom-flags")
>>>
>>> # in a different directory
>>> add_executable(E e.cpp)
>>> target_link_libraries(E A)
>>> # ^---  this would do something similiar to
>>> set_target_properties(E PROPERTIES LINK_FLAGS "--custom-flags")
>>>
>>> For example, to use A:LINK_FLAGS
>>>
>>> Thanks
>>>
>>> --
>>>
>>> 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
>>>
>>
>>
>> --
>>
>> 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
>>
>


-- 
Regards!
http://groleo.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140803/abf98066/attachment-0001.html>


More information about the CMake mailing list