[CMake] Setting IMPORTED_LOCATION_* for existing packages

Michael Hertling mhertling at online.de
Thu Sep 22 13:19:00 EDT 2011


On 09/21/2011 09:07 AM, Hauke Heibel wrote:
> Hi,
> 
> I started to work with imported targets and thus with setting the
> property IMPORTED_LOCATION and the like. I stumbled over a case
> (GTest) where the standard find_package call returns me a list of libs
> for 'debug' and 'optimized' modes and I am setting them like this
> 
> find_package(GTest REQUIRED)
> add_library(GTest UNKNOWN IMPORTED)
> foreach(arg ${GTEST_LIBRARIES})
>   if("${arg}" MATCHES "^(debug|optimized)$")
>     set(_doing "${arg}")
>   elseif("${_doing}" MATCHES "^debug$")
>     message("setting debug lib to: ${arg}")
>     set_target_properties(GTest PROPERTIES IMPORTED_LOCATION_DEBUG "${arg}")
>   else()
>     message("setting optimized lib to: ${arg}")
>     set_target_properties(GTest PROPERTIES IMPORTED_LOCATION "${arg}")
>   endif()
> endforeach()

AFAICS, you've a single imported target GTest, and you are continuously
setting *this* target's location - sometimes for a debug configuration,
sometimes without configuration - to the location of its *prerequisite*
libraries reported by the GTest package's find module or config file.
IMO, this doesn't make any sense. Possibly, you want to set the GTest
target's IMPORTED_LINK_INTERFACE_LIBRARIES[_<CONFIG>] properties in
place of the IMPORTED_LOCATION[_<CONFIG>] ones. Moreover, note that
TARGET_LINK_LIBRARIES()'s debug/optimized/general switches apply to
the immediately following library only, so you probably need to re-
set the "_doing" variable in the ELSEIF() and ELSE() branches in
order to obtain the expected result.

> I am just wondering whether there is a more simple method to do this.
> It looks a bit cumbersome.

What do you actually intent to achieve? Introduce a GTest imported
target and set up its prerequisites reported in GTEST_LIBRARIES as
it would be done for imported targets from the first? Doesn't the
GTEST_LIBRARIES variable per se work for you?

> Regards,
> Hauke

Regards,

Michael


More information about the CMake mailing list