[CMake] VC2005 - ADD_CUSTOM_TARGET problems..
Brad King
brad.king at kitware.com
Thu May 26 14:06:07 EDT 2005
Shishir Ramam wrote:
> root/
> PROJECT(MyProject)
> subdir1/src
> ADD_EXECUTABLE(target1 target1_srcs.c)
> # target1 generates a header file - say gen_header.h
> subdir2/
> ADD_EXECUTABLE(target2 target2_srcs.c)
>
> target2 includes gen_header.h So my interest is in building and running target1
> before attempting to build target2.
This is a common design and is fully supported by CMake, but not quite
the way you are doing things. The custom command for generating the
header should be added in subdir2/CMakeLists.txt:
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/gen_header.h
COMMAND ${EXE_DIR}/target1 ARGS arg1 arg2
DEPENDS ${EXE_DIR}/target1
)
Since the header is generated it will not exist when the dependencies of
the source files are scanned, so you need to add the dependency using a
source file property:
SET_SOURCE_FILES_PROPERTIES(target2_src.c
PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/gen_header.h)
The FOREACH command can help you do this for more than one source in
target2.
Note that generating source files is much easier than generating header
files because you do not need the OBJECT_DEPENDS part. Usually we use
CONFIGURE_FILE to produce header files at CMake time with build-specific
information. Then you don't need the generation step at all.
-Brad
More information about the CMake
mailing list