[CMake] including generated cmake-files from a ExternalPackage

jens persson jens at persson.cx
Wed Nov 25 08:17:31 EST 2009


Hello,

I have a problem relating to ExterlalPackage

I have to project (main and lib in this example) that is placed in two
directories next to each other where main needs lib to be able to
link.  I have created a set up so that the main procject uses
ExternalProject to compile lib. This works flawless but since lib is
cmake based I have a export command that creates a include file that I
want to use when configuring main, but since that is not created until
build time I have problems with using it in main/CMakeLists.txt. A
workaround I have used is distributing a empty include file so that
the configure steps goes through but the linking of main fails on the
first run of make, on the second cmake notices that the include file
is updated and reconfigures.


Anyone have any sugestions about how to solve this?

Side note, I don't know if it complicates things but the builds have
to be runnable in tree (no install step).


Thanks in advance
/jp


Example files below:
main/CMakeLists.txt

INCLUDE(ExternalProject)
INCLUDE(../lib/module_toc.cmake)

add_executable(tester
        main.c
)

target_link_libraries(tester
        mylib)

ExternalProject_Add(mylib_a
        DOWNLOAD_COMMAND ""
        SOURCE_DIR ../lib
        CONFIGURE_COMMAND ${CMAKE_COMMAND} .
        BUILD_IN_SOURCE 1
        INSTALL_COMMAND ""


lib/CMakeLists.txt:
PROJECT (lib)
CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
CMAKE_POLICY (VERSION 2.6)

add_library(mylib
        bar.c
        foo.c
)

export(
        TARGETS mylib
        FILE module_toc.cmake
        )


-- 
jens persson
<jens at persson.cx>
Mäster Olofsväg 24
S-224 66 LUND;SWEDEN


More information about the CMake mailing list