Search code examples
bashqmake

Calling sed in a qmake script


Here is my problem: I want have my qmake script detect my opencv version and save the result in the CONFIG variable. I need the result to have this form : "opencv20","opencv21","opencv22",etc. I know that I can use the system() function to call bash commands and wanted to use something like this :

CONFIG += opencv$$system(pkg-config --modversion opencv | cut -d. -f'1,2' | sed 's/\.//g')

It works fine in my terminal, but qmake gives me "opencv2." when I try to print the output. The outputs of pkg-config and cut commands alone are correct so I assume the sed call is confusing qmake somehow... any hints ?


Solution

  • system() commands are executed in a subshell. That's why you have to escape your strings:

    CONFIG += opencv$$system(pkg-config --modversion opencv | cut -d . -f \'1,2\' | sed \'s/\.//g\')