From 3e31cecffb401508cd893032be8b77889c721b83 Mon Sep 17 00:00:00 2001 From: Alexander Neundorf Date: Thu, 19 Mar 2009 00:55:45 +0000 Subject: -add modified versions of CheckCXXSourceRuns/Compiles.cmake, which can handle imported library targets (see http://lists.kde.org/?t=123686453500002&r=1&w=2 ) Alex svn path=/trunk/KDE/kdelibs/; revision=941177 --- ...leImportedTargetsInCMakeRequiredLibraries.cmake | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 modules/HandleImportedTargetsInCMakeRequiredLibraries.cmake (limited to 'modules/HandleImportedTargetsInCMakeRequiredLibraries.cmake') diff --git a/modules/HandleImportedTargetsInCMakeRequiredLibraries.cmake b/modules/HandleImportedTargetsInCMakeRequiredLibraries.cmake new file mode 100644 index 00000000..28564ab6 --- /dev/null +++ b/modules/HandleImportedTargetsInCMakeRequiredLibraries.cmake @@ -0,0 +1,81 @@ + +# This is a helper function used by CheckCXXSourceRuns.cmake and +# CheckCXXSourceCompiles.cmake. Actually it should be used by all macros which +# use TRY_COMPILE() or TRY_RUN(). +# It takes the CMAKE_REQUIRED_LIBRARY variable and searches it for imported +# (library) targets. Since the project created by TRY_COMPILE() (and TRY_RUN()) +# does not know about these imported targets, this macro here replaces these +# imported targets with the actual library files on disk and it also +# adds the libraries from the link interface of these imported targets. +# E.g the imported target KDE4__kdeui is replaced on my system with /opt/kdelibs/lib/libkdeui.so +# and the link interface libraries, which includes e.g. /opt/kdelibs/lib/libkdecore.so. +# This way imported targets work also when used with CHECK_CXX_SOURCE_COMPILES/RUNS(). + +# Copyright (c) 2009, Alexander Neundorf, +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +FUNCTION(HANDLE_IMPORTED_TARGETS_IN_CMAKE_REQUIRED_LIBRARIES _RESULT) +# handle imported library targets + SET(_CCSR_IMP_TARGETS_MAP) + SET(_CCSR_REQ_LIBS ${CMAKE_REQUIRED_LIBRARIES}) + SET(_CHECK_FOR_IMPORTED_TARGETS TRUE) + SET(_CCSR_LOOP_COUNTER 0) + WHILE(_CHECK_FOR_IMPORTED_TARGETS) + MATH(EXPR _CCSR_LOOP_COUNTER "${_CCSR_LOOP_COUNTER} + 1 ") + SET(_CCSR_NEW_REQ_LIBS ) + SET(_CHECK_FOR_IMPORTED_TARGETS FALSE) + FOREACH(_CURRENT_LIB ${_CCSR_REQ_LIBS}) + GET_TARGET_PROPERTY(_importedConfigs ${_CURRENT_LIB} IMPORTED_CONFIGURATIONS) + IF (_importedConfigs) + # Ok, so this is an imported target. + # First we get the imported configurations. + # Then we get the location of the actual library on disk of the first configuration. + # then we'll get its link interface libraries property, + # iterate through it and replace all imported targets we find there + # with there actual location. + + # guard against infinite loop: abort after 100 iterations ( 100 is arbitrary chosen) + IF ("${_CCSR_LOOP_COUNTER}" LESS 100) + SET(_CHECK_FOR_IMPORTED_TARGETS TRUE) +# ELSE ("${_CCSR_LOOP_COUNTER}" LESS 1) +# MESSAGE(STATUS "********* aborting loop, counter : ${_CCSR_LOOP_COUNTER}") + ENDIF ("${_CCSR_LOOP_COUNTER}" LESS 100) + + LIST(GET _importedConfigs 0 _firstImportedConfig) + GET_TARGET_PROPERTY(_firstImportedLocation ${_CURRENT_LIB} LOCATION_${_firstImportedConfig}) + GET_TARGET_PROPERTY(_linkInterfaceLibs ${_CURRENT_LIB} IMPORTED_LINK_INTERFACE_LIBRARIES_${_firstImportedConfig} ) + + LIST(APPEND _CCSR_NEW_REQ_LIBS ${_firstImportedLocation}) +# MESSAGE(STATUS "Appending lib ${_CURRENT_LIB} as ${_firstImportedLocation}") + FOREACH(_currentLinkInterfaceLib ${_linkInterfaceLibs}) +# MESSAGE(STATUS "Appending link interface lib ${_currentLinkInterfaceLib}") + LIST(APPEND _CCSR_NEW_REQ_LIBS ${_currentLinkInterfaceLib} ) + ENDFOREACH(_currentLinkInterfaceLib ${_linkInterfaceLibs}) + ELSE(_importedConfigs) + # "Normal" libraries are just used as they are. + LIST(APPEND _CCSR_NEW_REQ_LIBS ${_CURRENT_LIB} ) +# MESSAGE(STATUS "Appending lib directly: ${_CURRENT_LIB}") + ENDIF(_importedConfigs) + ENDFOREACH(_CURRENT_LIB ${_CCSR_REQ_LIBS}) + + SET(_CCSR_REQ_LIBS ${_CCSR_NEW_REQ_LIBS} ) + ENDWHILE(_CHECK_FOR_IMPORTED_TARGETS) + + # Finally we iterate once more over all libraries. This loop only removes + # all remaining imported target names (there shouldn't be any left anyway). + SET(_CCSR_NEW_REQ_LIBS ) + FOREACH(_CURRENT_LIB ${_CCSR_REQ_LIBS}) + GET_TARGET_PROPERTY(_importedConfigs ${_CURRENT_LIB} IMPORTED_CONFIGURATIONS) + IF (NOT _importedConfigs) + LIST(APPEND _CCSR_NEW_REQ_LIBS ${_CURRENT_LIB} ) +# MESSAGE(STATUS "final: appending ${_CURRENT_LIB}") + ELSE (NOT _importedConfigs) +# MESSAGE(STATUS "final: skipping ${_CURRENT_LIB}") + ENDIF (NOT _importedConfigs) + ENDFOREACH(_CURRENT_LIB ${_CCSR_REQ_LIBS}) + SET(${_RESULT} ${_CCSR_NEW_REQ_LIBS} PARENT_SCOPE) + +ENDFUNCTION(HANDLE_IMPORTED_TARGETS_IN_CMAKE_REQUIRED_LIBRARIES _CCSR_REQ_LIBS) + -- cgit v1.2.1 From d75c51be7b462e488f91c71fb83c49b8ccc5794f Mon Sep 17 00:00:00 2001 From: Alexander Neundorf Date: Mon, 11 Jan 2010 20:12:40 +0000 Subject: -fix handling of imported targets which don't have the link interface libraries property set, and also fix it on Windows Alex CCMAIL: CCMAIL: christoph@maxiom.de svn path=/trunk/KDE/kdelibs/; revision=1073213 --- .../HandleImportedTargetsInCMakeRequiredLibraries.cmake | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'modules/HandleImportedTargetsInCMakeRequiredLibraries.cmake') diff --git a/modules/HandleImportedTargetsInCMakeRequiredLibraries.cmake b/modules/HandleImportedTargetsInCMakeRequiredLibraries.cmake index 28564ab6..e28efd44 100644 --- a/modules/HandleImportedTargetsInCMakeRequiredLibraries.cmake +++ b/modules/HandleImportedTargetsInCMakeRequiredLibraries.cmake @@ -44,15 +44,23 @@ FUNCTION(HANDLE_IMPORTED_TARGETS_IN_CMAKE_REQUIRED_LIBRARIES _RESULT) ENDIF ("${_CCSR_LOOP_COUNTER}" LESS 100) LIST(GET _importedConfigs 0 _firstImportedConfig) - GET_TARGET_PROPERTY(_firstImportedLocation ${_CURRENT_LIB} LOCATION_${_firstImportedConfig}) + IF(NOT WIN32) + GET_TARGET_PROPERTY(_firstImportedLocation ${_CURRENT_LIB} IMPORTED_LOCATION_${_firstImportedConfig}) + ELSE(NOT WIN32) + GET_TARGET_PROPERTY(_firstImportedLocation ${_CURRENT_LIB} IMPORTED_IMPLIB_${_firstImportedConfig}) + ENDIF(NOT WIN32) GET_TARGET_PROPERTY(_linkInterfaceLibs ${_CURRENT_LIB} IMPORTED_LINK_INTERFACE_LIBRARIES_${_firstImportedConfig} ) LIST(APPEND _CCSR_NEW_REQ_LIBS ${_firstImportedLocation}) # MESSAGE(STATUS "Appending lib ${_CURRENT_LIB} as ${_firstImportedLocation}") - FOREACH(_currentLinkInterfaceLib ${_linkInterfaceLibs}) + IF(_linkInterfaceLibs) + FOREACH(_currentLinkInterfaceLib ${_linkInterfaceLibs}) # MESSAGE(STATUS "Appending link interface lib ${_currentLinkInterfaceLib}") - LIST(APPEND _CCSR_NEW_REQ_LIBS ${_currentLinkInterfaceLib} ) - ENDFOREACH(_currentLinkInterfaceLib ${_linkInterfaceLibs}) + IF(_currentLinkInterfaceLib) + LIST(APPEND _CCSR_NEW_REQ_LIBS ${_currentLinkInterfaceLib} ) + ENDIF(_currentLinkInterfaceLib) + ENDFOREACH(_currentLinkInterfaceLib ${_linkInterfaceLibs}) + ENDIF(_linkInterfaceLibs) ELSE(_importedConfigs) # "Normal" libraries are just used as they are. LIST(APPEND _CCSR_NEW_REQ_LIBS ${_CURRENT_LIB} ) -- cgit v1.2.1 From 377a0187d5a3b5b9a104d3f14d790bcbe2c6c254 Mon Sep 17 00:00:00 2001 From: Patrick Spendrin Date: Wed, 20 Jan 2010 16:33:21 +0000 Subject: forward port fix svn path=/trunk/KDE/kdelibs/; revision=1077671 --- modules/HandleImportedTargetsInCMakeRequiredLibraries.cmake | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'modules/HandleImportedTargetsInCMakeRequiredLibraries.cmake') diff --git a/modules/HandleImportedTargetsInCMakeRequiredLibraries.cmake b/modules/HandleImportedTargetsInCMakeRequiredLibraries.cmake index e28efd44..b775b424 100644 --- a/modules/HandleImportedTargetsInCMakeRequiredLibraries.cmake +++ b/modules/HandleImportedTargetsInCMakeRequiredLibraries.cmake @@ -44,11 +44,7 @@ FUNCTION(HANDLE_IMPORTED_TARGETS_IN_CMAKE_REQUIRED_LIBRARIES _RESULT) ENDIF ("${_CCSR_LOOP_COUNTER}" LESS 100) LIST(GET _importedConfigs 0 _firstImportedConfig) - IF(NOT WIN32) - GET_TARGET_PROPERTY(_firstImportedLocation ${_CURRENT_LIB} IMPORTED_LOCATION_${_firstImportedConfig}) - ELSE(NOT WIN32) - GET_TARGET_PROPERTY(_firstImportedLocation ${_CURRENT_LIB} IMPORTED_IMPLIB_${_firstImportedConfig}) - ENDIF(NOT WIN32) + GET_TARGET_PROPERTY(_firstImportedLocation ${_CURRENT_LIB} IMPORTED_LOCATION_${_firstImportedConfig}) GET_TARGET_PROPERTY(_linkInterfaceLibs ${_CURRENT_LIB} IMPORTED_LINK_INTERFACE_LIBRARIES_${_firstImportedConfig} ) LIST(APPEND _CCSR_NEW_REQ_LIBS ${_firstImportedLocation}) -- cgit v1.2.1