[CMake] MinGW Link with -l instead of path?

J Decker d3ck0r at gmail.com
Thu Apr 4 13:16:29 EDT 2013


On Wed, Apr 3, 2013 at 9:12 AM, J Decker <d3ck0r at gmail.com> wrote:

> alternate target_link_libraries.  Usage is the same.  Test if each library
> to link is a target, get that targets path, and break it into parts and add
> it to LINK_FLAGS else add with target_link_libraries...
>
> macro(my_target_link_libraries target )
>     if(CMAKE_COMPILER_IS_GNUCC)
>        foreach( target_lib ${ARGN} )
>           if( TARGET ${target_lib} )
>              get_property( lib_path TARGET ${target_lib} PROPERTY LOCATION)
>              if( ${lib_path} MATCHES "(.*)/([^/]*)$" )
>                 get_target_property(existing_link_flags ${target}
> LINK_FLAGS)
>

#  Revision to handle OUTPUT_NAME overridden targets.
             get_property( existing_outname TARGET ${target_lib} PROPERTY
OUTPUT_NAME )
             if( NOT existing_outname )
             set( existing_outname ${target_lib} )
             endif( NOT existing_outname )



>                 if(existing_link_flags)
> +                    set(new_link_flags "${existing_link_flags} -L
> ${CMAKE_MATCH_1} -l ${existing_outname }")
>                 else()
> +                    set(new_link_flags "-L ${CMAKE_MATCH_1} -l
> ${existing_outname}")
>                 endif()
>                 set_target_properties( ${target} PROPERTIES LINK_FLAGS
> ${new_link_flags})
>              endif( ${lib_path} MATCHES "(.*)/([^/]*)$" )
>           else()
>              target_link_libraries( ${target} ${target_lib} )
>           endif( TARGET ${target_lib} )
>        endforeach( target_lib ${ARGN} )
>     else()
>     target_link_libraries( ${target} ${ARGN} )
>     endif()
> endmacro()
>
>


macro(my_target_link_libraries target )
    if(CMAKE_COMPILER_IS_GNUCC)
       foreach( target_lib ${ARGN} )
          if( TARGET ${target_lib} )
             get_property( lib_path TARGET ${target_lib} PROPERTY LOCATION)
             get_property( existing_outname TARGET ${target_lib} PROPERTY
OUTPUT_NAME )
             if( NOT existing_outname )
             set( existing_outname ${target_lib} )
             endif( NOT existing_outname )
             if( ${lib_path} MATCHES "(.*)/([^/]*)$" )
                get_target_property(existing_link_flags ${target}
LINK_FLAGS)
                if(existing_link_flags)

                    set(new_link_flags "${existing_link_flags} -L
${CMAKE_MATCH_1} -l ${existing_outname}")
                else()
                    set(new_link_flags "-L ${CMAKE_MATCH_1} -l
${existing_outname}")
                endif()
                set_target_properties( ${target} PROPERTIES LINK_FLAGS
${new_link_flags})
             endif( ${lib_path} MATCHES "(.*)/([^/]*)$" )
          else()
             target_link_libraries( ${target} ${target_lib} )
          endif( TARGET ${target_lib} )
       endforeach( target_lib ${ARGN} )
    else()
    target_link_libraries( ${target} ${ARGN} )
    endif()
endmacro()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130404/21f1d997/attachment.htm>


More information about the CMake mailing list