GoogleTest already has a CMake option for this: gtest_force_shared_crtĮnabling this option will make gtest link the runtimes dynamically too, and match the project in which it is included. This will generate an error that looks something like the following: gtest.lib(gtest-all.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj I found this here:īy default, new Visual Studio projects link the C runtimes dynamically but GoogleTest links them statically. Worth noting that when generating googletest from CMake GUI I had to enabled gtest_force_shared_crtĪs I was getting a linker error. Using CONFIG makes it use the GTest-provided GTestConfig.cmake files which describes exactly what is available without erroring about the lack of release artifacts. It seems that the logic in this is not set up to handle a build without release artifacts. Here is the explanation, but I will read more into the CONFIG parameter.ĬMake ships with a FindGTest module. set(GTest_ROOT "c:/cpp/googletest")Īnd all is well with the world. CMake uses this PowerShell code and gets its arguments from the CI environment. If your CI is using cmd anyways, just call C:\path\to\vcvarsall.bat args you may need. Using PowerShell is probably way easier since it can be sourced in the shell directly. I am updating the thread incase anyone needs this here in the future. ben.boeckel (Ben Boeckel (Kitware)) July 3, 2021, 1:11pm 5. Notice the CONFIG parameter that I was not previously using (nor was required for pugixml or spdlog). I posted on the CMake forum and was suggested the following, which worked. Is there something additional I must do to get the GTestTargets-debug.cmake to be 'read/parsed'? I'm assuming that this would point CMake to the 'd' equivalent lib file. Which is referencing the 'd' suffixed filename.Īlso my Project Configuration (via the Visual Studio interface) is set to 圆4-Debug (default). IMPORTED_LOCATION_DEBUG "$/lib/gtestd.lib" Set_target_properties(GTest::gtest PROPERTIES Set_property(TARGET GTest::gtest APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) The GTestTargets-debug.cmake contains the following: # Import target "GTest::gtest" for configuration "Debug" If I manually remove the 'd' suffixes from the files, the error goes away. So when I save my CMakeLists.txt file, I get the errorĬould NOT find GTest (missing: GTEST_LIBRARY GTEST_MAIN_LIBRARY) However, the GTest project INSTALL target builds the files with a 'd' suffix (as I have selected 'Debug' / '圆4' Solution Configuration). I have added the following (after discovering I needed to use ROOT not DIR and point to the root directory. I am now seeking to add googletest (GTest). Set(pugixml_DIR "c:/cpp/pugixml/lib/cmake/pugixml") In my project CMakeLists.txt I simply add set(spdlog_DIR "c:/cpp/spdlog/lib/cmake/spdlog") My process in general is using CMake GUI to generate, opening the generated project in VS2019, running 'INSTALL' target, which builds and installs as expected. I have successfully added pugixml and spdlog, compiled and debugged A-OK. I have a CPP project set up in Visual Studio 2019.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |