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

List:       cmake
Subject:    Re: [CMake] change add_executable to add_library leads to an error
From:       Cedric Doucet <cedric.doucet () inria ! fr>
Date:       2015-12-23 13:54:43
Message-ID: 1173688230.4526873.1450878883939.JavaMail.zimbra () inria ! fr
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi Petr! 

Yes, it helps me a lot! 
I have tried to apply your approach and this is exactly what I want. 

Thank you! :) 

Cédric 

----- Mail original -----

> De: "Petr Kmoch" <petr.kmoch@gmail.com>
> À: "Cedric Doucet" <cedric.doucet@inria.fr>
> Cc: cmake@cmake.org
> Envoyé: Mercredi 23 Décembre 2015 14:41:55
> Objet: Re: [CMake] change add_executable to add_library leads to an error

> Hi Cedric.

> add_custom_target() does not work the way you think it does. The arguments
> given after the target name are commands which the custom target will
> execute. So what your custom target `statphys` does is execute a program
> named `simol-statphys`. When `simol-statphys` was the name of an executable
> target, CMake figured out a dependency based on this and arranged it so that
> `simol-statphys` is built first and then executed.

> However, when `simol-statphys` is a library target, it does not receive this
> special treatment; and why would it, since you cannot execute a library.
> Therefore, it simply tries to execute a program named `simol-statphys` and,
> expectedly, fails.

> If I understand your intention with the custom target correctly, you want to
> have a shorthand alias for the target in the makefile. The correct syntax to
> achieve that would be:

> add_custom_target(statphys)
> add_dependencies(statphys simol-statphys)

> Hope this helps.

> Petr

> On Wed, Dec 23, 2015 at 2:26 PM, Cedric Doucet < cedric.doucet@inria.fr >
> wrote:

> > Hello,
> 

> > I have the following script:
> 
> > =================================
> 

> > file(GLOB_RECURSE statphys "*.cpp")
> 

> > #add_library(simol-statphys SHARED ${statphys})
> 
> > add_executable(simol-statphys ${statphys})
> 

> > add_dependencies(simol-statphys simol-core)
> 

> > add_custom_target(statphys simol-statphys)
> 

> > target_link_libraries(simol-statphys simol-core)
> 

> > target_link_libraries(simol-statphys
> > ${ARMADILLO_INSTALL_DIR}/lib/libarmadillo.so)
> 
> > target_link_libraries(simol-statphys
> > ${YAMLCPP_INSTALL_DIR}/lib/libyaml-cpp.a)
> 

> > =================================
> 

> > I would like generate a shared library simol-statphys instead of an
> > executable simol-statphys.
> 

> > In other words, I would like to replace the call to add_executable, to the
> > one which is contained in the comment below this call.
> 

> > However, if I do this, and I type
> 

> > make statphys
> 

> > I get the following error message:
> 

> > Scanning dependencies of target statphys
> 
> > /bin/sh: 1: simol-statphys: not found
> 
> > make[3]: *** [src/modules/statphys/CMakeFiles/statphys] Erreur 127
> 
> > make[2]: *** [src/modules/statphys/CMakeFiles/statphys.dir/all] Erreur 2
> 
> > make[1]: *** [src/modules/statphys/CMakeFiles/statphys.dir/rule] Erreur 2
> 
> > make: *** [statphys] Erreur 2
> 

> > Does someone can explain me where do the problem come from?
> 

> > Cédric
> 

> > --
> 

> > Powered by www.kitware.com
> 

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

> > Kitware offers various services to support the CMake community. For more
> > information on each offering, please visit:
> 

> > CMake Support: http://cmake.org/cmake/help/support.html
> 
> > CMake Consulting: http://cmake.org/cmake/help/consulting.html
> 
> > CMake Training Courses: http://cmake.org/cmake/help/training.html
> 

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

> > Follow this link to subscribe/unsubscribe:
> 
> > http://public.kitware.com/mailman/listinfo/cmake
> 

[Attachment #5 (text/html)]

<html><body><div style="font-family: times new roman, new york, times, serif; \
font-size: 12pt; color: #000000"><div><br></div><div>Hi \
Petr!</div><div><br></div><div>Yes, it helps me a lot!</div><div>I have tried to \
apply your approach and this is exactly what I want.</div><div><br></div><div>Thank \
you! :)</div><div><br></div><div>Cédric</div><div><br></div><hr \
id="zwchr"><blockquote style="border-left:2px solid \
#1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:norm \
al;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>De: \
</b>"Petr Kmoch" &lt;petr.kmoch@gmail.com&gt;<br><b>À: </b>"Cedric Doucet" \
&lt;cedric.doucet@inria.fr&gt;<br><b>Cc: </b>cmake@cmake.org<br><b>Envoyé: \
</b>Mercredi 23 Décembre 2015 14:41:55<br><b>Objet: </b>Re: [CMake] change \
add_executable to add_library leads to an error<br><div><br></div><div \
dir="ltr"><div><div><div><div><div><div>Hi \
Cedric.<br><div><br></div></div>add_custom_target() does not work the way you think \
it does. The arguments given after the target name are commands which the custom \
target will execute. So what your custom target `statphys` does is execute a program \
named `simol-statphys`. When `simol-statphys` was the name of an executable target, \
CMake figured out a dependency based on this and arranged it so that `simol-statphys` \
is built first and then executed.<br><div><br></div></div>However, when \
`simol-statphys` is a library target, it does not receive this special treatment; and \
why would it, since you cannot execute a library. Therefore, it simply tries to \
execute a program named `simol-statphys` and, expectedly, \
fails.<br><div><br></div></div>If I understand your intention with the custom target \
correctly, you want to have a shorthand alias for the target in the makefile. The \
correct syntax to achieve that would \
be:<br><div><br></div></div>&nbsp;add_custom_target(statphys)<br></div>&nbsp;add_dependencies(statphys \
simol-statphys)<br><div><br></div></div><div>Hope this \
helps.<br></div><div><br></div>Petr<br></div><div class="gmail_extra"><br><div \
class="gmail_quote">On Wed, Dec 23, 2015 at 2:26 PM, Cedric Doucet <span \
dir="ltr">&lt;<a href="mailto:cedric.doucet@inria.fr" \
target="_blank">cedric.doucet@inria.fr</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div><div style="font-family:times new roman,new \
york,times,serif;font-size:12pt;color:#000000"><div><br></div><div>Hello,</div><div><br></div><div>I \
have the following script:</div><div>=================================</div><div><p \
style="margin:0px">file(GLOB_RECURSE statphys "*.cpp")</p><p \
style="margin:0px"><br></p><p style="margin:0px">#add_library(simol-statphys SHARED \
${statphys})<br>add_executable(simol-statphys ${statphys})</p><p \
style="margin:0px"><br></p><p style="margin:0px">add_dependencies(simol-statphys \
simol-core)<br></p><p style="margin:0px">add_custom_target(statphys \
simol-statphys)</p><p style="margin:0px"><br></p><p \
style="margin:0px">target_link_libraries(simol-statphys simol-core)</p><p \
style="margin:0px">target_link_libraries(simol-statphys \
${ARMADILLO_INSTALL_DIR}/lib/libarmadillo.so)<br>target_link_libraries(simol-statphys \
${YAMLCPP_INSTALL_DIR}/lib/libyaml-cpp.a)</p><p \
style="margin:0px">=================================</p><p \
style="margin:0px"><br></p><p style="margin:0px">I would like generate a shared \
library simol-statphys instead of an executable simol-statphys.</p><p \
style="margin:0px">In other words, I would like to replace the call to \
add_executable, to the one which is contained in the comment below this call.</p><p \
style="margin:0px"><br></p><p style="margin:0px">However, if I do this, and I \
type</p><p style="margin:0px"><br></p><p style="margin:0px">&nbsp; &nbsp; make \
statphys</p><p style="margin:0px"><br></p><p style="margin:0px">I get the following \
error message:</p><p style="margin:0px"><br></p><p style="margin:0px">Scanning \
dependencies of target statphys<br>/bin/sh: 1: simol-statphys: not found<br>make[3]: \
*** [src/modules/statphys/CMakeFiles/statphys] Erreur 127<br>make[2]: *** \
[src/modules/statphys/CMakeFiles/statphys.dir/all] Erreur 2<br>make[1]: *** \
[src/modules/statphys/CMakeFiles/statphys.dir/rule] Erreur 2<br>make: *** [statphys] \
Erreur 2</p><p style="margin:0px"><br></p><p style="margin:0px">Does someone can \
explain me where do the problem come from?</p><p style="margin:0px"><br></p><p \
style="margin:0px">Cédric</p></div><div><br></div></div></div><br>--<br> <br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" \
target="_blank">www.kitware.com</a><br> <br>
Please keep messages on-topic and check the CMake FAQ at: <a \
href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" \
target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br> <br>
Kitware offers various services to support the CMake community. For more information \
on each offering, please visit:<br> <br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" \
target="_blank">http://cmake.org/cmake/help/support.html</a><br> CMake Consulting: <a \
href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" \
target="_blank">http://cmake.org/cmake/help/consulting.html</a><br> CMake Training \
Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" \
target="_blank">http://cmake.org/cmake/help/training.html</a><br> <br>
Visit other Kitware open-source projects at <a \
href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" \
target="_blank">http://www.kitware.com/opensource/opensource.html</a><br> <br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" \
target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br></blockquote></div><br></div>
 </blockquote><br></div></body></html>



-- 

Powered by www.kitware.com

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

Kitware offers various services to support the CMake community. For more information \
on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

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

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake



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

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