external_gtest.cmake 2.74 KB
Newer Older
1
# ******************************************************************************
2
# Copyright 2017-2019 Intel Corporation
3
#
4 5 6
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10 11 12 13 14
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
15
# ******************************************************************************
16 17 18 19

# Enable ExternalProject CMake module
include(ExternalProject)

20
#------------------------------------------------------------------------------
21
# Download and install GoogleTest ...
22
#------------------------------------------------------------------------------
23 24

SET(GTEST_GIT_REPO_URL https://github.com/google/googletest.git)
25
SET(GTEST_GIT_LABEL release-1.8.1)
26

27 28 29
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
    if (DEFINED NGRAPH_USE_CXX_ABI)
        set(COMPILE_FLAGS "${COMPILE_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=${NGRAPH_USE_CXX_ABI}")
30 31 32 33 34
    endif()
endif()

set(GTEST_OUTPUT_DIR ${EXTERNAL_PROJECTS_ROOT}/gtest/build/googlemock/gtest)

35 36 37 38
if (APPLE OR LINUX)
    set(COMPILE_FLAGS -fPIC)
endif()

39 40 41 42 43 44 45 46 47
set(GTEST_CMAKE_ARGS
    -DCMAKE_CXX_FLAGS=${COMPILE_FLAGS}
)
if(WIN32)
    list(APPEND GTEST_CMAKE_ARGS
        -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE=${GTEST_OUTPUT_DIR}
        -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG=${GTEST_OUTPUT_DIR}
        -Dgtest_force_shared_crt=TRUE
    )
48 49
endif()

50 51 52 53 54 55 56 57
ExternalProject_Add(
    ext_gtest
    PREFIX gtest
    GIT_REPOSITORY ${GTEST_GIT_REPO_URL}
    GIT_TAG ${GTEST_GIT_LABEL}
    # Disable install step
    INSTALL_COMMAND ""
    UPDATE_COMMAND ""
58 59 60 61 62 63
    CMAKE_GENERATOR ${CMAKE_GENERATOR}
    CMAKE_GENERATOR_PLATFORM ${CMAKE_GENERATOR_PLATFORM}
    CMAKE_GENERATOR_TOOLSET ${CMAKE_GENERATOR_TOOLSET}
    CMAKE_ARGS
        ${NGRAPH_FORWARD_CMAKE_ARGS}
        ${GTEST_CMAKE_ARGS}
64 65 66
    BINARY_DIR "${EXTERNAL_PROJECTS_ROOT}/gtest/build"
    EXCLUDE_FROM_ALL TRUE
    )
67

68
#------------------------------------------------------------------------------
69

70
ExternalProject_Get_Property(ext_gtest SOURCE_DIR BINARY_DIR)
71

72
add_library(libgtest INTERFACE)
73
add_dependencies(libgtest ext_gtest)
74
target_include_directories(libgtest SYSTEM INTERFACE ${SOURCE_DIR}/googletest/include)
75 76 77 78 79 80
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(GTEST_LIB_NAME gtestd)
else()
    set(GTEST_LIB_NAME gtest)
endif()
target_link_libraries(libgtest INTERFACE ${GTEST_OUTPUT_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${GTEST_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})