[Cmake] FIND_PACKAGE()

Brad King brad . king at kitware . com
Fri, 14 Nov 2003 17:33:06 -0500 (EST)


On Fri, 14 Nov 2003, Mathieu Malaterre wrote:

> I would like to be able to find lib in my binary dir, and also that it
> works with CMake. Thus I wrote a CMakeLists.txt in the top dir of gdcm,
> which put every lib in gdcm-bin/lib and put includes in
> gdcm-bin/include, but on windows I must be carefull with Debug vs. Release.
>
> So my question is how can I use ${INTDIR} or ${CMAKE_CFG_INTDIR} in my
> FindGdcm.make file. So that at compile time, my third party code pick
> the right lib (debug/release).

You should setup Gdcm to have a GcdmConfig.cmake file in the top of its
build tree.  It should contain an entry like GDCM_LIBRARY_DIRS that lists
the directories (without debug/release suffix) in which the libraries were
placed during the build.  Then the outside project looks like this:

FIND_PACKAGE(Gdcm)
LINK_DIRECTORIES(${GDCM_LIBRARY_DIRS})

ADD_EXECUTABLE(myexe myexe.cxx)
TARGET_LINK_LIBRARIES(myexe ${GDCM_LIBRARIES})

When it is built in Visual Studio under a particular configuration, say
Debug, it will use the Gdcm libraries from the Debug directory in the Gdcm
build tree.  If the outside project is built under a configuration for
which Gdcm was not built, you will get link errors because it will not be
able to find the libraries.

You may effectively ignore the existence of the configuration
Debug/Release/etc directories when creating GdcmConfig.cmake.

-Brad