[cmake-developers] Should sucessive calls to find_package for one package succeed?
Hi, Should successive calls to find_package succeed in general? Eg find_package(Grantlee COMPONENTS Templates) find_package(Grantlee COMPONENTS TextDocument) ? Currently if the target package uses Config files and install(TARGETS ... EXPORT) the convention is to use include(${CMAKE_CURRENT_LIST_DIR}/GrantleeTargets.cmake) in the config file. The problem is that that Targets file uses an unguarded ADD_LIBRARY(grantlee_templates SHARED IMPORTED) which cmake errors on: add_library cannot create imported target "grantlee_templates" because another target with the same name already exists. The fix appears to be to wrap the call to add_library: if (NOT TARGET grantlee_templates) ADD_LIBRARY(grantlee_templates SHARED IMPORTED) endif() I can fix this if it is a bug. Thanks, Steve. -- Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers
Re: [cmake-developers] Should sucessive calls to find_package for one package succeed?
On 11/6/2011 7:00 PM, Stephen Kelly wrote: include(${CMAKE_CURRENT_LIST_DIR}/GrantleeTargets.cmake) It is up to the author of the config file to block this correctly against multiple inclusion, e.g. if(NOT Grantlee_TARGETS_INCLUDED) set(Grantlee_TARGETS_INCLUDED 1) include(${CMAKE_CURRENT_LIST_DIR}/GrantleeTargets.cmake) endif() if (NOT TARGET grantlee_templates) ADD_LIBRARY(grantlee_templates SHARED IMPORTED) endif() This would hide cases of accidentally conflicting target names. -Brad -- Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers
Re: [cmake-developers] Should sucessive calls to find_package for one package succeed?
Brad King wrote: > On 11/6/2011 7:00 PM, Stephen Kelly wrote: >> include(${CMAKE_CURRENT_LIST_DIR}/GrantleeTargets.cmake) > > It is up to the author of the config file to block this correctly > against multiple inclusion, e.g. > > if(NOT Grantlee_TARGETS_INCLUDED) > set(Grantlee_TARGETS_INCLUDED 1) > include(${CMAKE_CURRENT_LIST_DIR}/GrantleeTargets.cmake) > endif() Ok, thanks. Seems like an important thing to document. Is there any page showing how to use config files and targets files? I only found out how to use them by talking to Alex :). > >> if (NOT TARGET grantlee_templates) >>ADD_LIBRARY(grantlee_templates SHARED IMPORTED) >> endif() > > This would hide cases of accidentally conflicting target names. > I don't understand. You mean if someone called install(EXPORTS) with the wrong target? Thanks, Steve. -- Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers
Re: [cmake-developers] Should sucessive calls to find_package for one package succeed?
On 11/7/2011 10:18 AM, Stephen Kelly wrote: Ok, thanks. Seems like an important thing to document. Is there any page showing how to use config files and targets files? http://www.cmake.org/Wiki/CMake/Tutorials#CMake_Packages This section: http://www.cmake.org/Wiki/CMake/Tutorials/Packaging#Packaging_and_Exporting could be updated with that suggestion. if (NOT TARGET grantlee_templates) ADD_LIBRARY(grantlee_templates SHARED IMPORTED) endif() This would hide cases of accidentally conflicting target names. I don't understand. If an application defines a target named "foo" as part of its own build and then uses find_package to load a dependency that also defines "foo" then a target-wise blocker like the above will silently skip the imported target. Then the imported dependency won't link correctly because it will use the application's foo instead of the package's foo. We need to allow the add_library command to complain about an existing target. -Brad -- Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers