[Insight-developers] passing include dirs and libs list through
Alexandre GOUAILLARD
agouaillard at gmail.com
Mon May 16 13:59:23 EDT 2011
great !
it's 2am here, so I ll test that tomorrow on my win XP machine (even
if it s national hollyday - vesak day).
thanks again brad, that s really helpfull.
alex.
On Mon, May 16, 2011 at 11:52 PM, Brad King <brad.king at kitware.com> wrote:
> On 05/14/2011 07:31 AM, Alexandre GOUAILLARD wrote:
>> then, in ITK, In the case of GDCM, this is not happening, and the
>> list of librairies are hardcoded in
>> Modules/ThirdParty/GDCM/CMakeList.txt
>> Can you confirm that we are suppose to copy over the list to
>> ITK-GDCM_LIBRARIES and that some cmake magic will take care of using
>> those when needed?
>
> It's not a copy. It is a list of the libraries that ITK-GDCM intends
> to provide whether from the system or from its own source tree. Every
> module that provides libraries sets that list explicitly to the libraries
> it provides.
>
>> that, and that we should use the "GDCM_LIBRARY_DIRS" for that.
> [snip]
>> If I look in other third party module ... they do not seem to use it
>
> The ITK-VNL module in The Modules/ThirdParty/VNL/CMakeLists.txt does.
> In Modules/ThirdParty/GDCM/CMakeLists.txt add:
>
> set(ITK-GDCM_LIBRARIES gdcmDICT gdcmMSFF )
> + set(ITK-GDCM_SYSTEM_LIBRARY_DIRS "${GDCM_LIBRARY_DIRS}")
> set(ITK-GDCM_NO_SRC 1)
>
> to propagate library directories from the system. Of course since
> GDCMConfig does not provide GDCM_LIBRARY_DIRS this won't actually
> help. However, GDCM exports its targets in GDCMTargets.cmake and
> loads them from GDCMConfig so you shouldn't ever need link dirs
> at all. See below.
>
>> What am I missing here?
>
> Nothing. This is due to an oversight in our design for modules that
> can switch between building a library or finding it on the system :(
> The design does not account for third-party packages on the system
> that actually provide a targets file like GDCM does.
>
> What GDCM intends to happen is that the dependent package runs
> find_package(GDCM) which loads GDCMConfig.cmake which then loads
> GDCMTargets.cmake to import the GDCM library targets as logical
> names:
>
> http://www.cmake.org/Wiki/CMake/Tutorials/Exporting_and_Importing_Targets
>
> Even though GDCM is providing the right stuff ITK is not using it
> correctly. The problem is that imported targets have scope only in
> the directory where they are imported, and below. Therefore in
> ITK the GDCM logical target names are meaningful only in the
> Modules/ThirdParty/GDCM directory and below. When the string names
> are passed to other directories through ITK-GDCM_LIBRARIES and used
> in target_link_libraries calls, CMake has no idea that the names are
> supposed to be interpreted as imported targets. Therefore it just
> passes them with -l options.
>
> The patch below works around this problem by creating a normal
> library target "ITK-GDCM" that links to the imported libraries in
> a scope where they are available. When other directories reference
> ${ITK-GDCM_LIBRARIES} they will get just ITK-GDCM which is a real
> target. CMake follows the transitive dependencies of it correctly
> in the proper scope and links the real gdcm libraries.
>
> -Brad
>
>
> diff --git a/Modules/ThirdParty/GDCM/CMakeLists.txt b/Modules/ThirdParty/GDCM/CMakeLists.txt
> index 2c68408..004f530 100644
> --- a/Modules/ThirdParty/GDCM/CMakeLists.txt
> +++ b/Modules/ThirdParty/GDCM/CMakeLists.txt
> @@ -9,8 +9,7 @@ if(ITK_USE_SYSTEM_GDCM)
> set(ITK-GDCM_SYSTEM_INCLUDE_DIRS
> ${GDCM_INCLUDE_DIRS}
> )
> - set(ITK-GDCM_LIBRARIES gdcmDICT gdcmMSFF )
> - set(ITK-GDCM_NO_SRC 1)
> + set(ITK-GDCM_LIBRARIES ITK-GDCM)
> else()
> set(ITK-GDCM_INCLUDE_DIRS
> ${ITK-GDCM_BINARY_DIR}
> diff --git a/Modules/ThirdParty/GDCM/src/CMakeLists.txt b/Modules/ThirdParty/GDCM/src/CMakeLists.txt
> index 2eec2dc..9170bb0 100644
> --- a/Modules/ThirdParty/GDCM/src/CMakeLists.txt
> +++ b/Modules/ThirdParty/GDCM/src/CMakeLists.txt
> @@ -1,3 +1,10 @@
> +if(ITK_USE_SYSTEM_GDCM)
> + add_library(ITK-GDCM ITK-GDCM.cxx)
> + target_link_libraries(ITK-GDCM gdcmDICT gdcmMSFF)
> + itk_module_target(ITK-GDCM)
> + return()
> +endif()
> +
> set(GDCM_TARGETS_NAME ${ITK-GDCM-targets})
> set(GDCM_INSTALL_BIN_DIR ${ITK-GDCM_INSTALL_RUNTIME_DIR})
> set(GDCM_INSTALL_LIB_DIR ${ITK-GDCM_INSTALL_LIBRARY_DIR})
> diff --git a/Modules/ThirdParty/GDCM/src/ITK-GDCM.cxx b/Modules/ThirdParty/GDCM/src/ITK-GDCM.cxx
> new file mode 100644
> index 0000000..286c861
> --- /dev/null
> +++ b/Modules/ThirdParty/GDCM/src/ITK-GDCM.cxx
> @@ -0,0 +1 @@
> +int ITK_GDCM(void) { return 0; }
>
More information about the Insight-developers
mailing list