<br><br>
<div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">ankit jain</b> <span dir="ltr"><<a href="mailto:ankitguddu@gmail.com">ankitguddu@gmail.com</a>></span><br>Date: 2009/2/11<br>
Subject: Re: [CMake] MSVC7.1 static link question<br>To: Brad King <<a href="mailto:brad.king@kitware.com">brad.king@kitware.com</a>><br><br><br><br><br>
<div class="gmail_quote">2009/2/10 Brad King <span dir="ltr"><<a href="mailto:brad.king@kitware.com" target="_blank">brad.king@kitware.com</a>></span>
<div>
<div></div>
<div class="Wj3C7c"><br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>
<div></div>
<div>Luigi Calori wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Bill Hoffman ha scritto:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Philip Lowman wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">On Mon, Feb 9, 2009 at 12:39 PM, Luigi Calori <<a href="mailto:l.calori@cineca.it" target="_blank">l.calori@cineca.it</a> <mailto:<a href="mailto:l.calori@cineca.it" target="_blank">l.calori@cineca.it</a>>> wrote:<br>
<br> I' m quite a newbie in static linking, I would like to combine two lib<br> into one:<br> say libtiff needs libjpeg and zlib<br> If you generate them separately, then when you build an executable that<br> needs libtiff, you have to link also libjpeg and zlib otherwise unref<br>
happens<br> It is possible, under VisualStudio interface, to specify libjpeg.lib and<br> zlib.lib as Additional Dependencies<br> This way (even if the linker show warnings as duplicate symbols) I<br> obtain a libtiff that can be used alone.<br>
My question is: can I obtain the same result with cmake?<br> I' ve tried to use TARGET_LINK_LIBRARIES, that is perfecly working for<br> exe and SHARED linkage but no success: the<br> vs project has always the Additional Dependencies field empty.<br>
<br> Am I completely missing something?<br><br></blockquote>CMake does not work that way since it is not achievable cross platform. If you project is CMake based CMake will chain the libraries. If you use other build tools then you will have to explicitly list libjpeg and zlib with the libtiff. To do this in CMake you have two options:<br>
<br>1. have a library that uses libtiff<br>add_library(mylib ...)<br>target_link_libraries(mylib libtiff libjepg zlib)<br>add_executable(myexe ...)<br>target_link_libraries(myexe mylib) # will link in tiff jpeg and zlib<br>
<br>2. create an imported target for libtiff<br>add_library(libtiff IMPORTED)<br>set_target_properties(libtiff PROPERTIES IMPORTED_LOCATION /path/to/libtiff.lib)<br>target_link_libraries(libtiff libjpeg zlib)<br>add_executable(myexe ...)<br>
target_link_libraries(myexe libtiff) # will link jpeg and zlib<br><br><br>-Bill<br><br><br><br></blockquote>Hi Philip and Bill:<br><br>I tried Philip suggestion and it seem working: it adds the flags as Additiona Optins in the commandline form and it seems to produce a<br>
libtiff.lib that links ok.<br>The problem is that STATIC_LIBRARY_FLAGS property is not differentiated between Debug / Release.<br><br>Bill, is your method equivalent?<br><br>Is your suggestion applicable if the exe and the lib stay in two completely different projects?<br>
<br>What I mean is that I ' m willing to have a CMake project that BUILDS and install libtiff.lib (static)<br><br>Then I have another project that build a .dll (or .exe, I think it behave the same) that Find and use my libtiff.lib.<br>
<br>Both your suggested method seem to assume that myexe and libtiff are built at the same time.<br>This is not my case, I would like build libtiff static on win32 in such a way that allow other projects (built with cmake) to link it without adding explicitly the other dependent libraries.<br>
so to not require changes in the dependent project (it is actually OpenSceneGraph, Philip)<br>So either modifying VS project or adding STATIC_LIBRARY_FLAGS I am able to do.<br><br>I tried to use IMPORTED bud it did not worked<br>
</blockquote><br></div></div>Bill's example will not work as written. The target_link_libraries command<br>does not work for imported targets. See IMPORTED target and general<br>packaging documentation here:<br><br>
<a href="http://www.cmake.org/Wiki/CMake_2.6_Notes#Exporting_and_Importing_Targets" target="_blank">http://www.cmake.org/Wiki/CMake_2.6_Notes#Exporting_and_Importing_Targets</a><br> <a href="http://www.cmake.org/Wiki/CMake_2.6_Notes#Packages" target="_blank">http://www.cmake.org/Wiki/CMake_2.6_Notes#Packages</a><br>
<br>CMake 2.6 makes it easy to export targets from one project (either its<br>build tree or install tree) for use by another project.<br><font color="#888888"><br>-Brad</font>
<div>
<div></div>
<div></div></div></blockquote>
<div> </div></div></div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>
<div><span></span>If our library which we want to link is not in the curre tn project and we linkan executable to it through target_link_libraries by giving it entire path like /another/project/lib, will it not work properly. is it compulsory to use import and export targets for it.</div>
</div></blockquote>
<div> </div><font color="#888888">
<div>Ankit</div></font>
<div class="Ih2E3d">
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>
<div><span></span><br>_______________________________________________<br>Powered by <a href="http://www.kitware.com/" target="_blank">www.kitware.com</a><br><br>Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br><br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
</div></div></blockquote></div></div><br></div><br>