[opensuse-packaging] CMake and OBS

Hi, Are there any best known methods to package CMake based projects using the open build service ? Specifically what I am looking forward to is a simplified way of: 1) Installing all the libraries that CMake generates to /usr/lib (or) /opt/<company>/lib 2) Installing all the binaries that CMake generates to /usr/bin (or) /opt/<company>/bin 3) Populate BuildRequires: based on the find_package inside the CMakeLists.txt( 4) Building only a small subset of all the targets supported by the CMake file in a project. To explain on this point. Assume that my project has 10 targets and I need only 5 targets (3 binaries and 2 libraries that they depend) to be shipped to the users. So, I want a way to generate a tarball with only these 3 binaries and their dependencies (2 libraries in our case), which can be used in a build-service project. If I am not using OBS for distributing the binaries, I can easily build the two binary targets alone and can ship the resultant binaries. But if I want to use CMake what is the best way for achieving this instead of creating a tarball with the sources for all the 10 targets ? I googled around a bit before asking here but could not find any relevant information. I see that CMake is used heavily in KDE and so some of the openSUSE packagers would have run into similar requirements and wanted to find out the best practices for using CMake in OBS. Thanks. Sankar -- To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-packaging+owner@opensuse.org

On Thu, Sep 05, 2013 at 12:45:53AM -0600, Sankar P wrote:
Hi,
Are there any best known methods to package CMake based projects using the open build service ?
[removing obs ML as this is not related to build system] Hi Sankar, have you checked the cmake macros written by Tomas Chvatal? Maybe some of your questions should be implemented as macro ... http://lists.opensuse.org/opensuse-factory/2013-08/msg00174.html Regards Michal Vyskocil
Specifically what I am looking forward to is a simplified way of:
1) Installing all the libraries that CMake generates to /usr/lib (or) /opt/<company>/lib 2) Installing all the binaries that CMake generates to /usr/bin (or) /opt/<company>/bin 3) Populate BuildRequires: based on the find_package inside the CMakeLists.txt( 4) Building only a small subset of all the targets supported by the CMake file in a project. To explain on this point. Assume that my project has 10 targets and I need only 5 targets (3 binaries and 2 libraries that they depend) to be shipped to the users. So, I want a way to generate a tarball with only these 3 binaries and their dependencies (2 libraries in our case), which can be used in a build-service project. If I am not using OBS for distributing the binaries, I can easily build the two binary targets alone and can ship the resultant binaries. But if I want to use CMake what is the best way for achieving this instead of creating a tarball with the sources for all the 10 targets ?
I googled around a bit before asking here but could not find any relevant information. I see that CMake is used heavily in KDE and so some of the openSUSE packagers would have run into similar requirements and wanted to find out the best practices for using CMake in OBS.
Thanks.
Sankar
-- To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-packaging+owner@opensuse.org
-- To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-packaging+owner@opensuse.org

Hi Sankar,
have you checked the cmake macros written by Tomas Chvatal? Maybe some of your questions should be implemented as macro ...
http://lists.opensuse.org/opensuse-factory/2013-08/msg00174.html
Thanks. Sorry for the late reply. Was down with some health issues. I shall look into this. At first glance I am not able to understand much. My packaging skills are pretty rudimentary and I have not tried with much of these macros. I will try to play with some of these CMake macros in a test project and will update. Thanks for the pointer. Sankar -- To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-packaging+owner@opensuse.org

Dnia czwartek, 5 września 2013 00:45:53 Sankar P pisze:
Hi,
Are there any best known methods to package CMake based projects using the open build service ?
Specifically what I am looking forward to is a simplified way of:
1) Installing all the libraries that CMake generates to /usr/lib (or) /opt/<company>/lib 2) Installing all the binaries that CMake generates to /usr/bin (or) /opt/<company>/bin
{ rpm -qd cmake; } Chris -- To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-packaging+owner@opensuse.org

On 9/6/2013 at 11:22 PM, in message <1477147.Yx7NZbg7Kf@linux-d902>, Krzysztof *elechowski<giecrilj@stegny.2a.pl> wrote: Dnia czwartek, 5 wrze*nia 2013 00:45:53 Sankar P pisze: Hi,
Are there any best known methods to package CMake based projects using the open build service ?
Specifically what I am looking forward to is a simplified way of:
1) Installing all the libraries that CMake generates to /usr/lib (or) /opt/<company>/lib 2) Installing all the binaries that CMake generates to /usr/bin (or) /opt/<company>/bin
{ rpm -qd cmake; }
{ rpm -qd cmake | xargs grep -i buildservice; } What I am looking for is a way to define the install prefixes in the OBS' .spec files as opposed to generating RPM via CMake itself. Sankar -- To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-packaging+owner@opensuse.org

Hi, 1. library install path (DLIB_INSTALL_DIR) is defined by CMakeLists.txt itself, no matter where you are. the same applys to binary install path. see this CMakeLists.txt from fcitx: https://github.com/fcitx/fcitx/blob/master/CMakeLists.txt starting from line 189 and it will answer all your questions. 2. fetching rpm dependencies from CMakeLists.txt on the fly is not possible. Because the name in find_package() is not the same as our package name. OBS doesn't have this implemented. 3. actually it's not a cmake thing. it's a rpm thing. You need something called conditional builds and a little tweak to your source (if you want to _just_ upload 5 targets as Source) In details you can read rpm manual, this chapter: http://rpm.org/gitweb?p=rpm.git;a=blob;f=doc/manual/conditionalbuilds;hb=HEA... And this in our wiki (written by me btw): http://en.opensuse.org/openSUSE:RPM_conditional_builds Here I'll just give you some briefings: 1. Tweak your source code to make the additional targets supplemental and their dependencies optional which can be turned on with a "-DXXX=On", also see fcitx CMakeLists.txt for example. The final result should be this: you `rm -rf` you conditional directory, the source still builds just by disabling those targets. Then you can uploaded a _clean_ source (maybe cut version of Novell product for example) 2. use %define or anything I mentioned in the wiki to define a switch in specfile. eg: %define _with_gtk3 0 This means "with gtk3" is _false_ Then tweak BuildRequires, eg: %if %{_with_gtk3} == 1 BuildRequires: gtk3-devel Requires: gtk3-tools %endif This means, if true, blabla, so you have to build it locally first to get all the things when it is true (obs will build it as a false, so you will not know what will be generated under a true situation) And in %build section, turn on your "optional" targets if "withg_gtk3" is 1, eg: %build cmake -DCMAKE_INSTALL_PREFIX=%{_prefix} -DLIB_INSTALL_DIR=%{_libdir} \ %if %{_with_gtk3} == 1 -DENABLE_GTK3=ON \ %endif .. And your %files section: %files [...] %if %{_with_gtk3} == 1 %{_libdir}/gtk3.so %endif Here you got it! But notice that the _with_gtk3 macro is "defined" by me. so rpm won't recognize it without the specfile, which means, if you download the src.rpm, you can just: rpmbuild --rebuild --with-gtk3=1 *.src.rpm Something like that, because the _with_gtk3 is only usable inside _this_ specfile. So you _must_ unrpm and change the number then rpmbuild -ba *.spec to get that. While rpm seems to have a "%bcond_with(out)" macro defined by default, which is harder to learn but is rebuild friendly. Good luck! Greetings Marguerite -- To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-packaging+owner@opensuse.org

Thanks for the help. But what I was looking for was something simple like %cmake and %cmake_install in the .spec file instead of setting up the CLIB_INSTALL_DIR etc. variables myself. The other link given by Michal seem to be useful and as per my requirements (not tried yet). Sankar
On 9/11/2013 at 01:35 AM, in message <CAK0PdA=YahRaM-bidsXwbMeWFodsWwp3gQgdSSA6Pbp6Vhspww@mail.gmail.com>, Marguerite Su <i@marguerite.su> wrote: Hi,
1. library install path (DLIB_INSTALL_DIR) is defined by CMakeLists.txt itself, no matter where you are. the same applys to binary install path.
see this CMakeLists.txt from fcitx:
https://github.com/fcitx/fcitx/blob/master/CMakeLists.txt
starting from line 189 and it will answer all your questions.
2. fetching rpm dependencies from CMakeLists.txt on the fly is not possible.
Because the name in find_package() is not the same as our package name. OBS doesn't have this implemented.
3. actually it's not a cmake thing. it's a rpm thing.
You need something called conditional builds and a little tweak to your source (if you want to _just_ upload 5 targets as Source)
In details you can read rpm manual, this chapter:
http://rpm.org/gitweb?p=rpm.git;a=blob;f=doc/manual/conditionalbuilds;hb=HEA D
And this in our wiki (written by me btw):
http://en.opensuse.org/openSUSE:RPM_conditional_builds
Here I'll just give you some briefings:
1. Tweak your source code to make the additional targets supplemental and their dependencies optional which can be turned on with a "-DXXX=On", also see fcitx CMakeLists.txt for example.
The final result should be this: you `rm -rf` you conditional directory, the source still builds just by disabling those targets.
Then you can uploaded a _clean_ source (maybe cut version of Novell product for example)
2. use %define or anything I mentioned in the wiki to define a switch in specfile.
eg: %define _with_gtk3 0
This means "with gtk3" is _false_
Then tweak BuildRequires, eg:
%if %{_with_gtk3} == 1 BuildRequires: gtk3-devel Requires: gtk3-tools %endif
This means, if true, blabla, so you have to build it locally first to get all the things when it is true (obs will build it as a false, so you will not know what will be generated under a true situation)
And in %build section, turn on your "optional" targets if "withg_gtk3" is 1, eg:
%build cmake -DCMAKE_INSTALL_PREFIX=%{_prefix} -DLIB_INSTALL_DIR=%{_libdir} \ %if %{_with_gtk3} == 1 -DENABLE_GTK3=ON \ %endif ..
And your %files section:
%files [...] %if %{_with_gtk3} == 1 %{_libdir}/gtk3.so %endif
Here you got it!
But notice that the _with_gtk3 macro is "defined" by me. so rpm won't recognize it without the specfile, which means, if you download the src.rpm, you can just:
rpmbuild --rebuild --with-gtk3=1 *.src.rpm
Something like that, because the _with_gtk3 is only usable inside _this_ specfile.
So you _must_ unrpm and change the number then rpmbuild -ba *.spec to get that.
While rpm seems to have a "%bcond_with(out)" macro defined by default, which is harder to learn but is rebuild friendly.
Good luck!
Greetings
Marguerite -- To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-packaging+owner@opensuse.org
-- To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-packaging+owner@opensuse.org

Dnia wtorek, 10 września 2013 12:16:15 Sankar P pisze:
What I am looking for is a way to define the install prefixes in the OBS' .spec files as opposed to generating RPM via CMake itself.
You specify those as named parameters to cmake. HTH, Chris -- To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-packaging+owner@opensuse.org
participants (5)
-
Krzysztof Żelechowski
-
Křištof Želechovski
-
Marguerite Su
-
Michal Vyskocil
-
Sankar P