Skip to content

Commit

Permalink
[DEV] Use googletest installed on the system when available
Browse files Browse the repository at this point in the history
Also set project version to 20.12.00
  • Loading branch information
BoubacarDiene committed Dec 9, 2020
1 parent 7a2ccaf commit b602bf2
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 30 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ cmake_minimum_required(VERSION 3.17.2)
# - version = <year>.<month>.<patch>
# - The project's name will be used to name the executable
project(networkservice
VERSION 20.05.00
VERSION 20.12.00
LANGUAGES CXX
DESCRIPTION "A native service to allow performing network\
commands more securely by using related tools\
Expand Down
13 changes: 13 additions & 0 deletions ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ ARG JSON_INSTALL_DIR=/usr/local/include
RUN wget --no-check-certificate ${JSON_DOWNLOAD_URL}/v${JSON_VERSION}/json.hpp \
-P ${JSON_INSTALL_DIR}

# Install googletest and googlemock
ARG GTEST_VERSION=1.10.0
ARG GTEST_DOWNLOAD_URL=https://github.com/google/googletest/archive
ARG GTEST_INSTALL_DIR=/opt

RUN wget --no-check-certificate ${GTEST_DOWNLOAD_URL}/release-${GTEST_VERSION}.tar.gz -O - \
| tar xzC ${GTEST_INSTALL_DIR}
RUN mkdir -p ${GTEST_INSTALL_DIR}/googletest-release-${GTEST_VERSION}/build \
&& cd ${GTEST_INSTALL_DIR}/googletest-release-${GTEST_VERSION}/build \
&& cmake .. \
&& make && make install \
&& cd ${GTEST_INSTALL_DIR} && rm -rf googletest-release-${GTEST_VERSION}

# Add user
ENV USERNAME networkservice-usr
ENV HOMEDIR /home/${USERNAME}
Expand Down
86 changes: 58 additions & 28 deletions cmake/frameworks/googletest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
# \date April 2020
#
# \brief A CMake script to fetch googletest (gtest, gmock) at
# configure time and also adds it to the main build
# configure time and also adds it to the main build.
# However, in case googletest is already present on the
# system, it will be used instead.
#
# \see https://cmake.org/cmake/help/latest/module/FetchContent.html
#
Expand All @@ -16,39 +18,67 @@
# Variables #
#################################################################

# Gtest and Gmock are built as static libraries so installing
# them is useless. We just need to link with those libraries (*.a
# files when compiling unit tests
#
# See build/_deps/googletest-src/CMakeLists.txt
set(INSTALL_GTEST OFF
CACHE BOOL "Disable installation of googletest")
set(GTEST_VERSION 1.10.0
CACHE STRING "Which release are you interested in?"
FORCE)

#################################################################
# Fetch #
# Install #
#################################################################

include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.10.0
)
# Find installed googletest package
find_package(GTest ${GTEST_VERSION} EXACT QUIET)

# After the following call, the CMake targets defined by googletest
# will be defined and available to the rest of the build
FetchContent_MakeAvailable(googletest)
if(GTest_FOUND)

#################################################################
# Search directories #
#################################################################
#---------------------------------------------------------------#
# Search directories #
#---------------------------------------------------------------#

# Add googletest headers to include directories
include_directories(SYSTEM ${GTEST_INCLUDE_DIRS})

# Add directory containing googletest/googlemock libraries
# to the linker's search path. pthread is required by gtest
link_libraries(${GTEST_LIBRARIES};pthread)

else()

#---------------------------------------------------------------#
# Fetch #
#---------------------------------------------------------------#

# Gtest and Gmock are built as static libraries so installing
# them is useless. We just need to link with those libraries (*.a
# files when compiling unit tests
#
# See build/_deps/googletest-src/CMakeLists.txt
set(INSTALL_GTEST OFF
CACHE BOOL "Disable installation of googletest")

include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-${GTEST_VERSION}
)

# After the following call, the CMake targets defined by googletest
# will be defined and available to the rest of the build
FetchContent_MakeAvailable(googletest)

#---------------------------------------------------------------#
# Search directories #
#---------------------------------------------------------------#

# Add googletest headers to include directories
include_directories(SYSTEM ${googletest_SOURCE_DIR}/googletest/include)

# Add googletest headers to include directories
include_directories(SYSTEM ${googletest_SOURCE_DIR}/googletest/include)
# Add googlemock headers to include directories
include_directories(SYSTEM ${googlemock_SOURCE_DIR}/googlemock/include)

# Add googlemock headers to include directories
include_directories(SYSTEM ${googlemock_SOURCE_DIR}/googlemock/include)
# Add directory containing googletest/googlemock static libraries
# to the linker's search path
link_directories(SYSTEM ${CMAKE_BINARY_DIR}/lib)

# Add directory containing googletest/googlemock static libraries
# to the linker's search path
link_directories(SYSTEM ${CMAKE_BINARY_DIR}/lib)
endif()
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ set(TESTS_INSTALL_DIR ${CMAKE_INSTALL_BINDIR}/tests)
# change the sign of the result [-Werror=sign-conversion]
#
# Add "-Wno-error=sign-conversion" to make the build pass.
message(STATUS "Downloading googletest...")
message(STATUS "Preparing googletest...")
set(CMAKE_CXX_FLAGS -Wno-error=sign-conversion)
include(${CMAKE_SOURCE_DIR}/cmake/frameworks/googletest.cmake)

Expand Down

0 comments on commit b602bf2

Please sign in to comment.