discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] GNURadio CMake question


From: Marcus Müller
Subject: Re: [Discuss-gnuradio] GNURadio CMake question
Date: Thu, 29 Oct 2015 10:58:29 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0

Hi Damindra,

I'm assuming you're looking at an out-of-tree (OOT) module that was generated with gr_modtool (i.e. that follows the usual CMake architecture).

So, there's a CMakeLists.txt in your main folder and in lib/.
When you look at the main CMakeLists.txt (I'm linking to an example here, [1]), you'll find lines like
find_package(PackageName)
which is a way of telling CMake to look into a few directories, looking for a file called "FindPackageName.cmake".
Let's illustrate this with:
find_package(CppUnit)
This makes CMake look into your OOT's cmake/Modules/, and execute what's in FindCppUnit.cmake[2]. What that does is very similar to the magic autotools does: It first asks pkg-config about cppunit [3] and then verifies that the files are actually are there, or tries to guess their location. Chances are your library also has a pkg-config entry[4].

So, what you'd do is
  1. verify noone else has written a CMake Find script for the C library you want. Else, use that, copy it to cmake/Modules, and jump to 3.
  2. copy cmake/Modules/FindCppUnit.cmake to cmake/Modules/FindYourLibrary.cmake; modify everything so that it doesn't say Cppunit, but your library.
  3. Take not of how the YourLibrary_LIBRARIES and YourLibrary_INCLUDE_DIRS are written exactly in FindYourModule.cmake
  4. add find_package(YourModule) to the main CMakeLists.txt
  5. in the lib/CMakeLists.txt, modify the "include_directories(${Boost_INCLUDE_DIR})" [5] to read "include_directories(${Boost_INCLUDE_DIR} ${YourLibrary_INCLUDE_DIRS})"
  6. in the lib/CMakeLists.txt, modify the "target_link_libraries" [6] directives to include "${YourLibrary_LIBRARIES}"

Notice that this clearly isn't the fastest way to just link against a library; you could of course also just "hardcode" the library name and include paths in 5. and 6., but 1. -- 4. gives you a portable (to some extent, even to Windows) and reusable solution, even on systems (like mine) where self-built libraries might be in totally unusual locations. I personally find writing build scripts a bit boring, but its a job worth doing right from the start, because fixing the problems you get when you try to run the same build procedure on a slightly different machine just isn't worth it. Not to mention the frustration you save other people when they happen to try your code on their machine.

Best regards, and happy hacking,
Marcus


[1] https://github.com/marcusmueller/gr-debugme/blob/master/CMakeLists.txt#L104
[2] https://github.com/marcusmueller/gr-debugme/blob/master/cmake/Modules/FindCppUnit.cmake
[3] https://github.com/marcusmueller/gr-debugme/blob/master/cmake/Modules/FindCppUnit.cmake#L13
[4] check by running "pkg-config --list-all|grep -i NAMEOFYOURLIBRARY"
[5] https://github.com/marcusmueller/gr-debugme/blob/master/lib/CMakeLists.txt#L25
[6] https://github.com/marcusmueller/gr-debugme/blob/master/lib/CMakeLists.txt#L39
On 29.10.2015 04:28, Damindra Bandara wrote:
Hi,

I am interested in adding an additional C library (shared object) into GNU Radio.  In auto tools it would be equivalent to a LDFLAGS.  I would be glad if I could know how to add a -lcustom library to cmake?

Thank You,
Damindra


_______________________________________________
Discuss-gnuradio mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio


reply via email to

[Prev in Thread] Current Thread [Next in Thread]