[CMake] [New Module] FindHDF5.cmake

Michael Jackson mike.jackson at bluequartz.net
Fri Jul 10 13:01:58 EDT 2009


reponses in line..


On Jul 10, 2009, at 12:33 PM, Will Dicharry wrote:

> Michael Jackson wrote:
>>
>>
>> On Jul 10, 2009, at 11:13 AM, Brad King wrote:
>>
>>> Will Dicharry wrote:
>>>> Mike Jackson wrote:
>>>>> Can you post your module or attach it to a bug/feature request?  
>>>>> I also
>>>>> have a FindHDF5 module and I would like to compare the two.
>>>>
>>>> Sorry about that, I meant to attach the module to the first  
>>>> email.  It
>>>> is attached to this one.
>>>
>>> After you two have combined your versions and reached consensus,
>>> please post again and Cc me.  Then I'll send instructions to get
>>> CVS commit access.  I see no reason not to have co-maintainers
>>> for a module.
>>>
>>> Thanks,
>>> -Brad
>>
>> I'll let Will be the maintainer. My module ends up being a bit more  
>> specific to my own version of HDF5, ie, I am just looking for the  
>> libraries (c, c++, and High Level) but not really looking for the  
>> HDF5 compiler scripts.
>>
>> Couple of observations about the module:
>>
>> Does it find the HDF5 C++ library?
>
> No, but I'll add that in by invoking the HDF5 C++ wrapper compiler  
> and searching the output.

Great.
>
>>
>> Can it figure out if the HDF5 library is a static or dynamic  
>> library? (I configure a header file that has that information  
>> inside it which can then be tested for).
>
> No, I'll look into how to determine that.  Suggestions welcome.

Well, I don't think there is an easy way to do it besides looking at  
the fully name of the library file, but even then that can give you  
bad results. In my CMake build system for HDF5 I add a few more  
#define elements into the H5Config.h file that has the necessary parts  
to be able to determine how HDF5 was compiled- static or dynamic.

>
>>
>> Is it properly finding dependent libraries when needed, like szip  
>> or zip ( I don't as I do NOT compile HDF5 with that support)?
>
> Yes, I need it to work across a number of platforms, many of which  
> do compile in szip support.  I search for all libraries linked by  
> the wrapper compiler and add them to the HDF5_LIBRARIES list.

You may also want to include variables such as HDF5_SZIP_LIBRARY and  
HDF5_ZIP_LIBRARY. You also might want to include some CMake code to  
generate the following variables:

HDF5_LIBRARY_DEBUG
HDF5_LIBRARY_RELEASE
HDF5_LIBRARY

  For each library found. I think the normal hdf5 distribution will  
append a 'd' to the name of the hdf5 library when built in Debug mode.  
My own build system uses '_d' on windows and _debug on gcc. The  
necessary cmake code will "do the right thing" if one of the libraries  
are not found.

############################################
#
# Check the existence of the libraries.
#
############################################
# This macro was taken directly from the FindQt4.cmake file that is  
included
# with the CMake distribution. This is NOT my work. All work was done  
by the
# original authors of the FindQt4.cmake file. Only minor modifications  
were
# made to remove references to Qt and make this file more generally  
applicable
#########################################################################

MACRO (_MXA_ADJUST_LIB_VARS basename)
   IF (${basename}_INCLUDE_DIR)

   # if only the release version was found, set the debug variable  
also to the release version
   IF (${basename}_LIBRARY_RELEASE AND NOT ${basename}_LIBRARY_DEBUG)
     SET(${basename}_LIBRARY_DEBUG ${${basename}_LIBRARY_RELEASE})
     SET(${basename}_LIBRARY       ${${basename}_LIBRARY_RELEASE})
     SET(${basename}_LIBRARIES     ${${basename}_LIBRARY_RELEASE})
   ENDIF (${basename}_LIBRARY_RELEASE AND NOT ${basename}_LIBRARY_DEBUG)

   # if only the debug version was found, set the release variable  
also to the debug version
   IF (${basename}_LIBRARY_DEBUG AND NOT ${basename}_LIBRARY_RELEASE)
     SET(${basename}_LIBRARY_RELEASE ${${basename}_LIBRARY_DEBUG})
     SET(${basename}_LIBRARY         ${${basename}_LIBRARY_DEBUG})
     SET(${basename}_LIBRARIES       ${${basename}_LIBRARY_DEBUG})
   ENDIF (${basename}_LIBRARY_DEBUG AND NOT ${basename}_LIBRARY_RELEASE)
   IF (${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE)
     # if the generator supports configuration types then set
     # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a  
value
     IF (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
       SET(${basename}_LIBRARY       optimized ${$ 
{basename}_LIBRARY_RELEASE} debug ${${basename}_LIBRARY_DEBUG})
     ELSE(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
       # if there are no configuration types and CMAKE_BUILD_TYPE has  
no value
       # then just use the release libraries
       SET(${basename}_LIBRARY       ${${basename}_LIBRARY_RELEASE} )
     ENDIF(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
     SET(${basename}_LIBRARIES       optimized ${$ 
{basename}_LIBRARY_RELEASE} debug ${${basename}_LIBRARY_DEBUG})
   ENDIF (${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE)

   SET(${basename}_LIBRARY ${${basename}_LIBRARY} CACHE FILEPATH "The $ 
{basename} library")

   IF (${basename}_LIBRARY)
     SET(${basename}_FOUND 1)
   ENDIF (${basename}_LIBRARY)

ENDIF (${basename}_INCLUDE_DIR )

   # Make variables changeble to the advanced user
   MARK_AS_ADVANCED(${basename}_LIBRARY ${basename}_LIBRARY_RELEASE $ 
{basename}_LIBRARY_DEBUG ${basename}_INCLUDE_DIR )
ENDMACRO (_MXA_ADJUST_LIB_VARS)


>
>> Make use of some sort of environment variable as a possible  
>> solution to finding the root of where HDF5 is installed, I  
>> personally use the environment variable "HDF5_INSTALL" for use in  
>> my script.
>
> No.  I'd personally prefer to rely on setting something similar in  
> the cache rather than using an environment variable, but I'm open to  
> changing my opinion.

Yes. Simply because if you gather 20 people who compile HDF5 you will  
probably get some, if not all, who decide they want HDF5 installed  
somewhere else: /opt, /sw, /usr, /usr/local, /Users/$HOME/.. , /Users/ 
Shared/Toolkits, /Users/Shared/OpenSource, C:/hdf5, C:/Developer/GCC,  
C:/Program Files/hdf5 (replace the drive letter with any other drive  
letter on windows).

  Having to run cmake and cmake not being able to find HDF5 EVERY TIME  
is a PITA. I used to have to deal with this. A simple environment  
variable solves this problem. If you want a concrete case, just look  
at Boost. Used by lots of people, installed everywhere imaginable.  
Even _with_ setting Boost_ROOT CMake _still_ sometimes has problems  
finding boost (Of course the crazy library naming doesn't help). Qt -  
Same thing: Either provide QtDir or the qmake executable. Ignoring the  
use of an environment variable is ignoring a dead easy way to help  
your users use CMake effectively. So.. Yes.


>
>> I imagine what I _should_ be doing is creating a HDF5Config.cmake  
>> file and UseHDF5.cmake file for my own HDF5 distribution (which is  
>> based on HDF5 version 1.6.9 and uses CMake as its build system).
>>
>> Just my comments. If you want to see what I've come up with let me  
>> know. My git repo is public:
>>
>> http://www.bluequartz.net/cgi-bin/gitweb/gitweb.cgi?p=MXADataModel.git;a=blob_plain;f=Resources/CMake/MXAFindHDF5.cmake;hb=HEAD
>>
>
> I'll take a look so I can try to make the module as useful as  
> possible.  Thanks for the suggestions!
>
> --Will
>
>> _________________________________________________________
>> Mike Jackson                  mike.jackson at bluequartz.net
>> BlueQuartz Software                    www.bluequartz.net
>> Principal Software Engineer                  Dayton, Ohio

I know my system works great on OS X, Windows, and Linux when built as  
a serial library. What I _don't_ know is how well it works every where  
else (BSD, Clusters, Solaris, AIX, Crays) which is why I never tried  
to submit it as a module.

Mike



More information about the CMake mailing list