2

I am aware that CMake's EXCLUDE_FROM_ALL allows me to exclude a target from both make and make all.

What if I wanted to only exclude the target from the default make but include it in the make all?

Example:

add_executable(aaa ${AAA_SOURCE})
add_executable(bbb EXCLUDE_FROM_ALL ${BBB_SOURCE})

Result:

make only builds aaa

make all only builds aaa

What I want:

make only builds aaa

make all builds aaa and bbb

usr1234567
  • 21,601
  • 16
  • 108
  • 128
Rufus
  • 5,111
  • 4
  • 28
  • 45
  • 2
    Are you aware, that if you omit the target in your make call, it will automatically build all? – usr1234567 Jan 05 '18 at 09:13
  • for reference: https://stackoverflow.com/questions/47553569/how-can-i-build-multiple-targets-using-cmake-build?rq=1 – Rufus Jan 11 '18 at 03:42

1 Answers1

2

When using CMake with the Unix Makefiles Generator, you will get make files that have the default target all.
When you run make <target>, the <target> gets build. If the argument is omitted, the default target is build. Adding all does not mean that all targets are build, but the target called all.
To answer your question: As both ("" and "all") are the same target, you cannot add a build to one target but not to the other.

By the way, there is no clear definition what all should include, cf. What does "all" stand for in a makefile?

usr1234567
  • 21,601
  • 16
  • 108
  • 128
  • So I assume it's not possible to create a target, say called `all`, that refers to multiple targets – Rufus Jan 11 '18 at 03:41
  • You can have such a target, but you have to name it different from the build-in ones like "test", "install", or "all". – usr1234567 Jan 11 '18 at 06:48
  • Could you tell me the CMake command for creating a target that actually refers to multiple targets? I assume it's not `add_executable` since that only refers to 1 target.. – Rufus Jan 11 '18 at 07:22
  • Just create a new target and use add_dependencies. A litte complicated, but still valid answer: https://stackoverflow.com/q/47553569/2799037 – usr1234567 Jan 11 '18 at 13:00