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

J Decker d3ck0r at gmail.com
Wed Apr 3 12:12:08 EDT 2013


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)
                if(existing_link_flags)
                    set(new_link_flags "${existing_link_flags} -L
${CMAKE_MATCH_1} -l ${target_lib}")
                else()
                    set(new_link_flags "-L ${CMAKE_MATCH_1} -l
${target_lib}")
                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/20130403/35870054/attachment.htm>


More information about the CMake mailing list