[CMake] How to determine the current target?

Richard Wackerbarth richard at nfsnet.org
Thu Apr 9 19:21:52 EDT 2009


Jeremy,

I think that the "problem" is that CMake was never oriented toward the  
situation that you, and many others, have where it is "very expensive"  
to have the code under development as a part of a much larger project.  
When you get to a relatively stable situation, you will appreciate the  
automated building and testing of the entire project. However, I agree  
that, until you reach a "stable" set of changes, you need to be able  
to "focus" on one part of the project and postpone having those  
changes tested against the rest of the project.

My suggestion would be to use a cache variable to select your "current  
target".

SET(CURRENT_TARGET "All" CACHE String "Part of the project under  
development")

IF (CURRENT_TARGET MATCHES "Interpreter")
     SUBDIR (Interpreter)
ELSEIF (CURRENT_TARGET MATCHES "Translator")
     SUBDIR (Translator)
ELSEIF (CURRENT_TARGET MATCHES "Backend")
     SUBDIR (Backend)
ELSEIF (CURRENT_TARGET MATCHES "All")
     SUBDIR (Interpreter)
     SUBDIR (Translator)
     SUBDIR (Backend)
ELSE
     ERROR ("Invalid CURRENT_TARGET")
ENDIF


Richard

On Apr 9, 2009, at 3:38 PM, Jeremy Cowgar wrote:

> Alexander Neundorf wrote:
>>
>> No, that's wrong in principle.
>> In the cmake files there is no current target, they describe all  
>> targets.
>>
>> If you want to do something when some target is built, you have to  
>> do this via dependencies, either via add_custom_command() or  
>> add_custom_target().
>>
>
> Hm, the reason I want it is because of how I am using CMake and  
> triggering a generator. I have to translate .e files (Euphoria)  
> into .c files when the source .e files change. Yesterday, Bill  
> Hoffman helped me quite a bit with this and I finally got that  
> working. The only problem is that we translate 3 main programs, the  
> interpreter, the translator and the backend. Each one produces about  
> 115,000 lines of C code and it takes ~20 seconds for each target.  
> So, here's what happens... I edit common.e which is included in all  
> three programs (interpreter, translator and backend). Right now I am  
> working on the interpreter, so I do:
>
> wmake eui
> To rebuild the interpreter. However, CMake now sees that common.e  
> has changed, it triggers running cmake.exe to rebuild the makefiles  
> and when it does so, all three produces are triggered for a  
> generation because common.e has changed. That would be correct if I  
> was building all three programs, however, I am only working on the  
> interpreter, I don't want to wait an extra 40 seconds to translate  
> the backend and translator when I am not working on it. Now, wmake  
> eui only compiles the interpreter source files, but the translation  
> is time consuming (considering you edit, compile, edit compile,  
> etc...).
>
> Some how I would like to realize that they want to build the  
> interpreter only, don't worry about re-translating the translator  
> and backend right now.
>
> You can see my two main CMake files in : http://rapideuphoria.svn.sourceforge.net/viewvc/rapideuphoria/trunk/source/ 
>  to see how I am doing this currently. I just can't figure out how  
> to not re-translate the other programs that I really don't care  
> about right now.
>
> Thanks for any help,
>
> Jeremy




More information about the CMake mailing list