How to choose which CMake executable target will be the default one?
build, cmake
Solution
An example CMakeLists.txt that does what you requested:
ADD_EXECUTABLE(target1 a.c)
ADD_EXECUTABLE(target2 EXCLUDE_FROM_ALL b.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)
Problem
I have written a `CMakeLists.txt` file including 2 executables (`target1` and `target2`): ``` ADD_EXECUTABLE(target1 ${CXX_FILES}) TARGET_LINK_LIBRARIES(target1 ${requiredlibs}) ADD_EXECUTABLE(target2 ${CXX_FILES} ${OTHER_CXX_FILES}) 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.