Skip to content

Commit

Permalink
cmake: update to work with recent upstream googletest build changes
Browse files Browse the repository at this point in the history
Summary:
Previously to use gmock you simply needed to link against libgmock_main.
However, googletest pull request #1339 was recently merged into upstream
googletest: google/googletest#1339

These changes now require explicitly linking against libgmock_main, libgmock,
and libgtest.

Reviewed By: yfeldblum

Differential Revision: D6794709

fbshipit-source-id: 03dcccec966e62240987ee0051dfa87be8614cca
  • Loading branch information
simpkins authored and facebook-github-bot committed Jan 24, 2018
1 parent da420c9 commit a963e27
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
43 changes: 34 additions & 9 deletions CMake/FindGMock.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,52 @@
#
# LIBGMOCK_DEFINES - List of defines when using libgmock.
# LIBGMOCK_INCLUDE_DIR - where to find gmock/gmock.h, etc.
# LIBGMOCK_LIBRARY - List of libraries when using libgmock.
# LIBGMOCK_LIBRARIES - List of libraries when using libgmock.
# LIBGMOCK_FOUND - True if libgmock found.


IF (LIBGMOCK_INCLUDE_DIR)
# Already in cache, be silent
SET(LIBGMOCK_FIND_QUIETLY TRUE)
ENDIF ()

FIND_PATH(LIBGMOCK_INCLUDE_DIR gmock/gmock.h)

FIND_LIBRARY(LIBGMOCK_LIBRARY gmock_main)
FIND_LIBRARY(LIBGMOCK_MAIN_LIBRARY gmock_main)
FIND_LIBRARY(LIBGMOCK_LIBRARY gmock)
FIND_LIBRARY(LIBGTEST_LIBRARY gtest)
set(LIBGMOCK_LIBRARIES
${LIBGMOCK_MAIN_LIBRARY}
${LIBGMOCK_LIBRARY}
${LIBGTEST_LIBRARY}
)

# There isn't currently an easy way to determine if a library was compiled as
# a shared library on Windows, so just assume we've been built against a shared
# build of gmock for now.
SET(LIBGMOCK_DEFINES "GTEST_LINKED_AS_SHARED_LIBRARY=1" CACHE STRING "")
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
# The GTEST_LINKED_AS_SHARED_LIBRARY macro must be set properly on Windows.
#
# There isn't currently an easy way to determine if a library was compiled as
# a shared library on Windows, so just assume we've been built against a
# shared build of gmock for now.
SET(LIBGMOCK_DEFINES "GTEST_LINKED_AS_SHARED_LIBRARY=1" CACHE STRING "")
endif()

# handle the QUIETLY and REQUIRED arguments and set LIBGMOCK_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBGMOCK DEFAULT_MSG LIBGMOCK_DEFINES LIBGMOCK_LIBRARY LIBGMOCK_INCLUDE_DIR)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
LIBGMOCK
DEFAULT_MSG
LIBGMOCK_MAIN_LIBRARY
LIBGMOCK_LIBRARY
LIBGTEST_LIBRARY
LIBGMOCK_LIBRARIES
LIBGMOCK_INCLUDE_DIR
)

MARK_AS_ADVANCED(LIBGMOCK_DEFINES LIBGMOCK_LIBRARY LIBGMOCK_INCLUDE_DIR)
MARK_AS_ADVANCED(
LIBGMOCK_DEFINES
LIBGMOCK_MAIN_LIBRARY
LIBGMOCK_LIBRARY
LIBGTEST_LIBRARY
LIBGMOCK_LIBRARIES
LIBGMOCK_INCLUDE_DIR
)
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ if (BUILD_TESTS)
Boost::thread
follybenchmark
folly
${LIBGMOCK_LIBRARY}
${LIBGMOCK_LIBRARIES}
)
apply_folly_compile_options_to_target(folly_test_support)

Expand Down

0 comments on commit a963e27

Please sign in to comment.