Wireshark-dev: [Wireshark-dev] CMake support out of source plugin compilation

From: Maarten Bezemer <maarten.bezemer@xxxxxxxxx>
Date: Thu, 13 Nov 2014 14:21:16 +0100
Hello,

This email is (a bit) long, as I am trying to explain the Wireshark patches I 
send, as requested by Graham Bloice.


First of all: I am new to Wireshark and its development. Furthermore I am also 
new to cmake development/scripting. So I'll explain my context/background in 
this to make clear why I started this 'quest':
I am working on writing an ASN.1 dissector for a custom protocol we are trying 
to implement. Soon I decided it is inconvenient to need to full Wireshark 
source for the development of a simple dissector plugin. Hence I decided to go 
for 'out of source' plugin development, which seemed possible according to 
some examples.
These examples copied (cmake) helper scripts and somewhat modified them to make 
them work. This is only slightly better than requiring the complete Wireshark 
source, as these copied scripts do not stay up-to-date.
I am working on providing patches to adjust Wireshark to have the required 
scripts installed along Wireshark. Now I got asked to start a thread on this 
mailing list to provide information on the patches.


My first (and most important) commit [1] adds cmake scripts to find the 
Wireshark development (cmake) scripts. The main component is the 
WiresharkConfig.cmake.in. This template file is used to fill in all details of a 
particular build. Same goes for WiresharkConfigVersion.cmake. As said I am not 
a cmake expert, but I understood [2] that both are required by the 
FindWireshark.cmake script. This script is used by find_package(Wireshark) to 
actually find the Wireshark development information.

Next, I noticed that Wireshark and its plugins require glib, so I provided a 
patch that adds FindGLIB2.cmake to the Wireshark development installation [3].

And additionally, I provided a new cmake variable containing the Wireshark 
(shared) library, in order to help developers linking their code to the 
Wireshark library [4].

These three patches together, provide out of code cmake support for Wireshark.
As I mentioned, I want to build an ASN.1 based dissector, so I would like to 
have the asn2wrs.py script available to generate the C source code from my 
asn-files.

The first patch in the 'asn.1 series' [5] adds a FindAsn2Wrs.cmake script, that 
is able to find the asn2wrs.py file and makes it location available in the cmake 
variable ASN2WRS_EXECUTABLE. It also modifies UseAsn2Wrs.cmake to make use of 
this new variable.

Next, I futher modified UseAsn2Wrs.cmake, as it assumes it is only used in the 
Wireshark sources [6,7].

And finally, it is added to the wireshark development installation e.g. the 
wireshark-dev.deb package [8].

These 4 patches make asn2wrs.py available for an out of source cmake build of 
a ASN.1 dissector.


Besides these patches, I noticed that building the Debian packages (using 
either dpkg-build or pbuilder) result in an erroneous Wireshark installation. 
Theglobal plugin folder is set to '/usr//usr/lib/..etc..', so none of the 
plugins are found (and thus not loaded). This issue is fixed by [9].

But, fixing this issue showed anther problem: Since [10], CMAKE_INSTALL_LIBDIR 
is assumed to be relative to the installation prefix. But, it only got 
changed/updated at a single location. So building the Debian packages 
(obviously) failed, as everything got installed in /lib. /bin, etc instead of 
/usr/bin, /usr/lib, etc. Patch [11] fixes this issue.


Currently, I am working on making the make-dissector-reg.py script also 
available for out of source builds. On my machine it is already working. I did 
not send the required patches yet, as I am in the process of cleaning up.

Hopefully, I clarified the patches I send for review. If not, please ask and 
I'll try to explain better/in more detail.


While I am at it, there is one thing I would like to ask here: I noticed that 
some tools like idl2wrs, idl2deb and asn2deb are installed in /usr/bin (see 
bedian/wireshark-dev.install). But, the asn2wrs.py script is installed in 
/usr/share/pyshared. This seems inconsistent... Is there any reason for this?
Furthermore, adding these scripts in /usr/bin makes to available as (user) 
terminal commands, which seems odd, as these scripts are not going to be used 
by 'regular' users... So I would propose to put them all to 
/usr/share/pyshared, especially as i am intending to make make-dissector-
reg.py also available, resulting in even more Wireshark development scripts 
getting installed.

Regards,
  Maarten Bezemer 

References:
 1: https://code.wireshark.org/review/5235/
 2: http://www.cmake.org/Wiki/CMake/Tutorials/Packaging
 3: https://code.wireshark.org/review/5252
 4: https://code.wireshark.org/review/5251
 5: https://code.wireshark.org/review/5253
 6: https://code.wireshark.org/review/5254
 7: https://code.wireshark.org/review/5255
 8: https://code.wireshark.org/review/5256
 9: https://code.wireshark.org/review/5232
 10: https://code.wireshark.org/review/5149
 11: https://code.wireshark.org/review/5233