[CMake] [New Module] FindHDF5.cmake

Will Dicharry wdicharry at stellarscience.com
Fri Jul 10 13:27:09 EDT 2009


Michael Jackson wrote:
> reponses in line..

My responses are inline too.  I'm snipping some of the front matter for 
brevity.

>
>
> On Jul 10, 2009, at 12:33 PM, Will Dicharry wrote:
>
>> Michael Jackson wrote:
>>>
>>> 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.

The wrapper compiler directly references the specific library files for 
HDF5.  I guess I could look at the extension in a platform dependent way 
and decide from that.  Do you see any problems with that particular 
approach?  I think h5cc -showconfig may print that information as well, 
I'll look into doing it that way too.

>
>>
>>>
>>> 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

Yes, I'll definitely need to add the build configuration differences.

>
>  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.

My "No" wasn't "No I won't do it", it was "No, it doesn't currently do 
it".  You present a good argument, consider my opinion changed.  I'll 
add environment variable support.

>
>
>>
>>> 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.

I regularly test on Linux and a number of HPC platforms that include 
Cray, IBM/AIX, and various Linux clusters.  I don't regularly run on 
Windows and OSX, but I may be able to get access to machines for testing 
there too.  In the future, I'll probably need it to work on all of 
these, so I'll be working at keeping all of the platforms going.

Thanks for the suggestions and sorry for the confusion about the 
environment variables.

--Will
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3344 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090710/eb2c31da/attachment.bin>


More information about the CMake mailing list