10

I use cmake to generate qtcreator's project files, For the run part I can have different targets, but the build parts, I can only select all, and could not build each targets separately. Is there anyway I can build only one targets with qtcreator's cmake projects?

emailhy
  • 780
  • 9
  • 22

3 Answers3

11

Since QtCreator 4.0.0, on Projects pane, go to build steps -> Details and select your target. You can also use the "--target" command line option with cmake.

Update:

Since QtCreator 4.3.0 with CMake 3.7.2 or greater the list of targets is on the project view, so you can just right click and build.

rboc
  • 344
  • 3
  • 10
  • But is it possible to select more than one target to build? It seems like it's either "all" or "one", but the interface is a list of checkboxes, so it seems like it should be possible to select as many as you want, but it only lets you select one. – David Doria Aug 24 '17 at 12:58
  • In Qt creator 4.0.0 you can only select one target on the Projects pane. Yes, is a list of checkboxes, but you can only select one. Since QtCreator 4.3.0 all the tagets are viewable in the project view as well as int the Project pane, but multiple targets can't be selected yet in order to build either by selecting in the Projects pane or on the project view. – rboc Aug 25 '17 at 08:14
4

With QtCreator 4.0+ it is is possible, see rboc's answer below.


Old answer

I believe this is currently essentially impossible. I say "essentially" because if you wanted to, you could make a custom build configuration for each target you want to create, manually specifying the target as an argument in the command for that configuration. Then, to build that target, simply select that configuration and build. This is an extremely hacky workaround, but unfortunately I think it's the only viable option at the moment. A better solution might be to create a separate project for each target.

Antonio
  • 19,451
  • 13
  • 99
  • 197
Kyle Strand
  • 15,941
  • 8
  • 72
  • 167
  • yes, you right, but cmake very usefull for cross platfom, cross IDE developmant. Adding additional customization to the project only for Qt Creator usage isn't very helpfull. I use Qt Creator 4.0 and the problem is still the same. I can't build only one target. I could only build the whole solution. It is so sad (. – Maks May 28 '16 at 09:01
  • @Maks If you're using CMake, you can build individual targets from the command line. – Kyle Strand May 28 '16 at 21:19
  • 1
    Make sure to view @rboc's answer - this does seem possible now. – David Doria Nov 10 '16 at 13:37
  • 1
    @DavidDoria I've updated my answer rto refer to rboc's. I've also asked OP to change the accepted answer. – Kyle Strand Nov 10 '16 at 17:23
1

One can configure QtCreator to build the target that is currently selected for running, which IMHO should be the default.

To do so, navigate to the "Projects" pane, then in your Kit's "Build" tab, locate the "Build Steps" section. Remove all existing build steps by clicking on the cross.

Add one "Custom Process Step". Fill the "command" field with "%{CMake:Executable:FilePath}", the "arguments" field with "--build . --target %{CurrentRun:Executable:FileBaseName}" and the "working directory" field with "%{buildDir}" (all without quotes).

Tada!

fkorsa
  • 684
  • 1
  • 8
  • 22