Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CMake to download GoogleTest as part of build #94

Merged
merged 2 commits into from
Jun 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed 3rdparty/gtest-1.7.0.zip
Binary file not shown.
37 changes: 36 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,43 @@

cmake_minimum_required(VERSION 3.2 )

project(g3sink CXX)

set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_STANDARD_REQUIRED ON)

option (BUILD_STATIC "Building sinks as static libraries. Linking with static g3log library" OFF)
option (BUILD_TEST "Build the unit tests" ON)

add_subdirectory(syslog)
add_subdirectory(logrotate)
add_subdirectory(snippets)

if(BUILD_TEST)
# Download and unpack googletest at configure time
configure_file(CMakeLists.txt.in
googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
execute_process(COMMAND ${CMAKE_COMMAND} --build .
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )

# Prevent GoogleTest from overriding our compiler/linker options
# when building with Visual Studio
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

# Add googletest directly to our build. This adds
# the following targets: gtest, gtest_main, gmock
# and gmock_main
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
${CMAKE_BINARY_DIR}/googletest-build)

# The gtest/gmock targets carry header search path
# dependencies automatically when using CMake 2.8.11 or
# later. Otherwise we have to add them here ourselves.
if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories("${gtest_SOURCE_DIR}/include"
"${gmock_SOURCE_DIR}/include")
endif()

enable_testing()
endif (BUILD_TEST)
16 changes: 16 additions & 0 deletions CMakeLists.txt.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 2.8.2)

project(googletest-download NONE)

include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG master
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)

6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,11 @@ in Ubuntu it can be installed with `sudo apt-get install zlib1g-dev`. Please see
### Building with unit tests added using CMake option "-DBUILD_TEST=ON"
```
cd g3sinks
cd 3rdparty
unzip gtest-1.7.0.zip
cd ..
cd logrotate
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/usr/local/ -DBOOST_ROOT=/usr/local cmake -DBUILD_TEST=ON ..
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/usr/local/ -DBOOST_ROOT=/usr/local -DBUILD_TEST=ON ..
make -j
```

### Executing the unit tests
```
Expand Down
3 changes: 0 additions & 3 deletions logrotate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ SET_TARGET_PROPERTIES(${LIBRARY_TO_BUILD} PROPERTIES
LINKER_LANGUAGE CXX
OUTPUT_NAME ${LIBRARY_TO_BUILD}
CLEAN_DIRECT_OUTPUT 1
CXX_STANDARD 14
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
SOVERSION ${VERSION}
)

Expand Down
5 changes: 1 addition & 4 deletions logrotate/packaging/g3logrotate.spec
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ fi
# SKIP_BUILD_RPATH, CMAKE_SKIP_BUILD_RPATH,
PATH=%{install_root}/bin:$PATH
cd %{name}-%{version}
cd 3rdparty
unzip -u gtest-1.7.0.zip
cd ../logrotate
mkdir -p build
cd build
if [ -z "$BOOST_DIR" ] ; then
Expand All @@ -40,7 +37,7 @@ fi
rm -f CMakeCache.txt


%{install_root}/bin/cmake -DADD_LOGROTATE_UNIT_TEST=ON -DCMAKE_PREFIX_PATH=%{install_root} -DCMAKE_CXX_COMPILER_ARG1:STRING=' -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -Wall -Werror -fPIC -Ofast -m64 -Wl,-rpath -Wl,. -Wl,-rpath -Wl,%{install_root}/lib -Wl,-rpath -Wl,%{install_root}/lib64 ' -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=ON -DCMAKE_CXX_COMPILER=%{install_root}/bin/g++ ..
%{install_root}/bin/cmake -DBUILD_TEST=ON -DCMAKE_PREFIX_PATH=%{install_root} -DCMAKE_CXX_COMPILER_ARG1:STRING=' -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -Wall -Werror -fPIC -Ofast -m64 -Wl,-rpath -Wl,. -Wl,-rpath -Wl,%{install_root}/lib -Wl,-rpath -Wl,%{install_root}/lib64 ' -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=ON -DCMAKE_CXX_COMPILER=%{install_root}/bin/g++ ..

make -j6
./UnitTestRunner
Expand Down
21 changes: 5 additions & 16 deletions logrotate/test/Test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,10 @@
# 2015, April 30, @author Kjell.Hedstrom
# =====================================================

option (ADD_LOGROTATE_UNIT_TEST "logrotate unit tests" OFF)

IF (ADD_LOGROTATE_UNIT_TEST)

IF (BUILD_TEST)
include_directories(${CMAKE_PREFIX_PATH}/include)
MESSAGE("Test include : : " ${CMAKE_PREFIX_PATH}/include " : lib : " ${g3logger})


set(GTEST_DIR ${DIR_3RDPARTY}/gtest-1.7.0)
set(GTEST_INCLUDE_DIRECTORIES ${GTEST_DIR}/include ${GTEST_DIR} ${GTEST_DIR}/src)
MESSAGE( "Attempt to build gtest. gtest directory: " ${GTEST_DIR})
include_directories(${GTEST_INCLUDE_DIRECTORIES})
add_library(gtest_170_lib ${GTEST_DIR}/src/gtest-all.cc)
set_target_properties(gtest_170_lib PROPERTIES COMPILE_DEFINITIONS "GTEST_HAS_RTTI=0")
enable_testing(true)
include_directories(test)
file(GLOB TEST_SRC_FILES "test/*.cpp" "test/*.h" "test/*.hpp")

Expand All @@ -28,12 +17,12 @@ IF (ADD_LOGROTATE_UNIT_TEST)
set_target_properties(UnitTestRunner PROPERTIES COMPILE_DEFINITIONS "GTEST_HAS_RTTI=0")

IF (MSVC)
target_link_libraries(UnitTestRunner ${LIBRARY_TO_BUILD} ${g3logger} gtest_170_lib dbghelp ${PLATFORM_LINK_LIBRIES})
target_link_libraries(UnitTestRunner ${LIBRARY_TO_BUILD} ${g3logger} gtest_main dbghelp ${PLATFORM_LINK_LIBRIES})
ELSE()
SET(CMAKE_CXX_FLAGS "-Wall -Wno-sign-compare -rdynamic -Wunused -std=c++14 -pthread -D_GLIBCXX_USE_NANOSLEEP")

TARGET_LINK_LIBRARIES(UnitTestRunner ${LIBRARY_TO_BUILD} ${g3logger} gtest_170_lib ${PLATFORM_LINK_LIBRIES})
TARGET_LINK_LIBRARIES(UnitTestRunner ${LIBRARY_TO_BUILD} ${g3logger} gtest_main ${PLATFORM_LINK_LIBRIES})
ENDIF()
ELSE()
MESSAGE("-DADD_LOGROTATE_UNIT_TEST=OFF")
ENDIF (ADD_LOGROTATE_UNIT_TEST)
MESSAGE("-DBUILD_TEST=OFF")
ENDIF (BUILD_TEST)
5 changes: 1 addition & 4 deletions scripts/buildAndRunTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ function install_g3log () {
mkdir g3log-install && cd g3log-install
git clone https://github.com/KjellKod/g3log.git -b master
cd g3log
unzip -o 3rdParty/gtest/gtest-1.7.0.zip -d 3rdParty/gtest
mkdir -p build_travis
cd build_travis
cmake -DADD_G3LOG_UNIT_TEST=ON ..
Expand All @@ -52,9 +51,7 @@ fi
cd $pwd
mkdir build

cd 3rdparty && unzip gtest-1.7.0.zip
cd $pwd
cd build && cmake -DADD_LOGROTATE_UNIT_TEST=ON ..
cd build && cmake -DBUILD_TEST=ON ..

make -j
echo "FINISHED BUILDING LOGROTATE & SYSLOG"
Expand Down
3 changes: 0 additions & 3 deletions snippets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ cmake_minimum_required(VERSION 3.2 )
LINKER_LANGUAGE CXX
OUTPUT_NAME g3log_snippets_file_example
CLEAN_DIRECT_OUTPUT 1
CXX_STANDARD 14
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
target_include_directories(g3log_snippets_file_example PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
target_link_libraries(g3log_snippets_file_example g3logger)
Expand Down
3 changes: 0 additions & 3 deletions syslog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ SET_TARGET_PROPERTIES(g3log_syslog PROPERTIES
LINKER_LANGUAGE CXX
OUTPUT_NAME g3log_syslog
CLEAN_DIRECT_OUTPUT 1
CXX_STANDARD 14
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
${g3log_syslogVersion}
)
target_link_libraries(g3log_syslog PUBLIC g3logger)
Expand Down