2

I am using CMake to build a Qt5 project on OS X. I need to create a build process that is as simple as possible for others.

By default Qt5 installs to the home folder on OS X. However, it then places its files within a directory named after the exact version number, e.g. 5.2.1.

At the moment I am using these lines in my CMake file:

set(QT5_PATH $ENV{HOME}/Qt5.2.1/5.2.1/clang_64/ CACHE PATH "Path to Qt5")
set(QT5_MODULE_PATH ${QT5_PATH}/lib/cmake)
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${QT5_MODULE_PATH})

This works, but unfortunately breaks with each minor update of Qt as the 5.2.1 needs to be changed to 5.2.2, etc.

In Windows there are environment variables that can be used to find Qt. Is there anything similar in OS X that I can use within CMake to find a Qt installation?

usr1234567
  • 21,601
  • 16
  • 108
  • 128
Tim MB
  • 4,413
  • 4
  • 38
  • 48

1 Answers1

0

Use find_package instead of juggling with the paths yourself. Then your users can rely on standard CMake mechanism instead of figuring out your own CMake code.

Use find_package(Qt5Widgets) to get targets like Qt::Widgets to link against and for the includes.
Similar for Qt5Core and whatever part of Qt 5 you need.

See Qt's documentation: http://doc.qt.io/qt-5/cmake-manual.html

usr1234567
  • 21,601
  • 16
  • 108
  • 128
  • Note that the documentation you link to does not recommend using `Qt5Widgets_INCLUDE_DIRS` etc, but recommends imported targets like `Qt5::Widgets` instead. And you should recommend that too :). – steveire Jun 05 '16 at 09:16
  • @steveire You are right, I added an according sentence. – usr1234567 Jun 05 '16 at 13:09
  • I should have said 'you should recommend that instead' (that is the article recommends it and you should too - not you should recommend the variables in addition - that doesn't make any sense). I see no reason to encourage anyone towards the variables. Use the imported targets and ignore the variables. – steveire Jun 05 '16 at 19:43