Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-dev: Re: [Wireshark-dev] CMake for Windows

From: Graham Bloice <graham.bloice@xxxxxxxxxxxxx>
Date: Wed, 26 Jun 2013 11:29:38 +0100
On 26 June 2013 11:07, Roland Knall <rknall@xxxxxxxxx> wrote:
Hi

GLOB and GLOB_RECURSE should normally only catch files, not
directories. (As noted on
http://www.cmake.org/cmake/help/v2.8.11/cmake.html#command:file)


Several references found on Google imply that it did return directories as well despite the docs.  My empirical testing seems to show that it doesn't.
 
You should look for ares.h. From the returned path you could deduct
the directory path with STRING.

I'll try this next. 

Alternativly you could look on google for Findcares.cmake, which will
get you some matches for other people, who attempted the same thing.
>From there you can either take their hints or create your own version.


I'm hacking in the  Wireshark copy of that file and all the ones I find on Google are similar.  None of them cater for Windows oddities.

More problematic is finding the library. But you could either use the
built-in function find_library or use the cmake module
FindPackageHandleStandardArgs.cmake (Description in the header of the
file).


Again, it appears that there is nothing in standard CMake to handle the Windows oddities.  There is an existing bug/enhancement for CMake to add VPATHS to find_path et al to cater for the version in the path but it hasn't been progressed since 2010.

My plan was to work out the path under $(PROJECT_LIB_DIR ) for each library and supply that as HINTS to find_path and find_library.

I believe there's another issue as well, on Windows the linker requires access to the import library for linking (e.g. $(PROJECT_LIB_DIR)/c-ares-1.9.1-1-win32ws/lib/libcares-2.lib) and then the dll should be copied to the output directory to load at run-time ($(PROJECT_LIB_DIR)/c-ares-1.9.1-1-win32ws/lib/libcares-2.dll).

I haven't worked out how CMake handles the import library yet.

Allways try to use as many built-in commands as possible, because even
something simple as a little foreach and some paths you set may lead
to cross-compilation mayhem in the future.

I think all the Windows oddities will have to be wrapped in IF(WIN32) or similar to prevent other breaking CMake on other platforms. 


kind regards,
Roland

On Wed, Jun 26, 2013 at 11:35 AM, Graham Bloice
<graham.bloice@xxxxxxxxxxxxx> wrote:
>
> On 26 June 2013 10:10, Roland Knall <rknall@xxxxxxxxx> wrote:
>>
>> Hi
>>
>> As I am somewhat converse in cmake, I can give you a few pointers, if you
>> like.
>>
>> In general for each package a cmake system should look for, a
>> Find<PackageName>.cmake file should exist in either one of two places:
>>
>> - The local directory (in wireshark underneath
>> <src>/cmake/modules/Find....
>> - Or the global cmake directory <cmake_install_dir>/Modules/Find...
>>
>> Those packages usually comply to a definition, where you can provide a
>> searchpath by setting a directory before including the package.
>>
>> So if you have a CMakeLists.txt with the following context:
>>
>>
>> ........
>> INCLUDE(Findzlib)
>> IF(ZLIB_FOUND)
>>
>>    ...
>>
>> ENDIF(ZLIB_FOUND)
>> ....
>>
>>
>> then you can set a search path by using:
>>
>> ...
>> IF(WIN32)
>>     SET(ZLIB_INCLUDE_DIRS "c:\\wireshark-win32-libs\\zlib125\\include")
>>     SET(ZLIB_LIBRARY_DIRS "c:\\wireshark-win32-libs\\zlib125\\bin"
>> "c:\\wireshark-win32-libs\\zlib125\\lib" )
>> ENDIF(WIN32)
>> INCLUDE(Findzlib)
>> ....
>>
>> But setting static routes should be avoided, so better set a relative
>> path (aka ${PROJECT_BINARY_DIR}/../..) or
>> using a system variable.
>>
>> If you have to call a script, you should do this by using either
>> EXECUTE_PROCESS or better create a CUSTOM_TARGET which you can depend
>> on, so that the right libraries will allways be downloaded, if they
>> cannot be found.
>>
>> Finally, if you include user-editable scripts, they should start with
>> CMake...... and end in .txt. Something like config.CMake should be
>> avoided, as it is nmake specific.
>>
>> kind regards,
>> Roland
>>
>
> I've been attempting that sort of thing but success eludes me.
>
> Take cares for instance.  The path to the include dir is
> $(PROJECT_LIB_DIR)/c-ares-1.9.1.1-win32ws/include.
>
> I don't want to hard-code the library version suffix so I'd like to get
> CMake to search within $(PROJECT_LIB_DIR) for a directory that begins
> "c-ares-".
>
> My current attempt is (with hard-coded paths and debugging messages):
>
> IF (WIN32)
>   MESSAGE("Searching wireshark libs for c-ares")
>   FILE(GLOB subdir "W:/Wireshark/wireshark-win32-libs/*")
>   FOREACH(dir $(subdir))
>     MESSAGE("Found: $(dir)")
>     IF(IS_DIRECTORY $(dir))
>       MESSAGE("Found: $(dir)")
>       IF("$(dir)" MATCHES "^c-ares-.*")
>         SET(CARES_HINTS $(dir))
>       ENDIF()
>     ENDIF()
>   ENDFOREACH()
> ENDIF(WIN32)
>
> This fails to find any subdirectories at all.  I've also tried GLOB_RECURSE
> with no change.
>
> Graham
>
> ___________________________________________________________________________
> Sent via:    Wireshark-dev mailing list <wireshark-dev@xxxxxxxxxxxxx>
> Archives:    http://www.wireshark.org/lists/wireshark-dev
> Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
>              mailto:wireshark-dev-request@xxxxxxxxxxxxx?subject=unsubscribe
___________________________________________________________________________
Sent via:    Wireshark-dev mailing list <wireshark-dev@xxxxxxxxxxxxx>
Archives:    http://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
             mailto:wireshark-dev-request@xxxxxxxxxxxxx?subject=unsubscribe