[cmake-developers] Topic hdf5-module-bug-fix
Brad King
brad.king at kitware.com
Tue May 24 15:28:15 EDT 2011
On 05/24/2011 03:04 PM, Will Dicharry wrote:
> Brad King wrote:
>> Therefore if someone finds HDF5 twice the second time may take the wrong
>> logic path. The proper value to test after the find_package call is
>> HDF5_FOUND to know whether or not the config file was found and loaded.
>
> Won't this have the same problem? HDF5_FOUND gets set by
> FindPackageHandleStandardArgs, so the second time find_package(HDF5)
> gets called on a system with the autoconf HDF5 build we'll take the
> wrong control path and call get_target_properties on targets that don't
> exist.
Yes, you're right.
> That's why I used the INCLUDE_DIR in the first place (forgetting
> about the backwards compatibility thing at the end). Is there something
> else I can branch on?
The find_package command will set HDF5_DIR to the directory containing
the config file. However, there is a different organization we can use.
The general form should be something like
if(NOT HDF5_FOUND)
find_package(HDF5 QUIET NO_MODULE)
if(HDF5_FOUND)
# ... map hdf5-config values to our outputs
endif()
endif()
if(NOT HDF5_FOUND)
# old-style search
endif()
if(HDF5_FOUND)
# Generic logic (if any) when HDF5 is found by either method.
# Logic should be safe to run twice or have its own guard.
endif()
By including the "NOT HDF5_FOUND" guard around each block then it does
not matter how many times the module is included.
-Brad
More information about the cmake-developers
mailing list