4
votes

I'm trying to figure out how to use Qt Creator's settings and pass some CMake arguments. Let's say I have an app which I can build using the terminal like so:

cmake .. -DQTDIR=/home/myCustomBuildStuff 
    -DLD_LIBRARY_PATH=/home/myCustomBuildStuff 
    -DCMAKE_INCLUDE_PATH=/home/myCustomBuildStuff/include
    # etc.

As you can see, I'm using my custom built Qt (plus some other libs). When I build using the terminal, everything works.

But now I want to try to use the Qt Creator and pass all the CMake arguments by using the Qt Creator settings.

I tried to use the CMake Configuration settings that can be found in the Kits. I tried to modify the Build Settings, and add my arguments directly to the Build Steps and/or CMake table above. None of that helps and my app fails to include my custom built QtWidgets from main.cpp:

/usr/lib/x86_64-linux-gnu/libQt5Core.so.5:-1: error: 
    version 'Qt_5.9' not found (required by home/myCustomBuiltStaff/bin/uic)

In the error above the path is obviously wrong (it needs to search in /home/myCustomBuiltStuff/ folder). But how do I pass that path by using the Qt Creator settings?

Note, I cannot touch the content of the CMake file and only want to make it to build as it builds in my terminal when I pass all the paths as arguments to CMake.

2
You can try to disable/remove the default built steps and add your build command as a Custom Process Step. This should give you the exact same result as running it in a terminal.m7913d
thank you, I was able to reproduce the build by using the Custom Steps.vicrucann
I so terribly miss the CMake wizard that was available for older versions of Qt Creator (v3.5) as demonstrated in this article!normanius
I just posted an issue in Qt Creator's issue tracking system. Let's see how they will respond.normanius

2 Answers

6
votes

So I followed an advice given in the comment, and had to add my own custom build steps in order to make sure I have the wanted CMake arguments passed correctly. I could not find any other way to pass them by using Qt Creator's settings and menus.

This is the list of steps I did:

  1. Go to Projects and chose the Build to edit. If you have several configurations, you will have to repeat the below steps for each.
  2. Disable or delete the default CMake step, normally it would be something like cmake --build . --target all
  3. Chose your Build directory.
  4. Add new Custom process step with Command to be cmake, Arguments to be your CMake arguments; normally you'd leave the Working directory to default.
  5. Add new Custom process step with Command to be make and add any necessary arguments (e.g. LD_LIBRARY_PATH).
  6. Go and edit the Run settings: make sure the Executable points to the one your cmake and make just created. There you can also add any necessary command line arguments.
0
votes

This is version 4.3.1 I am using. If not yet done you should have the most updated version of qtcreator.

File->Open:

Choose the CMakeLists.txt file of your project. Select your target and you should be able to get the project open at least.

Now click on "Projects". Assure you have selected Build & Run -> Build and under Cmake click on "Add" -> "String" or "Directory". In your case Directory make more sense. On the left you put the define, without "-D" of course and right side the value.

Repeat the step for every variable you want to define and click on "Apply"

If that does not work I would try to set the CMAKE_EXE_LINKER_FLAGS to -L/home/myCustomBuildStuff

Hint: To see if it worked you can pass VERBOSE=1 parameter to toolparameters if you are using makefiles under the section Build steps. That way your output will show if the variable were really passed.

Hint: Remeber to activate the "Advanced" selection so you see more if not all the variables defined fo Cmake.