RAD Studio 12.0 and GoogleTest Unit Testing Framework – How to Compile Earlier Version

If you are an owner of RAD Studio 11 (or C++ Builder 11) and you followed my suggested setup for GoogleTests, creating local copies of the GoogleTest library with each project as described in my blogs of 25th March:

Tips For Using GoogleTests with Embarcadero Clang64 for Windows VCL Projects.

then you will already have a local copy of the GoogleTest framework downloaded from Getit (using RAD Studio 11). This is stored in your getit repository, typically

C:\Users\Public\Documents\Embarcadero\Studio\22.0\CatalogRepository\GoogleTest-2021.09

I will call this long path ”…GT2021.09” for the rest of this blog. You can take this code and rebuild it using RAD Studio 12 and then update your projects with the newly built GoogleTest library files.

Proceed as follows.

1) Copy folder …GT2021.09 to a convenient new location, say …Projects\GoogleTest-2021.09

2) So you know (in the future) what the folder is, rename it to ..Projects\GoogleTest_12_from_11

3) Start up RAD Studio 12.0 (or C++ Builder 12.0).

4) Open up project group Googletest.groupproj which is in folder ..Projects\GoogleTest_12_from_11

5) Change all of the project targets to Windows 64 bit (*** see note below)

6) Do a “Build All Projects”. It will build all the projects without any errors.

7) Use file explorer to navigate to ..Projects\GoogleTest_12_from_11\cbuilder\bin\Win64\Release
and confirm that there is file sample8_unittest.exe

8) Open up a windows shell command window and run this sample8_unittest.exe file.
You should see a “passed all 12 tests” message. This confirms that all is well.

9) Replace gmock.a, gmock_main.a, gtest.a and gtest_main.a in your working folder (typically)

project_folder\Unit tests\GoogleTest\LibWin64

with newly compiled versions from ..Projects\GoogleTest_12_from_11\cbuilder\lib\Win64\Release

Notes.

*** (item 5 above) I have only tried this for Windows 64 bit applications. But it is sure to work fine with clang32 projects too.

If you are creating a new local copy of GoogleTest for first time use with a project, I repeat my suggestion from the earlier blog:

a) Create a new sub-folder in your project_folder called “Unit tests” (use this for your unit test *.cpp files).

b) Inside project_folder\Unit tests\ create a new sub-folder called Google Tests

c) Inside project_folder\Unit tests\GoogleTest\ create a new folder called LibWin64

d) Inside project_folder\Unit tests\GoogleTest\LibWin64 copy gmock.a, gmock_main.a, gtest.a and gtest_main.a from your newly compiled folder Projects\GoogleTest_12_from_11\cbuilder\lib\Win64\Release

e) Inside project_folder\Unit tests\GoogleTest\ create a new folder called include

f) Inside project_folder\Unit tests\GoogleTest\include copy all the contents (including further sub-folders) of
Projects\GoogleTest_12_from_11\googletest\include\gtest

Leave a comment