[CMake] How to integrate 3rd-party software into cmake system

Clark J. Wang dearvoid at gmail.com
Sat Jun 9 02:00:34 EDT 2007


For example, I have a project `test' which needs a 3rd-party software
`hello'. The directory structure looks like this:

test/test.c
test/CMakeLists.txt
test/build  <-- I run cmake in this directory
test/hello/hello.c
test/hello/main.c
test/hello/Makefile

hello's Makefile will create a lib `test/hello/libhello.so' and an exe
`test/hello/hello'. `test/test.c' depends on `libhello.so' to compile.
I write a CMakeLists.txt like this but it does not work:

### BEGIN ###

PROJECT(test)

SET(CMAKE_VERBOSE_MAKEFILE ON)

SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

LINK_DIRECTORIES(${LIBRARY_OUTPUT_PATH})

SET(hellodir ${PROJECT_SOURCE_DIR}/hello)
SET(hellolib ${LIBRARY_OUTPUT_PATH}/libhello.so)
SET(helloexe ${EXECUTABLE_OUTPUT_PATH}/hello)
ADD_CUSTOM_COMMAND(
    OUTPUT ${hellolib} ${helloexe}
    COMMAND make -C ${hellodir}
    COMMAND cp ${hellodir}/libhello.so ${hellolib}
    COMMAND cp ${hellodir}/hello ${helloexe}
)

ADD_EXECUTABLE(test test.c)
TARGET_LINK_LIBRARIES(test ${hellolib})

### END ###

Following is the output of make:

$ make
/usr/local/cmake-2.4.6/bin/cmake -H/root/tmp/cmake -B/root/tmp/cmake/b
--check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/cmake-2.4.6/bin/cmake -E cmake_progress_start
/root/tmp/cmake/b/CMakeFiles 1
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/root/tmp/cmake/b'
make -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/depend
make[2]: Entering directory `/root/tmp/cmake/b'
Scanning dependencies of target test
cd /root/tmp/cmake/b && /usr/local/cmake-2.4.6/bin/cmake -E cmake_depends
"Unix Makefiles" /root/tmp/cmake /root/tmp/cmake /root/tmp/cmake/b
/root/tmp/cmake/b /root/tmp/cmake/b/CMakeFiles/test.dir/DependInfo.cmake
make[2]: Leaving directory `/root/tmp/cmake/b'
make -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/build
make[2]: Entering directory `/root/tmp/cmake/b'
/usr/local/cmake-2.4.6/bin/cmake -E cmake_progress_report
/root/tmp/cmake/b/CMakeFiles 1
[100%] Building C object CMakeFiles/test.dir/test.o
/usr/bin/gcc   -o CMakeFiles/test.dir/test.o   -c /root/tmp/cmake/test.c
make[2]: *** No rule to make target `lib/libhello.so', needed by `bin/test'.
Stop.
make[2]: Leaving directory `/root/tmp/cmake/b'
make[1]: *** [CMakeFiles/test.dir/all] Error 2
make[1]: Leaving directory `/root/tmp/cmake/b'
make: *** [all] Error 2
$

So, how can I integrate 3rd-party software into my own project?

Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20070609/94e64e97/attachment.htm


More information about the CMake mailing list