[CMake] VC2005 - ADD_CUSTOM_TARGET problems..
Shishir Ramam
sramam at gmail.com
Thu May 26 15:19:17 EDT 2005
Brad,
As always, thanks for the quick response.
A few follow ups -
On 5/26/05, Brad King <brad.king at kitware.com> wrote:
> 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
> )
What is the purpose of OUTPUT here? I'm guessing it allows Cmake to
determine dependencies.
>
> 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)
This does seem reasonable. The complication that arose for my project
was the gen_header.h is also used for a few other targets in root/subdir1,
root/subdir2, root/subdir3.
Instead of adding the dependency for each source file, I was attempting
sequence the steps, such that -
1. target1 gets built,
2. gen_header.h gets generated via a ADD_CUSTOM_TARGET with the ALL option.
3. All the other targets can get built from there without any trouble.
To give you some idea on the rationale for pursuing this approach :
This is a third party code segment, and the gen_header.h is a file that
contains error codes and error strings based on platform specific
definitions - it's used all over the place. Am trying to prevent adding
the dependency to *all* source files, but figuring a minimal set is a pain
in the neck.
It all seems to work too. Just that there seems to be some kind of a loop
being introduced in the VC2005 solution, resulting in a high CPU usage.
Any hints on how to localise the problem would help...
-shishir
>
> 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.
Agreed. Dealing with 3rd party code, I'd like to keep the build system
interference
to a minimum in the hope that upgrading will be easier.
>
> -Brad
>
--
The man who doesn't read good books has no advantage over the man who
can't read them. - Mark Twain
More information about the CMake
mailing list