[CMake] ${PROJECT}-config.cmake

Michael Hertling mhertling at online.de
Tue Jun 8 17:56:15 EDT 2010


On 06/07/2010 08:54 PM, Biddiscombe, John A. wrote:
> Seems that just doing
> 
> IF (NOT ${PROJECTXXX_SOURCE_DIR})
>  include config file
> ENDIF
> 
> is enough and works ok. If the project is part of the same build, the source dir is defined, otherwise not.

To me, this seems not to be bulletproof: Even if you're outside that
particular project the superordinate environment could define such a
variable for a completely unrelated purpose, so the file surprisingly
wouldn't be included. Here, IMO, "IF(NOT TARGET ...)" is more reliable.

Regards,

Michael

>> -----Original Message-----
>> From: cmake-bounces at cmake.org [mailto:cmake-bounces at cmake.org] On Behalf Of
>> Biddiscombe, John A.
>> Sent: 07 June 2010 17:25
>> To: cmake at cmake.org
>> Subject: [CMake] ${PROJECT}-config.cmake
>>
>> 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/ <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
>>
>>



More information about the CMake mailing list