[CMake] target dependency in subdirectory not found

Jos van den Oever jos.van.den.oever at kogmbh.com
Mon Dec 12 14:42:54 EST 2011


I'm trying to get get CMake to do the equivalent from this Makefile. I'm using 
cp in this simple example, but want to use different commands in my project.

==Makefile==
srcdir=..

hij: a/efg
    cp a/efg hij
a/efg: $(srcdir)/a/abc
    -mkdir a
    cp $(srcdir)/a/abc a/efg
==========

For this I am using two CMakeLists.txt files.

==CMakeLists.txt==
cmake_minimum_required(VERSION 2.8)
add_subdirectory(a)
add_custom_command(
  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/hij
  COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different
    ${CMAKE_CURRENT_BINARY_DIR}/a/efg
    ${CMAKE_CURRENT_BINARY_DIR}/hij
  DEPENDS
    ${CMAKE_CURRENT_BINARY_DIR}/a/efg
  VERBATIM
)
add_custom_target(hij_target ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/hij)
==================
==a/CMakeLists.txt==
add_custom_command(
  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/efg
  COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different
    ${CMAKE_CURRENT_SOURCE_DIR}/abc
    ${CMAKE_CURRENT_BINARY_DIR}/efg
  DEPENDS
    ${CMAKE_CURRENT_SOURCE_DIR}/abc
  VERBATIM
)
====================

This gives me the error:

make[2]: *** No rule to make target `a/efg', needed by `hij'.  Stop.
make[1]: *** [CMakeFiles/hij_target.dir/all] Error 2
make: *** [all] Error 2

How can cmake be made to understand this simple dependency?

Cheers,
Jos

-- 
Jos van den Oever, software architect
+49 391 25 19 15 53
074 3491911
http://kogmbh.com/legal/


More information about the CMake mailing list