Question

I have a qt project setup as a subdirs project with my source code in a src directory and unit testing code setup in a test directory. Each has its own project file. I want to be able to compile the source on other computers, but they may not have the googletest library setup. I have looked at the qmake test function "requires()" and "packagesExist()" however, they do not seem to be built to handle external libraries.

How can I instruct qmake to skip the test project if the testing library is not found?

Was it helpful?

Solution

It is not possible without checking typical locations if the library is present in there.

Unfortunately, googletest does not seem to ship package-config ".pc" files either, so that is why you cannot use the packagesExist() qmake function.

So, I would use a bunch of exist call to work this around, or switch away from qmake to something better like cmake.

!exists("/foo/bar/baz.so"):!exists("/hello/world/baz.so"):...: message("Google test is not installed on your system")

OTHER TIPS

If the libraries you're trying to link to do not have pkgconfig information, you can make a qmake config test for each of these libraries using qtCompileTest(). I'll show you here how to use this feature of qmake.

qtCompileTest qmake config tests will run at qmake time. If the test compiles, config_ will be added to the CONFIG variable and qmake will print Checking for <testname>... yes or Checking for <testname>... no depending on whether or not the test compiled.

In your project dir, create a directory with the name config_tests, and under that create a directory for the library or feature you're going to test, a starting simple qmake project and main.cpp file, ending up like so:

myproject/
  myproject.pro
  <source files, etc>
  config_tests/
    googletest/
      googletest.pro
      main.cpp

Make the googletest project be very simple, with just the bare minimum to link an executable to the googletest library, and test including necessary headers for using it. Load this project directly into Qt Creator and test that it actually compiles in the scenarios you expect it to work, and not in others (i.e. test for the various platforms you'll be using that contain and don't contain the googletest library)

Next, use this qmake config test project in your main project by adding the following to the top of your project. load(configure) below loads in the qmake support for qtCompileTest - as it's not normally built-in:

load(configure)
qtCompileTest(googletest)

In the places where you will be compiling features that require googletest, you can wrap them in the following qmake test:

CONFIG(config_googletest) {
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top