[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cmake
Subject:    Re: [CMake] cmake trouble
From:       Eric Clark <eclark () ara ! com>
Date:       2012-10-22 16:04:22
Message-ID: EBDAAC048EBA3D4B8F00BB32CC24C8D9010777931C () mail-west-2 ! exchange2 ! ara ! wan
[Download RAW message or body]

[Attachment #2 (text/plain)]

Hello,

First off, you cannot call both add_executable and add_library in the same CMakeLists \
file. Here is what I can say about your other questions:


1.       All commands that require a target have to come after you have created the \
target via add_executable or add_library. This is simply because you need to have a \
target before you can adds things to it.

2.       I am not real sure why this would work. But, for common practices, you \
should always call target_link_libraries after your call to add_library or \
add_executable for the reason stated above.

3.       Again, this is the same answer. It will work as long as you make the call to \
the command after add_library or add_executable.

Hope this helps.
Eric

From: cmake-bounces@cmake.org [mailto:cmake-bounces@cmake.org] On Behalf Of ??
Sent: Monday, October 22, 2012 10:25 AM
To: cmake@cmake.org
Subject: [CMake] cmake trouble

Hello:
      I am using cmake for three months now.
but was trouble in a situation ¡£for details bellow: (in Windows)

ADD_LIBRARY(test SHARED  ${LIBTEST_SRC} ${LIBHELLO_SRC})
#ADD_LIBRARY(test STATIC ${LIBTEST_SRC} ${LIBHELLO_SRC})

#add executable
AUX_SOURCE_DIRECTORY(. FAN_SRC)
TARGET_LINK_LIBRARIES(fan test)
ADD_EXECUTABLE(fan ${FAN_SRC})

1.if i put "TARGET_LINK_LIBRARIES(fan test)" before ADD_EXECUTABLE command,this does \
not work ,why??

2. but if i  ADD_LIBRARY(test STATIC ${LIBTEST_SRC} ${LIBHELLO_SRC}) £¬it is  ok£¬why \
??

3.if i put "TARGET_LINK_LIBRARIES(fan test)" after ADD_EXECUTABLE command£¬it works \
,why ??

I am waiting for your help !!

With best wishes.<app:lj:%E6%AD%A4%E8%87%B4%E6%95%AC%E7%A4%BC?ljtype=blng&ljblngcont=0&ljtran=With%20best%20%20wishes.>



[Attachment #3 (text/html)]

<html xmlns:v="urn:schemas-microsoft-com:vml" \
xmlns:o="urn:schemas-microsoft-com:office:office" \
xmlns:w="urn:schemas-microsoft-com:office:word" \
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" \
xmlns="http://www.w3.org/TR/REC-html40"> <head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
	{font-family:SimSun;
	panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
	{font-family:SimSun;
	panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
	{font-family:"\@SimSun";
	panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:SimSun;
	mso-fareast-language:ZH-CN;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
	{mso-style-priority:34;
	margin-top:0in;
	margin-right:0in;
	margin-bottom:0in;
	margin-left:.5in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:SimSun;
	mso-fareast-language:ZH-CN;}
span.EmailStyle17
	{mso-style-type:personal-reply;
	font-family:"Calibri","sans-serif";
	color:#1F497D;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-family:"Calibri","sans-serif";}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
/* List Definitions */
@list l0
	{mso-list-id:693506633;
	mso-list-type:hybrid;
	mso-list-template-ids:-1074340364 67698703 67698713 67698715 67698703 67698713 \
67698715 67698703 67698713 67698715;} @list l0:level1
	{mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-.25in;}
@list l0:level2
	{mso-level-number-format:alpha-lower;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-.25in;}
@list l0:level3
	{mso-level-number-format:roman-lower;
	mso-level-tab-stop:none;
	mso-level-number-position:right;
	text-indent:-9.0pt;}
@list l0:level4
	{mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-.25in;}
@list l0:level5
	{mso-level-number-format:alpha-lower;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-.25in;}
@list l0:level6
	{mso-level-number-format:roman-lower;
	mso-level-tab-stop:none;
	mso-level-number-position:right;
	text-indent:-9.0pt;}
@list l0:level7
	{mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-.25in;}
@list l0:level8
	{mso-level-number-format:alpha-lower;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-.25in;}
@list l0:level9
	{mso-level-number-format:roman-lower;
	mso-level-tab-stop:none;
	mso-level-number-position:right;
	text-indent:-9.0pt;}
ol
	{margin-bottom:0in;}
ul
	{margin-bottom:0in;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">Hello,<o:p></o:p></span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">First \
off, you cannot call both add_executable and add_library in the same CMakeLists file. \
Here is what I can say about your other questions:<o:p></o:p></span></p> <p \
class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
 <p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo1"><![if \
!supportLists]><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><span \
style="mso-list:Ignore">1.<span style="font:7.0pt &quot;Times New \
Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
</span></span></span><![endif]><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">All \
commands that require a target have to come after you have created the target via \
add_executable or add_library. This is simply because you need  to have a target \
before you can adds things to it.<o:p></o:p></span></p> <p class="MsoListParagraph" \
style="text-indent:-.25in;mso-list:l0 level1 lfo1"><![if !supportLists]><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><span \
style="mso-list:Ignore">2.<span style="font:7.0pt &quot;Times New \
Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
</span></span></span><![endif]><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">I \
am not real sure why this would work. But, for common practices, you should always \
call target_link_libraries after your call to add_library or  add_executable for the \
reason stated above.<o:p></o:p></span></p> <p class="MsoListParagraph" \
style="text-indent:-.25in;mso-list:l0 level1 lfo1"><![if !supportLists]><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><span \
style="mso-list:Ignore">3.<span style="font:7.0pt &quot;Times New \
Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
</span></span></span><![endif]><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">Again, \
this is the same answer. It will work as long as you make the call to the command \
after add_library or add_executable.<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">Hope \
this helps.<o:p></o:p></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">Eric<o:p></o:p></span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
 <div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span \
style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span \
style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> \
cmake-bounces@cmake.org [mailto:cmake-bounces@cmake.org] <b>On Behalf Of </b>??<br>
<b>Sent:</b> Monday, October 22, 2012 10:25 AM<br>
<b>To:</b> cmake@cmake.org<br>
<b>Subject:</b> [CMake] cmake trouble<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<div>
<p class="MsoNormal"><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">Hello:<o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
I&nbsp;am&nbsp;using cmake&nbsp;for three months now.<o:p></o:p></span></p> </div>
<div>
<p class="MsoNormal"><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">but&nbsp;was \
trouble in&nbsp;a situation&nbsp;</span><span lang="ZH-CN" \
style="font-size:10.5pt;color:black">¡£</span><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">for
  details bellow: (in Windows)<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">&nbsp;<o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">ADD_LIBRARY(test \
SHARED&nbsp; ${LIBTEST_SRC} ${LIBHELLO_SRC})<br> #ADD_LIBRARY(test STATIC \
${LIBTEST_SRC} ${LIBHELLO_SRC})<o:p></o:p></span></p> </div>
<div>
<p class="MsoNormal"><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black"><br>
 #add executable<br>
AUX_SOURCE_DIRECTORY(. FAN_SRC)<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">TARGET_LINK_LIBRARIES(fan \
test)<br> ADD_EXECUTABLE(fan ${FAN_SRC})<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">&nbsp;<o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">1.if \
i put &quot;TARGET_LINK_LIBRARIES(fan test)&quot; before ADD_EXECUTABLE command,this \
does not work ,why??<o:p></o:p></span></p> </div>
<div>
<p class="MsoNormal"><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">&nbsp;<o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">2. \
but if i&nbsp; ADD_LIBRARY(test STATIC ${LIBTEST_SRC} \
${LIBHELLO_SRC})&nbsp;</span><span lang="ZH-CN" \
style="font-size:10.5pt;color:black">£¬</span><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">it
  is&nbsp; ok</span><span lang="ZH-CN" \
style="font-size:10.5pt;color:black">£¬</span><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">why \
??<o:p></o:p></span></p> </div>
<div>
<p class="MsoNormal"><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">&nbsp;<o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">3.if \
i put &quot;TARGET_LINK_LIBRARIES(fan test)&quot; after ADD_EXECUTABLE \
command</span><span lang="ZH-CN" style="font-size:10.5pt;color:black">£¬</span><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">it
  works ,why ??<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">&nbsp;<o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">I \
am waiting for your help !!<o:p></o:p></span></p> </div>
<div>
<p class="MsoNormal"><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">&nbsp;<o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black"><a \
href="app:lj:%E6%AD%A4%E8%87%B4%E6%95%AC%E7%A4%BC?ljtype=blng&amp;ljblngcont=0&amp;ljtran=With%20best%20%20wishes." \
target="_self">With best wishes.</a><o:p></o:p></span></p> </div>
<div>
<p class="MsoNormal"><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">&nbsp;<o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">&nbsp;<o:p></o:p></span></p>
 </div>
<div>
<p class="MsoNormal"><span \
style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">&nbsp;<o:p></o:p></span></p>
 </div>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p>&nbsp;</o:p></p>
</div>
</div>
</body>
</html>



--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
--===============0631816547==--

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic