2

I want to use the intel compiler for Qt, but using the intel compiler implies running the script

$ source /opt/intel/bin/compilervars.sh intel64

Of course, I could add this to ~/.bashrc, but this would not run it in QtCreator, where it still complains about missing icpc. So I want it to be a part of the main mkspec qmake file.

How can I execute that full bash command in qmake?

jeremy
  • 9,965
  • 4
  • 39
  • 59
The Quantum Physicist
  • 24,987
  • 19
  • 103
  • 189
  • 1
    http://stackoverflow.com/questions/3612283/running-a-program-script-from-qmake – Greenflow Aug 11 '13 at 19:56
  • just append /opt/intel/compilers_and_libraries_2018.2.199/linux/mkl/lib/intel64 and /opt/intel/compilers_and_libraries_2018.2.199/linux/ipp/lib/intel64 to LD_LIBRARY_PATH and you're ready to go ! – Aminos Feb 28 '20 at 17:33

2 Answers2

2

Short Answer: Using QMAKE_EXTRA_TARGETS and PRE_TARGET_DEPS, you can execute source /opt/intel/bin/compilersvars.sh intel64, but simply sourcing them will not solve your issue.

Long Answer: The QMake file is converted into a Makefile. Make then executes the Makefile. The problem you will run into is that Make executes each command in its own shell. Thus, simply sourcing the script will only affect one command, the command that executes the script.

There are a couple of possible ways to make things work:

  • Execute the script before starting Qt-Creator. I've actually done this for some projects where I needed to have special environment variables setup. To make my life easier, I created a shell command to setup the environment and then launch Qt-Creator.
  • Within Qt-Creator, modify the Build Environment for the project I've also used this trick. In your case, simply look at the environment setup by the script and change the "Build Environment" settings under the project tab for your project to match those setup by the script.

It might also be possible to modify QMake's compiler commands, but I am not sure you can make it execute two commands instead of one (source the script then execute the compiler). Further more, this will make the project very un-transportable to other systems.

jwernerny
  • 6,978
  • 2
  • 31
  • 32
0

You can create a shell script that does more or less the following:

#! /usr/bin/env sh

# Remove the script's path from the PATH variable to avoid recursive calls
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export PATH=${PATH/$SCRIPT_DIR:/}

# Set the environment up
source /opt/intel/bin/compilervars.sh intel64

# Call make with the given arguments
make "$@"

Save it into a file named "make" in an empty directory somewhere, make it executable, then change the build environment in QT Creator to prepend PATH with the script's directory:

PATH=[dir-of-make-script]:${Env:PATH}

You can do this either in the project settings or once and for all in the kit settings.

Like this, QT Creator will be fooled into calling your make script which sets up your environment before calling the actual make binary. I use a similar technique under Windows with Linux cross-toolchains and it has been working well so far.

Julien Ruffin
  • 822
  • 1
  • 7
  • 8