[cmake-developers] Supporting imported targets in CHECK_CXX_SOURCE_COMPILES() and friends

Brad King brad.king at kitware.com
Wed Aug 3 15:59:52 EDT 2011


On 7/18/2011 4:13 PM, Alexander Neundorf wrote:
> Hi,
>
> in KDE we have a copy of CHECK_CXX_SOURCE_COMPILES() which supports imported
> targets in CMAKE_REQUIRED_LIBRARIES:
> http://websvn.kde.org/branches/KDE/4.5/kdelibs/cmake/modules/CheckCXXSourceCompiles.cmake?revision=1143427&view=markup
> http://websvn.kde.org/branches/KDE/4.5/kdelibs/cmake/modules/HandleImportedTargetsInCMakeRequiredLibraries.cmake?view=markup
>
> This means, you can put any ${FOO_LIBRARY} you got from some find-module into
> CMAKE_REQUIRED_LIBRARIES and it will work, also if ${FOO_LIBRARY} is actually
> an imported target and not a path to a library.
>
> It works for us in KDE and I am not aware of problems with it. Also, the
> number of imported targets is increasing, by more and more projects installing
> Config.cmake files, so this is getting more important.
>
> I can remember that quite some time ago I suggested to merge this into cmake,
> but there were objections. I can't remember what the objections were, well,
> actually I don't see a reason not to have that in cmake.
>
> So, do these objections still exist or can I merge that into cmake ?

I think this was a private discussion we had over 2 years ago.  Here is
all I could find from that thread.  It looks like we were talking about
creating a general solution for try_compile.  I still don't have time to
look at it in detail, and the special case solution the above scripts
provide will not conflict with a future general solution.

Please try to generalize the scripts to work with the other CMake check
modules and push a topic to the stage for me to review.

Thanks,
-Brad


==============================================================================
From: Alexander Neundorf <neundorf at kde.org>
To: Brad King <brad.king at kitware.com>
Subject: Re: issue with imported library targets ?
Date: Thu, 12 Mar 2009 22:54:57 +0100

Hi Brad,

there is one more issue with imported library targets.
We have now e.g. ${KDE4_KDEUI_LIBRARY} in KDE, which resolves to the imported
target KDE4__kdeui .
Now if you try to use that for CMAKE_REQUIRED_LIBRARIES e.g. in
check_cxx_source_runs(), it breaks, because the trycompile-project doesn't
know about that imported target.

I made a quick almost working fix which we can add to KDE to make it work:
http://lists.kde.org/?l=kde-buildsystem&m=123689449526711&w=2

Something should go into cmake to make that work, not sure whether these
macros should be extended this way or whether cmCoreTryCompile should try to
analyze the flags and if it sees LINK_LIBRARIES iterate over it and handle it
appropriately. It seems almost a bit complicated for doing it in cmake code.

What do you think ?

Alex

==============================================================================

Date: Fri, 13 Mar 2009 09:20:07 -0400
From: Brad King <brad.king at kitware.com>
To: Alexander Neundorf <neundorf at kde.org>
Subject: Re: issue with imported library targets ?

Alexander Neundorf wrote:
> there is one more issue with imported library targets.
> We have now e.g. ${KDE4_KDEUI_LIBRARY} in KDE, which resolves to the imported
> target KDE4__kdeui .
> Now if you try to use that for CMAKE_REQUIRED_LIBRARIES e.g. in
> check_cxx_source_runs(), it breaks, because the trycompile-project doesn't
> know about that imported target.
>
> I made a quick almost working fix which we can add to KDE to make it work:
> http://lists.kde.org/?l=kde-buildsystem&m=123689449526711&w=2
>
> Something should go into cmake to make that work, not sure whether these
> macros should be extended this way or whether cmCoreTryCompile should try to
> analyze the flags and if it sees LINK_LIBRARIES iterate over it and handle it
> appropriately. It seems almost a bit complicated for doing it in cmake code.

I was reading that thread and realized the problem as soon as I saw
mention of KDE4__kdeui in a try-compile message thread.  Certainly we
should try to get the C++ code implementing try-compile to take care of
this.  Since the try-compile implementation knows what configuration it
will try to build (Debug, IIRC) it can just pre-compute the path to the
library and give it to the test project.  I'm not sure how to handle
dependencies though.  Perhaps instead the generated test project should
get code to reproduce the imported target.

I'll try to get to this sometime next week.

-Brad

==============================================================================

From: Alexander Neundorf <neundorf at kde.org>
To: Brad King <brad.king at kitware.com>
Subject: Re: issue with imported library targets ?
Date: Sun, 15 Mar 2009 21:37:32 +0100

On Friday 13 March 2009, you wrote:
> Alexander Neundorf wrote:
> > there is one more issue with imported library targets.
> > We have now e.g. ${KDE4_KDEUI_LIBRARY} in KDE, which resolves to the
> > imported target KDE4__kdeui .
> > Now if you try to use that for CMAKE_REQUIRED_LIBRARIES e.g. in
> > check_cxx_source_runs(), it breaks, because the trycompile-project
> > doesn't know about that imported target.
> >
> > I made a quick almost working fix which we can add to KDE to make it
> > work: http://lists.kde.org/?l=kde-buildsystem&m=123689449526711&w=2
> >
> > Something should go into cmake to make that work, not sure whether these
> > macros should be extended this way or whether cmCoreTryCompile should try
> > to analyze the flags and if it sees LINK_LIBRARIES iterate over it and
> > handle it appropriately. It seems almost a bit complicated for doing it
> > in cmake code.
>
> I was reading that thread and realized the problem as soon as I saw
> mention of KDE4__kdeui in a try-compile message thread.  Certainly we
> should try to get the C++ code implementing try-compile to take care of
> this.

As you may have seen I posted an improved version of my script to the
buildsystem list. It should now be good enough to make it work for now.
But I have the feeling that adding this macro everywhere feels not ideal. I
guess it's really better if try_compile could handle this.

Alex

==============================================================================

Subject: Re: issue with imported library targets ?
From: Brad King <brad.king at kitware.com>
To: neundorf at kde.org
Date: Mon, 16 Mar 2009 09:26:25 -0400

Alexander Neundorf wrote:
> As you may have seen I posted an improved version of my script to the
> buildsystem list. It should now be good enough to make it work for now.
> But I have the feeling that adding this macro everywhere feels not ideal. I
> guess it's really better if try_compile could handle this.

I guess that is okay for this instance of the problem but a general solution
would be better.  Can you please submit a bug tracker issue for this?  Please
include links to the kde-buildsystem archives for this thread.

Thanks,
-Brad

==============================================================================




More information about the cmake-developers mailing list