[CMake] how to build a target after installing dependencies?

Michael Hertling mhertling at online.de
Mon May 2 20:15:46 EDT 2011


On 05/02/2011 07:05 PM, hurcan solter wrote:
> Hi all
> 
>   I have a project that depends on some contrib libraries (SDL png etc..).
> If I can't find the dependencies through FindXXX macros
> I build them myself (wrote CMakeLists for dependencies) and link to the
> project, also setting the include directories(SDL_INCLUDE_DIR in spirit
> of FindXXX macros again).
> 
>    The problem is, for example; SDL header files resides in the directory
> SDL/include/filename.h but the project expects them to be in
>   SDL/filename.h as if SDL is installed already.The original makefile deals
> with this calling make install on the dependencies beforehand
>   then includes them from installation directory. I am guessing this is not
> possible with CMake during configuration phase because the makefiles are not
> generated
>   yet(There is also a MSVC dimension to consider ). I can place the
> libraries the way I want via ARCHIVE_OUTPUT_DIRECTORY but have no idea
>  how to do that with header files. This seems like a common problem but I am
> stumped at the moment
> 
>  Any pointers would be greatly appreciated.

Possibly, you can apply the super-build approach to your problem:
Configure the contributed libraries *and* your actual project as
external projects of a super project and establish a dependency
of your project on the contributed libraries, cf. [1]:

# Super Project's CMakeLists.txt:
ExternalProject_Add(SDL ...)
ExternalProject_Add(png ...)
...
ExternalProject_Add(ActualProject DEPENDS SDL png ...)

In this manner, the contributed libraries will be completely built and
installed when your actual project is configured, so the latter will
find the formers as they are expected.

However, you probably don't want to install the contributed libraries
to their final locations during the super project's build phase, e.g.
due to the premature necessity of root privileges. Instead, you might
do an intermediate installation at, say, ${CMAKE_BINARY_DIR}/externals
with the super project's CMAKE_BINARY_DIR and set CMAKE_PREFIX_PATH or
the like for your actual project accordingly to have FIND_PACKAGE() et
al. succeed. In the end, you either rebuild/reinstall the contributed
libraries to the final installation directory or try to just relocate
them. In the latter case, be aware of the possibility that they have
incorporated the configured installation prefix in their object code,
so a simple copy operation might not be sufficient; see [2] for a
discussion of this issue.

'hope that helps.

Regards,

Michael

[1] http://www.mail-archive.com/cmake@cmake.org/msg35800.html
[2] http://www.mail-archive.com/cmake@cmake.org/msg35892.html


More information about the CMake mailing list