Upgrading from 1.6 to 1.8.0 - CMake issues

554 views
Skip to first unread message

David Wallace

unread,
Apr 17, 2017, 9:30:52 PM4/17/17
to Google C++ Mocking Framework
I'm trying to upgrade from the version 1.6 of gmock/gtest that we've been using for the past several years, and I've pulled the googletest-release-1.8.0.tar.gz from the GitHub repository to get the latest released version.  I haven't been able to just swap it in for the old 1.6 code in a replacement of externals.  The problems I've been having so far seem to be related to the reorganization of the code - in 1.6, the integrated gtest was a subdirectory below gmake, and in 1.8, it looks like they are separate directory trees, named googletest and googlemock.  I've tried to reflect this by importing googletest and googlemock as separate directories under our top-level directory, and changing our top-level CMakeLists.txt to reflect the new locations:

$ svn diff
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt      (revision 41185)
+++ CMakeLists.txt      (working copy)
@@ -40,8 +40,8 @@
 SET( TCL_DIR ${CMAKE_SOURCE_DIR}/tcl/src )
 SET( TCL_SOURCE_DIR ${CMAKE_SOURCE_DIR}/tcl/src )
 SET( QT_CHARTS_DIR ${CMAKE_SOURCE_DIR}/UI/qtcharts )
-SET(GOOGLETEST_SOURCE_DIR ${CMAKE_SOURCE_DIR}/gmock/gtest)
-SET(GMOCK_SOURCE_DIR ${CMAKE_SOURCE_DIR}/gmock)
+SET(GOOGLETEST_SOURCE_DIR ${CMAKE_SOURCE_DIR}/googletest)
+SET(GMOCK_SOURCE_DIR ${CMAKE_SOURCE_DIR}/googlemock)
 SET(CMAKE_COLOR_MAKEFILE OFF)

 FIND_PACKAGE(CreateVersion REQUIRED)
@@ -200,11 +200,12 @@
   ON)

     MESSAGE( STATUS "Loading gmock/gtest Projects" )
-    add_subdirectory(gmock)
-    set_target_properties( gmock PROPERTIES FOLDER 3rdParty/google )
-    set_target_properties( gmock_main PROPERTIES FOLDER 3rdParty/google )
-    set_target_properties( gtest PROPERTIES FOLDER 3rdParty/google )
-    set_target_properties( gtest_main PROPERTIES FOLDER 3rdParty/google )
+    add_subdirectory(googlemock)
+    add_subdirectory(googletest)
+    #set_target_properties( gmock PROPERTIES FOLDER 3rdParty/google )
+    #set_target_properties( gmock_main PROPERTIES FOLDER 3rdParty/google )
+    #set_target_properties( gtest PROPERTIES FOLDER 3rdParty/google )
+    #set_target_properties( gtest_main PROPERTIES FOLDER 3rdParty/google )
 ENDIF()

 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
Index: .
===================================================================

(I've commented out the set_target_properties for the moment while I get the rest of this working.)

Running our top-level CMake produces an error that seems like it may be related to the reorganization of the code:

Loading gmock/gtest Projects

CMake Error at googletest/cmake/internal_utils.cmake:149 (add_library):
add_library cannot create target "gtest" because another target with the
same name already exists. The existing target is a static library created
in source directory "D:/Projects/trunk4/googletest". See documentation for
policy CMP0002 for more details.
Call Stack (most recent call first):
googletest/cmake/internal_utils.cmake:172 (cxx_library_with_type)
googletest/CMakeLists.txt:90 (cxx_library)

CMake Error at googletest/cmake/internal_utils.cmake:149 (add_library):
add_library cannot create target "gtest_main" because another target with
the same name already exists. The existing target is a static library
created in source directory "D:/Projects/trunk4/googletest". See
documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
googletest/cmake/internal_utils.cmake:172 (cxx_library_with_type)
googletest/CMakeLists.txt:91 (cxx_library)

CMake Error at googletest/CMakeLists.txt:92 (target_link_libraries):
Attempt to add link library "gtest" to target "gtest_main" which is not
built in this directory.

CMake Error at googletest/CMakeLists.txt:105 (install):
install TARGETS given target "gtest" which does not exist in this
directory.

The READEME.md in the new googlemock has a line "You must use the bundled version of Google Test when using Google Mock," which made sense in 1.6.  The error messages above would make sense if I'm grabbing a standalone version of gtest. Is there a version of 1.8 (or 1.7) that has the bundled version of gtest together with gmock in the same directory tree, or is the version in the separate directory that I get from the tar file what I should be using (in which case, that line may need editing)?


I haven't tried to build the new googlemock/googletest standalone yet under CMake, which will be one of the next things I try.  But ultimately, we need both of them building as static libraries with the rest of our CMake-driven system, so I want to check if I grabbed the wrong thing before I get too far into troubleshooting the CMake files included in the distribution.


Dave W.



David Wallace

unread,
Apr 18, 2017, 7:15:01 PM4/18/17
to Google C++ Mocking Framework
I found the problem - deleting the "add_subdirectory(googletest)" from my top-level CMake file gets rid of the error.  The googletest directory is still needed, but the googlemock directory has all the CMake commands it needs for building gtest as part of gmock.

Dave W.
Reply all
Reply to author
Forward
0 new messages