[CMake] Project being (unnecessarily) relinked

Jesper Eskilson jesper at eskilson.se
Wed Sep 12 04:10:47 EDT 2007


Jesper Eskilson wrote:
> Jesper Eskilson wrote:
>> Mike Jackson wrote:
>>>
>>>
>>> On Sep 11, 2007, at 3:03 AM, Jesper Eskilson wrote:
>>>
>>>>> A related question: if I include an external project in my solution
>>>>> using
>>>>>
>>>>> include_external_msproject(Bar ../../Bar/Bar.vcproj)
>>>>>
>>>>> can I later refer to this project using
>>>>>
>>>>> target_link_libraries(Foo Bar)
>>>>>
>>>>> More generally, what is the correct way to specify that a CMake
>>>>> target should be linked with some external library?
>>>>
>>>> It is this last question I would like to get an answer to.
>>>
>>>
>>> Say you have  another project that produces a library called 
>>> libBar.dll and that library is located in C:\Libs then you can refer 
>>> to that library in CMake directly. In other words, the cmake code you 
>>> have is absolutely correct:
>>>
>>> Target_link_Libraries(Foo Bar)
>>>
>>> with the following caveat: libBar.dll MUST be in a known directory 
>>> that the linker will look in. You can make sure of this by adding the 
>>> following cmake code above the "target_link_libraries" code:
>>>
>>>  LINK_DIRECTORIES ("C:\Libs")
>>
>> Ah. So if libBar.dll and libBar.lib are in different directories, 
>> *both* directories must be added using LINK_DIRECTORIES(), right?
>>
>> That should be documented somewhere (if it is, I've managed to miss it).
>>
> 
> After testing this, it appears that I still get the same relinking 
> behavior.

Well, that turned out to be a little hasty conclusion.

In case of linking with a DLL, having paths to both the dll and import 
lib in LINK_DIRECTORIES avoids relinking. So far, so good.

However, I still get relinks due to a dependency on a static library. In 
this case, I'm unable to add the path using LINK_DIRECTORIES since the 
path is different depending on the configuration. I'm currently adding 
the path using the LINK_FLAGS_{DEBUG, ...} target property (which 
probably is the cause of the relinking).

So, I would like to be able to do something like, given the debug 
version of MyStaticLib.lib is in lib/win32/debug:

LINK_DIRECTORIES_DEBUG(lib/win32/debug)
TARGET_LINK_LIBRARIES(Foo MyStaticLib)

To make things more difficult, I cannot do something like:

LINK_DIRECTORIES("lib/win32/$(ConfigurationName)")

because the configurations available for the static library 
(MyStaticLib.lib) do not map cleanly on the values for $(ConfigurationName).

<frustration>
Argh! Why can't things every be simple?!
</frustration>

Any hints on how to solve this?

-- 
/Jesper



More information about the CMake mailing list