[CMake] How to findXXX libraries with debug suffix

Philip Lowman philip at yhbt.com
Thu Feb 11 08:54:50 EST 2010


On Wed, Feb 10, 2010 at 10:49 AM, Will Dicharry
<wdicharry at stellarscience.com> wrote:
>> My only other comment is that some modules already use the following
>> form (usually due to someone adding DEBUG support later)
>> FOO_LIBRARY (cache variable)
>> FOO_LIBRARY_DEBUG (cache variable)
>> FOO_LIBRARIES (normal variable with debug/optimized keywords when
>> FOO_LIBRARY_DEBUG is available, else normal variable set to
>> FOO_LIBRARY)
>>
>> It would be nice to see a second macro that supports this format.
>
> I guess I'll have to think about that for a bit. But really, if other
> modules are going to need to modify code to use the macro, shouldn't they
> move to the more modern and descriptive form while they're at it? I know
> they probably have to maintain backwards compatibility, but they can do that
> by using the macro and setting FOO_LIBRARY to FOO_LIBRARY_RELEASE after the
> macro is called.

So if I understand correctly the code would do this?
find_library(FOO_LIBRARY ...)
find_library(FOO_LIBRARY_DEBUG ...)
set(FOO_LIBRARY_RELEASE ${FOO_LIBRARY})
call_the_macro()
   # macro creates FOO_LIBRARIES debug/optimized keywords
   # macro also sets FOO_LIBRARY with debug/optimized keywords *

I guess that probably would be safe and maintain backwards
compatibility with the module with the exception possibly of setting
FOO_LIBRARY to have the debug/optimized keywords (see below).

> I'm not sure I understand the situation you're describing here. Are you
> referring to the older backwards compatibility case, or something about the
> usual FOO_LIBRARY_DEBUG and FOO_LIBRARY_RELEASE case?

Sorry I wasn't very clear.  This covers the older "backwards
compatibility" case.  What I mean to say is that if the user was
relying on FOO_LIBRARY within existing target_link_libraries() calls
like below, they will get the warning below if FOO_LIBRARY is
redefined to contain debug/optimized keywords.

target_link_libraries(bar optimized ${FOO_LIBRARY})

# now FOO_LIBRARY contains
# optimized foo.so debug food.so

CMake Warning (dev) at CMakeLists.txt:8 (target_link_libraries):
  Link library type specifier "optimized" is followed by specifier
  "optimized" instead of a library name.  The first specifier will be
  ignored.

Removing the setting of FOO_LIBRARY to contain debug/optimized
keywords from your macro could break people.  Leaving it in if
FOO_LIBRARY is used in the manor I illustrated causes warnings.  You
might want to check with if(DEFINED FOO_LIBRARY) and if so not set it
maybe?

-- 
Philip Lowman


More information about the CMake mailing list