[CMake] Correct usage of add_library

Sergei Nikulov sergey.nikulov at gmail.com
Wed Dec 23 07:18:33 EST 2015


2015-12-23 15:08 GMT+03:00 Cedric Doucet <cedric.doucet at inria.fr>:
>
> Sorry, it was a mistake!
> Everything works fine!
>

Nice to hear that.

And another update to my previous answer.

If your module depends on kernel library (as I understand now it
should be linked to module) you'd better use

target_link_libraries(module1 kernel)

https://cmake.org/cmake/help/v3.4/command/target_link_libraries.html

This dependency also should be resolved first and add kernel library
to linker command.

>
>
>
> ----- Mail original -----
>> De: "Cedric Doucet" <cedric.doucet at inria.fr>
>> À: "Sergei Nikulov" <sergey.nikulov at gmail.com>
>> Cc: cmake at cmake.org
>> Envoyé: Mercredi 23 Décembre 2015 12:59:48
>> Objet: Re: [CMake] Correct usage of add_library
>>
>>
>> Hello,
>>
>> thank you very much, it works fine!
>>
>> Do you know how to create a target so that
>>
>>    make mykernel
>>
>> creates a library libkernel.so?
>>
>>
>> For the moment, I create a library with the command
>>
>>    add_library(kernel SHARED ${src})
>>
>> and I build libkernel.so by typing make.
>>
>> I have found there exists a command add_custom_target but I don't know how to
>> use it.
>> I tried
>>
>>    add_custom_target(mykernel DEPENDS kernel)
>>
>> but it does not seems to take my include_directories instructions into
>> account since some headers are not found anymore (they're found when I type
>> 'make').
>>
>> Cédric
>>
>> ----- Mail original -----
>> > De: "Sergei Nikulov" <sergey.nikulov at gmail.com>
>> > À: "Cedric Doucet" <cedric.doucet at inria.fr>
>> > Cc: cmake at cmake.org
>> > Envoyé: Mercredi 23 Décembre 2015 11:38:38
>> > Objet: Re: [CMake] Correct usage of add_library
>> >
>> > Hello,
>> >
>> > 2015-12-23 13:32 GMT+03:00 Cedric Doucet <cedric.doucet at inria.fr>:
>> > >
>> > > Hello,
>> > >
>> > > I have a code which consist in a kernel and several independent modules
>> > > which depend on this kernel.
>> > > I would like to let users build the module they want by typing, for
>> > > example,
>> > >
>> > >     make module1
>> > >
>> > > to build the first module.
>> > > But, as this first module depends on the kernel, I need this kernel to be
>> > > built BEFORE module1.
>> > >
>> >
>> > You should add
>> >
>> > add_dependencies(module1 kernel)
>> >
>> > in your module1 CMakeLists.txt
>> >
>> > https://cmake.org/cmake/help/latest/command/add_dependencies.html
>> >
>> > HTH,
>> >
>> > --
>> > Best Regards,
>> > Sergei Nikulov
>> >
>> --
>>
>> 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
>>



-- 
Best Regards,
Sergei Nikulov


More information about the CMake mailing list