[CMake] Force rebuild

Bill Hoffman hoffman.mlist at gmail.com
Tue Mar 27 14:30:24 EST 2007


kitts wrote:
> On Tuesday 27 Mar 2007 at 6:50:37 am, Bill Hoffman wrote:
>   
>> Min Cu wrote:
>>     
>>> Yes, that is more or less what I need. I have a project that generates
>>> a header file which is included in other projects. However, once the
>>> project is built when make is called the next time it does not get
>>> rebuilt. So, I guess my question is "How do I make the custom target
>>> run every built?" The solution needs to work on both Windows and
>>> Linux/Unix so I can't use the pre-build event. It is probably a silly
>>> question but I am new to CMake and don't know it well yet.
>>>       
>> add a custom target that depends on all.  Then use add_dependency to
>> make other targets depend on it.  So, look at these commends:
>>
>> add_dependencies
>> add_custom_target
>>
>> here:
>> http://www.cmake.org/HTML/Documentation.html
>>     
>
> Is it not possible to make target all depend on clean so that clean is run 
> before all?
>   
No, and there is not even a clean target in the IDE projects.   However, 
I don't see why you are
having trouble creating a custom command that is run each time.

ADD_CUSTOM_TARGET: Add a target with no output so it will always be built.

  ADD_CUSTOM_TARGET(Name [ALL] [command1 [args1...]]
                    [COMMAND command2 [args2...] ...]
                    [DEPENDS depend depend depend ... ]
                    [WORKING_DIRECTORY dir]
                    [COMMENT comment] [VERBATIM])

Adds a target with the given name that executes the given commands. The 
target has no output file and is ALWAYS CONSIDERED OUT OF DATE even if 
the commands try to create a file with the name of the target. Use 
ADD_CUSTOM_COMMAND to generate a file with dependencies. By default 
nothing depends on the custom target. Use ADD_DEPENDENCIES to add 
dependencies to or from other targets. If the ALL option is specified it 
indicates that this target should be added to the default build target 
so that it will be run every time (the command cannot be called ALL). 
The command and arguments are optional and if not specified an empty 
target will be created. If WORKING_DIRECTORY is set, then the command 
will be run in that directory. If COMMENT is set, the value will be 
displayed as a message before the commands are executed at build time. 
Dependencies listed with the DEPENDS argument may reference files and 
outputs of custom commands created with ADD_CUSTOM_COMMAND.


If you have ALL and no DEPENDS the command should run every time you 
type make.

-Bill



More information about the CMake mailing list