Take the 2-minute tour ×

I have written a CMakeLists.txt file including 2 executables (target1 and target2):

TARGET_LINK_LIBRARIES(target1 ${requiredlibs})

TARGET_LINK_LIBRARIES(target2 ${requiredlibs})

Now every time when I run make without any parameters both targets are rebuilt. But I want to define target1 as default executable so that running make without any parameters only builds target1. For building target2 I would run make target2.

Is this possible?

In the Makefile created by CMake there is the following definition: default_target: all

I think I need a way to set this default_target to target1.

Another problem I have is that make always rebuilds the targets, even if no source file has been changed.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

An example CMakeLists.txt that does what you requested:

ADD_EXECUTABLE(target1 a.c)


For me it does not rebuild the target if the source files are not changed (or modification time did not change). Output I get:

$ 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

Note that the second make does not rebuild anything.

(you could read the CMake manual for this type of information)

share|improve this answer
Thanks for your quick answer and for your example. EXCLUDE_FROM_ALL solved my problem. –  user1346791 Apr 20 '12 at 15:05
add comment

Your Answer


