Warning, /frameworks/kdelibs4support/cmake/modules/HandleImportedTargetsInCMakeRequiredLibraries.cmake is written in an unsupported language. File is not indexed.

0001 
0002 # This is a helper function used by CheckCXXSourceRuns.cmake and 
0003 # CheckCXXSourceCompiles.cmake. Actually it should be used by all macros which 
0004 # use TRY_COMPILE() or TRY_RUN().
0005 # It takes the CMAKE_REQUIRED_LIBRARY variable and searches it for imported
0006 # (library) targets. Since the project created by TRY_COMPILE() (and TRY_RUN())
0007 # does not know about these imported targets, this macro here replaces these
0008 # imported targets with the actual library files on disk and it also
0009 # adds the libraries from the link interface of these imported targets.
0010 # E.g the imported target KDE4__kdeui is replaced on my system with /opt/kdelibs/lib/libkdeui.so
0011 # and the link interface libraries, which includes e.g. /opt/kdelibs/lib/libkdecore.so.
0012 # This way imported targets work also when used with CHECK_CXX_SOURCE_COMPILES/RUNS().
0013 
0014 # Copyright (c) 2009, Alexander Neundorf, <neundorf@kde.org>
0015 #
0016 # Redistribution and use is allowed according to the terms of the BSD license.
0017 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
0018 
0019 FUNCTION(HANDLE_IMPORTED_TARGETS_IN_CMAKE_REQUIRED_LIBRARIES _RESULT)
0020 # handle imported library targets
0021    SET(_CCSR_IMP_TARGETS_MAP)
0022    SET(_CCSR_REQ_LIBS ${CMAKE_REQUIRED_LIBRARIES})
0023    SET(_CHECK_FOR_IMPORTED_TARGETS TRUE)
0024    SET(_CCSR_LOOP_COUNTER 0)
0025    WHILE(_CHECK_FOR_IMPORTED_TARGETS)
0026       MATH(EXPR _CCSR_LOOP_COUNTER "${_CCSR_LOOP_COUNTER} + 1 ")
0027       SET(_CCSR_NEW_REQ_LIBS )
0028       SET(_CHECK_FOR_IMPORTED_TARGETS FALSE)
0029       FOREACH(_CURRENT_LIB ${_CCSR_REQ_LIBS})
0030          GET_TARGET_PROPERTY(_importedConfigs ${_CURRENT_LIB} IMPORTED_CONFIGURATIONS)
0031          IF (_importedConfigs)
0032             # Ok, so this is an imported target.
0033             # First we get the imported configurations.
0034             # Then we get the location of the actual library on disk of the first configuration.
0035             # then we'll get its link interface libraries property,
0036             # iterate through it and replace all imported targets we find there
0037             # with there actual location.
0038 
0039             # guard against infinite loop: abort after 100 iterations ( 100 is arbitrary chosen)
0040             IF ("${_CCSR_LOOP_COUNTER}" LESS 100)
0041                SET(_CHECK_FOR_IMPORTED_TARGETS TRUE)
0042 #                ELSE ("${_CCSR_LOOP_COUNTER}" LESS 1)
0043 #                   MESSAGE(STATUS "********* aborting loop, counter : ${_CCSR_LOOP_COUNTER}")
0044             ENDIF ("${_CCSR_LOOP_COUNTER}" LESS 100)
0045 
0046             LIST(GET _importedConfigs 0 _firstImportedConfig)
0047             GET_TARGET_PROPERTY(_firstImportedLocation ${_CURRENT_LIB} IMPORTED_LOCATION_${_firstImportedConfig})
0048             GET_TARGET_PROPERTY(_linkInterfaceLibs ${_CURRENT_LIB} IMPORTED_LINK_INTERFACE_LIBRARIES_${_firstImportedConfig} )
0049 
0050             LIST(APPEND _CCSR_NEW_REQ_LIBS  ${_firstImportedLocation})
0051 #                MESSAGE(STATUS "Appending lib ${_CURRENT_LIB} as ${_firstImportedLocation}")
0052             IF(_linkInterfaceLibs)
0053                FOREACH(_currentLinkInterfaceLib ${_linkInterfaceLibs})
0054 #                   MESSAGE(STATUS "Appending link interface lib ${_currentLinkInterfaceLib}")
0055                   IF(_currentLinkInterfaceLib)
0056                      LIST(APPEND _CCSR_NEW_REQ_LIBS ${_currentLinkInterfaceLib} )
0057                   ENDIF(_currentLinkInterfaceLib) 
0058                ENDFOREACH(_currentLinkInterfaceLib ${_linkInterfaceLibs})
0059             ENDIF(_linkInterfaceLibs)
0060          ELSE(_importedConfigs)
0061             # "Normal" libraries are just used as they are.
0062             LIST(APPEND _CCSR_NEW_REQ_LIBS ${_CURRENT_LIB} )
0063 #                MESSAGE(STATUS "Appending lib directly: ${_CURRENT_LIB}")
0064          ENDIF(_importedConfigs)
0065       ENDFOREACH(_CURRENT_LIB ${_CCSR_REQ_LIBS})
0066 
0067       SET(_CCSR_REQ_LIBS ${_CCSR_NEW_REQ_LIBS} )
0068    ENDWHILE(_CHECK_FOR_IMPORTED_TARGETS)
0069 
0070    # Finally we iterate once more over all libraries. This loop only removes
0071    # all remaining imported target names (there shouldn't be any left anyway).
0072    SET(_CCSR_NEW_REQ_LIBS )
0073    FOREACH(_CURRENT_LIB ${_CCSR_REQ_LIBS})
0074       GET_TARGET_PROPERTY(_importedConfigs ${_CURRENT_LIB} IMPORTED_CONFIGURATIONS)
0075       IF (NOT _importedConfigs)
0076          LIST(APPEND _CCSR_NEW_REQ_LIBS ${_CURRENT_LIB} )
0077 #             MESSAGE(STATUS "final: appending ${_CURRENT_LIB}")
0078       ELSE (NOT _importedConfigs)
0079 #             MESSAGE(STATUS "final: skipping ${_CURRENT_LIB}")
0080       ENDIF (NOT _importedConfigs)
0081    ENDFOREACH(_CURRENT_LIB ${_CCSR_REQ_LIBS})
0082    SET(${_RESULT} ${_CCSR_NEW_REQ_LIBS} PARENT_SCOPE)
0083 
0084 ENDFUNCTION(HANDLE_IMPORTED_TARGETS_IN_CMAKE_REQUIRED_LIBRARIES _CCSR_REQ_LIBS)
0085