[CMake] change add_executable to add_library leads to an error

Cedric Doucet cedric.doucet at inria.fr
Wed Dec 23 08:54:43 EST 2015


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 at gmail.com>
> À: "Cedric Doucet" <cedric.doucet at inria.fr>
> Cc: cmake at 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 at 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
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20151223/90698613/attachment.html>


More information about the CMake mailing list