[CMake] FindHDF5.cmake improvement proposal
Will Dicharry
wdicharry at stellarscience.com
Tue Mar 2 11:07:48 EST 2010
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.
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?
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?
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.
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)
>
>
>
> best regards
>
--
Will Dicharry
Software Developer
Stellar Science Ltd Co
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5154 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100302/e9438b5b/attachment-0001.bin>
More information about the CMake
mailing list