[CMake] FindHDF5.cmake improvement proposal

Antonio Valentino antonio.valentino at tiscali.it
Tue Mar 2 11:53:45 EST 2010


Hi Will,

Il giorno Tue, 02 Mar 2010 09:07:48 -0700
Will Dicharry <wdicharry at stellarscience.com> ha scritto:

> Antonio Valentino wrote:
> > Hi list,
> > pasted below a snippet I use in a project of mine to handle HDF5
> > library.
> > The purpose is to improve detection of required library zlib and
> > szip in cases when the HDF5_C_COMPILER_EXECUTABLE is not available
> > e.g. when one try to use pre-build HDF5 libraries on win32.
> > The snippet also adds an option (WIN32 only) to set defines
> > required by HDF5 dlls. This part could be further automated with
> > some regexp (i suppose).
> > 
> > I'm not a cmake expert so I would like to receive some comment by
> > users more expert than me.
> > If the approach is correct I could try to submit a patch that
> > integrates the snippet in the FindHDF5.cmake module.
> 
> Hi Antonio,
> 
> I'm the maintainer of the FindHDF5 module, and I think your additions 
> would be useful when the wrapper compiler is not found (or if you
> happen to be on Windows, as much of the command line stripping code
> won't work there). I have a couple of questions:
> 
> 1. Someone else should weigh in on this: Is there any problem with 
> calling other find modules from within find modules? I don't think
> there should be a problem, but I've never tried it.

I had the same doubt but, grepping a bit, it seems to be OK to use
find_package inside a find module.

$ grep find_package /usr/share/cmake-2.8/Modules/*.cmake | grep -v '#'
/usr/share/cmake-2.8/Modules/ExternalProject.cmake:    find_package(CVS)
/usr/share/cmake-2.8/Modules/ExternalProject.cmake:
find_package(Subversion) /usr/share/cmake-2.8/Modules/FindBLAS.cmake:
find_package(Threads) /usr/share/cmake-2.8/Modules/FindBLAS.cmake:
find_package(Threads
REQUIRED) /usr/share/cmake-2.8/Modules/FindCUDA.cmake:find_package_handle_standard_args(CUDA
DEFAULT_MSG /usr/share/cmake-2.8/Modules/FindCVS.cmake:find_package_handle_standard_args(CVS
DEFAULT_MSG
CVS_EXECUTABLE) /usr/share/cmake-2.8/Modules/FindHDF5.cmake:find_package_handle_standard_args( HDF5
DEFAULT_MSG /usr/share/cmake-2.8/Modules/FindLAPACK.cmake:
find_package(BLAS) /usr/share/cmake-2.8/Modules/FindLAPACK.cmake:
find_package(BLAS
REQUIRED) /usr/share/cmake-2.8/Modules/FindLAPACK.cmake:
find_package(Threads
REQUIRED) /usr/share/cmake-2.8/Modules/FindMPI.cmake:find_package_handle_standard_args(MPI
DEFAULT_MSG MPI_LIBRARY
MPI_INCLUDE_PATH) /usr/share/cmake-2.8/Modules/FindOpenMP.cmake:find_package_handle_standard_args(OpenMP
DEFAULT_MSG /usr/share/cmake-2.8/Modules/FindOpenSceneGraph.cmake:
"Calling find_package(${_osg_module} ${_osg_required}
${_osg_quiet})") /usr/share/cmake-2.8/Modules/FindOpenSceneGraph.cmake:
find_package(${_osg_module}
${_osg_quiet}) /usr/share/cmake-2.8/Modules/FindPNG.cmake:find_package(ZLIB
${_FIND_ZLIB_ARG}) /usr/share/cmake-2.8/Modules/FindPNG.cmake:find_package_handle_standard_args(PNG
DEFAULT_MSG  PNG_LIBRARY PNG_PNG_INCLUDE_DIR)



> 2. For your SZip portion to work, there would need to be a 
> FindSZip.cmake in system modules directory. Do you have one that you
> can contribute?

Oh, sorry.
I found it on gitorious.org

http://gitorious.org/hdf5/hdf5-v18/blobs/master/Resources/CMake/FindSZIP.cmake

It seems that someone is going to Cmake-ify HDF5 itself.
I suppose the license is the same as HDF5 but I should check.

> 3. At the end of the module, you call include_directories, 
> link_directories, and add_definitions. It is customary to provide
> only variables and let the find module caller decide what to do with
> them. Also, I believe the use of link_directories is deprecated in
> favor of returning full paths to the found libraries. Would you be
> adverse to these changes?

No. I just posted a snippet I use in the CMakeLists.txt of my project.
Of course it requires some fix in order to be included in the
FindHDF5.cmake module.

Anyway I was not aware of the link_directories deprecation.
Il'' fix it as sun as I can.


> For the Windows portion, I'll take any help I can get. I work almost 
> entirely on Unix and Linux systems, so I'm more than happy to have 
> Windows support from someone more experienced than I in that arena.

Well, unfortunately also my development job is mainly on Linux.
In this days I'm performing a port so I'm messing a little bit on
windows too.


> Thanks for your help with this!
> -- Will
> 
> > 
> > 
> > 
> > FIND_PACKAGE(HDF5 COMPONENTS CXX)
> > IF(HDF5_FOUND)
> >  IF(NOT HDF5_C_COMPILER_EXECUTABLE)
> >   # Check if ${HDF5_LIBRARY} requires zlib and/or szlib library
> >   FIND_FILE(H5PUBCONF_H H5pubconf.h ${HDF5_INCLUDE_DIR})
> >   IF(H5PUBCONF_H)
> >    MESSAGE(STATUS "H5PUBCONF_H: ${H5PUBCONF_H}")
> >    FILE(READ ${H5PUBCONF_H} H5CONFIG)
> > 
> >    STRING(REGEX MATCH "\n#define H5_HAVE_ZLIB_H"
> >           HDF5_NEEDS_ZLIB ${H5CONFIG})
> >    STRING(REGEX MATCH "\n#define H5_HAVE_SZLIB_H"
> >           HDF5_NEEDS_SZLIB ${H5CONFIG})
> >   ELSE(H5PUBCONF_H)
> >    MESSAGE(STATUS "No H5PUBCONF_H found.")
> >   ENDIF(H5PUBCONF_H)
> > 
> >   IF(HDF5_NEEDS_ZLIB)
> >    MESSAGE(STATUS "Testing if HDF5 needs zlib -- yes")
> >    FIND_PACKAGE(ZLIB REQUIRED)
> >    SET(HDF5_INCLUDE_DIR ${HDF5_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS})
> >    SET(HDF5_LIBRARIES ${HDF5_LIBRARIES} ${ZLIB_LIBRARIES})
> >   ELSE(HDF5_NEEDS_ZLIB)
> >    MESSAGE(STATUS "Testing if HDF5 needs zlib -- no")
> >   ENDIF(HDF5_NEEDS_ZLIB)
> > 
> >   IF(HDF5_NEEDS_SZLIB)
> >    MESSAGE(STATUS "Testing if HDF5 needs szip lib -- yes")
> >    FIND_PACKAGE(SZIP REQUIRED)
> >    SET(HDF5_INCLUDE_DIR ${HDF5_INCLUDE_DIR} ${SZIP_INCLUDE_DIRS})
> >    SET(HDF5_LIBRARIES ${HDF5_LIBRARIES} ${SZIP_LIBRARIES})
> >   ELSE(HDF5_NEEDS_SZLIB) 
> >    MESSAGE(STATUS "Testing if HDF5 needs szip lib -- no")
> >   ENDIF(HDF5_NEEDS_SZLIB)
> > 
> >   IF(WIN32)
> >    OPTION(HDF5_USE_DLL "Enable pre-processor macros for HDF5 DLLs."
> >           OFF)
> >    IF(HDF5_USE_DLL)
> >     ADD_DEFINITIONS(-D_HDF5USEDLL_
> >                     -DHDF5CPP_USEDLL
> >                     -D_HDF5USEHLDLL_
> >                     -DHDF5USE_HLCPPDLL)
> >    ENDIF(HDF5_USE_DLL)
> >   ENDIF(WIN32)
> >  ENDIF(NOT HDF5_C_COMPILER_EXECUTABLE)
> > 
> >  INCLUDE_DIRECTORIES(${HDF5_INCLUDE_DIR})
> >  LINK_DIRECTORIES(${HDF5_LIBRARY_DIRS})
> >  ADD_DEFINITIONS(-DHAVE_HDF5)
> > ENDIF(HDF5_FOUND)


ciao


-- 
Antonio Valentino


More information about the CMake mailing list