![]() Check for working CXX compiler: /usr/bin/c++ - works Check for working CXX compiler: /usr/bin/c++ Check for working C compiler: /usr/bin/cc - works Check for working C compiler: /usr/bin/cc The CXX compiler identification is GNU 4.8.4 The C compiler identification is GNU 4.8.4 Src='/home/david/perso/gtest-cmake-example/build/test/gtest/src/master.zip'ĭst='/home/david/perso/gtest-cmake-example/build/test/gtest/src/gtest' warning: did not verify file - no URL_HASH specified? Performing download step (download, verify and extract) for 'gtest'ĭst='/home/david/perso/gtest-cmake-example/build/test/gtest/src/master.zip'įile='/home/david/perso/gtest-cmake-example/build/test/gtest/src/master.zip' Building CXX object main/CMakeFiles/myApp.dir/ Building CXX object libbar/CMakeFiles/libbar.dir/ Building CXX object libfoo/CMakeFiles/libfoo.dir/ Here is how the testfoo CMakeLists.txt file would look like: The testfoo program depends on libfoo, GoogleTest and GoogleMock. #Writing a testfoo test program for libfoo As a workaround, I had to explicitly use include_directories to specify them. Note: It should theoretically be possible to set the GoogleTest and GoogleMock include directories as target properties using the INTERFACE_INCLUDE_DIRECTORIES variable, but it fails because these directoires don’t exist yet when they are declared. "IMPORTED_LOCATION" "$/googletest/include" Set_target_properties(libgtest PROPERTIES # Create a libgtest target to be used as a dependency by test programsĪdd_library(libgtest IMPORTED STATIC GLOBAL) # Get GTest source and binary directories from CMake projectĮxternalProject_Get_Property(gtest source_dir binary_dir) Obviously, this is only an option if you actually do have a buildsystem, but if this is the case, this would be my recommendation.ĭepending on how your buildsystem is structured, your mileage may vary, but in the end you should be able to declare GoogleTest and GoogleMock as dependencies using CMake functions like the built-in find_package or the pkg-config based pkg_check_modules. #Having both packages integrated in your build system There are at least three options to integrate your project with GoogleTest and GoogleMock. #Resolving GoogleTest and GoogleMock dependencies This is where things get a bit hairy, since Google does not recommend to install these packages in binary form, but instead to recompile them with your project. Since all test programs will be using these packages, the root CMakeLists.txt file should contain all directives required to resolve the corresponding dependencies. Tests programs are based on Google’s Googletest framework and its GoogleMock extension. In my simplistic example, there is only one subdirectory under test, but in a typical project, it would contain several subdirectories, one for each test program. The test directory contains a single executable allowing to test the libfoo service using a mock version of libbar.įrom Wikipedia: In object-oriented programming, mock objects are simulated objects that mimic the behavior of real objects in controlled ways.įor those interested, the code for this sample project is on github. The main subdirectory contains the main project target, an executable providing the super-useful libfoo service using the awesome libbar backend (for example libfoo could be a generic face recognition library and libbar a GPU-based image processing library).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |