![]() ![]() ![]() When building static libraries, CMake’s default, MSVC defaults to linkingĪgainst the multi-threaded, DLL-specific version of the standard library. When using Visual Studio to build our test we would run into a problem. We don’t just add the Google Mock directory, we also work around Worry about those later, for now it’s good enough. There are several potential problems with that line but we will The path to Google Mock is stored in a cached variable so that you canĮasily set it to the correct value either from the command line or via one There were some minor changes to the C++, grab the files here:Ĭmake_minimum_required ( VERSION 2.8 FATAL_ERROR ) set ( CMAKE_LEGACY_CYGWIN_WIN32 0 ) project ( "To Do List" ) enable_testing () if ( "$ /include ) add_executable ( ToDoTest ) target_link_libraries ( ToDoTest toDoCore gmock_main ) add_test ( ToDoTest ToDoTest )įirst we add the Google Mock directory to our project then we add our If we had a collection of classes instead of just one. Unit test, and perhaps a GUI App it would be compiled three times. So if the ToDo class is used by our command line tool, a CMake will compile source files once for each target Though it is a single source file making it a library actually has one We will make the ToDo class its own library, and put it in a subdirectory. Google Mock to add a more realistic unit test. In this chapter we will split up our project to have a library which we can Let’s add subdirectories, libraries,Īnd proper unit tests to make our project more realistic. A real project would be moreĬomplicated than the one we’ve created. The contents of the file will be made available to the calling script of find_package().So far our project is rather simple. We just need to provide the my_library-config.cmake file. Set(MY_LIBRARY_VERSION $ - matches this expression. Set(MY_LIBRARY_VERSION_MINOR 0 CACHE STRING "minor version" FORCE) Set(MY_LIBRARY_VERSION_MAJOR 1 CACHE STRING "major version" FORCE) # define library version (update: apparently you can also do it in project()!) The root CMakeLists.txt can look as follows: cmake_minimum_required(VERSION 3.0) ![]() This allows a seperation of CMake’s config files and other, unrelated configuration macros etc. The configurations will be set in the file which will be preprocessed to config_impl.hpp and included by config.hpp. The root CMakeLists.txt defines configuration options and adds the subdirectories. The library, the examples and the tool each has their own CMakeLists.txt defining the target and related code in their subdirectory. It also comes with some examples, a tool and unit tests. So we have a library consisting of various header and source files. The setupįor the scope of the tutorial, let’s say we have a library that has the following CMake structure: - include/ Throughout this post, I’ll be assuming a 3.x CMake version and an already existing CMake project. In particular, the system will be able to handle multiple installed versions and multiple configurations. In this post, I will show you how to install your library so that it can be used easily by other projects. As of version 0.5 my memory library now provides support for system-wide installation and CMake’s find_package().īecause I’ve spent hours of trial and error to come up with it, I’ll document it here. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |