I just tried reproducing your 2 examples.  Setup 1 works fine for me with
no messages about policy CMP0022.  The only way I could get that message
produced was by omitting the cmake_minimum_required(VERSION 3.0) line.  Are
you sure you're running the exact same CMakeLists.txt file that you have
posted here ?

For setup 2 I get the same results as you.  CMake seems to insist on
converting the forward slash into a backwards slash, probably because it
thinks it is a file path, which totally screws things up.  I suspect this
is a bug in cmake: adding linker flags like this works for linux because it
doesn't mess with strings like "-Wl,-Bstatic".  The only workaround I can
suggest is to set CMAKE_EXE_LINKER_FLAGS:

if (MSVC)
        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}
/FORCE:Multiple")
endif()

which correctly adds the option you want but it will do it for all
libraries in the current context.  In order to only have it applied to the
one library you would need to have a separate CMakeLists.txt for that
library and add the lines above to adjust the CMAKE_EXE_LINKER_FLAGS only
in that CMakeLists.txt.  Then you would have to do and
add_subdirectory(special_lib) somewhere in your higher level CMakeLists.txt.

--
Glenn



On 3 August 2014 07:43, Adrian M Negreanu <gro...@gmail.com> wrote:

> 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 <chrysal...@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.coo...@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 <gro...@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
>
-- 

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

Reply via email to