2012-04-20 18 views
12

Ho scritto un file di CMakeLists.txt tra cui 2 eseguibili (target1 e target2):Come scegliere quale target eseguibile CMake sarà quello predefinito?

ADD_EXECUTABLE(target1 ${CXX_FILES}) 
TARGET_LINK_LIBRARIES(target1 ${requiredlibs}) 

ADD_EXECUTABLE(target2 ${CXX_FILES} ${OTHER_CXX_FILES}) 
TARGET_LINK_LIBRARIES(target2 ${requiredlibs}) 

Ora, ogni volta che eseguo make senza parametri entrambi i bersagli vengono ricostruiti. Ma voglio definire target1 come eseguibile predefinito in modo tale che l'esecuzione in esecuzione senza parametri costruisca solo target1. Per la costruzione di target2 eseguirei make target2.

È possibile?

Nel Makefile creato da CMake c'è la seguente definizione: default_target: tutto

Credo di aver bisogno di un modo per impostare questo default_target-target1.

Un altro problema che ho è che make ricostruisce sempre gli obiettivi, anche se nessun file sorgente è stato modificato.

risposta

11

Un esempio CMakeLists.txt che fa quello che avete richiesto:

ADD_EXECUTABLE(target1 a.c) 

ADD_EXECUTABLE(target2 EXCLUDE_FROM_ALL b.c) 

Per me non ricostruisce il bersaglio, se i file di origine non vengono modificati (o tempo di modifica non è cambiata). Uscita ottengo:

$ make -f Makefile 
Scanning dependencies of target target1 
[100%] Building C object CMakeFiles/target1.dir/a.c.o 
Linking C executable target1 
[100%] Built target target1 
[$ make -f Makefile 
[100%] Built target target1 

Si noti che la seconda marca non ricostruisce nulla.

(si poteva leggere la CMake manual per questo tipo di informazioni)

+0

Grazie per la risposta rapida e per il tuo esempio. EXCLUDE_FROM_ALL ha risolto il mio problema. – user1346791

Problemi correlati