0

I am try to install GoogleTest for testing a C++ project on macOS 10.12.

I have retrieved the latest source, release-1.8.0 and am having issues building the library. I have tried the following:

$ cd googletest-release-1.8.0 
$ mkdir build
$ cd build
$ cmake ..
$ make

There are no errors, however the lib files don't appear to be created anywhere that I can find.

What am I doing wrong here? I don't know too much about CMake.

arbass
  • 3
  • 3

2 Answers2

0

I just tried this on OS X; after the steps you listed, there's a subdirectory under build/ called googlemock/ containing libgmock.a and gtest/libgtest.a.

The headers are in the main folder under googletest/include/gtest/.

Alternatively, there's maybe some guidance in this older answer

Community
  • 1
  • 1
AS Mackay
  • 2,831
  • 9
  • 19
  • 25
0

You could use External Project like this:

<<CMakeLists.txt>>

cmake_minimum_required(VERSION 2.6)
project(myproject)

# Enable ExternalProject CMake module
include(ExternalProject)


# Download and install GoogleTest
ExternalProject_Add(
    gtest
    URL https://github.com/google/googletest/archive/release-1.8.0.zip
    PREFIX include/gtest
    # Disable install step
    INSTALL_COMMAND ""
)

# Create a libgtest target to be used as a dependency by test programs
add_library(libgtest IMPORTED STATIC GLOBAL)
add_dependencies(libgtest gtest)

# Set gtest properties
ExternalProject_Get_Property(gtest source_dir binary_dir)
set_target_properties(libgtest PROPERTIES
    IMPORTED_LOCATION "${binary_dir}/googlemock/gtest/libgtest.a"
    IMPORTED_LINK_INTERFACE_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}"
#   "INTERFACE_INCLUDE_DIRECTORIES" "${source_dir}/include"
)
# I couldn't make it work with INTERFACE_INCLUDE_DIRECTORIES
set(GTEST_LIB "${source_dir}/googletest/include")

# Create a libgmock target to be used as a dependency by test programs
add_library(libgmock IMPORTED STATIC GLOBAL)
add_dependencies(libgmock gmock)

include_directories(${GTEST_LIB} ${GMOCK_LIB})
add_executable(test_exec testmain.cpp someotherfile.cpp)
target_link_libraries(test_exec libgtest libgmock)

Should work.

theoden8
  • 773
  • 7
  • 16