[CMake] ${PROJECT}-config.cmake

Biddiscombe, John A. biddisco at cscs.ch
Mon Jun 7 11:24:58 EDT 2010


When using the install target command as follows

  INSTALL (
      TARGETS
          ${HDF5_LIB_TARGET}
      EXPORT
          ${HDF5_EXPORTED_TARGETS}
      LIBRARY DESTINATION lib COMPONENT libraries
      ARCHIVE DESTINATION lib COMPONENT libraries
      RUNTIME DESTINATION bin COMPONENT libraries
  )

cmake very nicely generates an HDF5-config.cmake file in the build directory, and at install time, in the install directory. This is great.

However, I have project A(paraview) with two subdirectories B (hdf5) and C (mystuff), where C "uses" B. All is well except that if C includes the hdf5-config.cmake from the Build directory as generated by B (ADD_LIBRARY(vtkhdf5 SHARED IMPORTED)) , cmake produces error messages along the lines of

CMake Error at D:/cmakebuild/pv-shared/Utilities/hdf5-1.8/HDF5-config.cmake:16 (ADD_LIBRARY):
add_library cannot create imported target "vtkhdf5" because another target
with the same name already exists.

Naturally, when building C standalone using the install directory of standalone B, all works fine.

Everything would be simple, if cmake would simply skip the imported target from B the second time it is loaded when called from the subproject C, then a single set of config and cmakelists would work all the time, but as it is, extra logic needs to be added.

Is there any easy way of telling project C, load the config file if B is not part of the same build so that I can reuse the same syntax between separate build or common builds. I'd like to use the generated hdf5-config.cmake files because they have all the necessary properties set correctly (like when target name is not the same as lib name etc etc, which makes things harder like below).

# Import target "vtkhdf5" for configuration "Debug"
SET_PROPERTY(TARGET vtkhdf5 APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
SET_TARGET_PROPERTIES(vtkhdf5 PROPERTIES
  IMPORTED_IMPLIB_DEBUG "D:/cmakebuild/pv-shared/bin/Debug/vtkhdf5ddll.lib"
  IMPORTED_LINK_INTERFACE_LIBRARIES_DEBUG "ws2_32;wsock32;C:/Program Files/MPICH2/lib/mpi.lib;vtkzlib"
  IMPORTED_LOCATION_DEBUG "D:/cmakebuild/pv-shared/bin/Debug/vtkhdf5ddll.dll"
  )

Thanks

JB


--
John Biddiscombe,                            email:biddisco @ cscs.ch
http://www.cscs.ch/
CSCS, Swiss National Supercomputing Centre  | Tel:  +41 (91) 610.82.07
Via Cantonale, 6928 Manno, Switzerland      | Fax:  +41 (91) 610.82.82

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100607/a127b082/attachment.htm>


More information about the CMake mailing list