mirror of
https://github.com/KjellKod/g3log.git
synced 2024-12-12 10:23:50 +01:00
Use CMake to download GoogleTest as part of build (#355)
Having GoogleTest source in the project means we are likely using a stale version of test. This change is to use CMake to download GoogleTest as part of the build's configuration step.
This commit is contained in:
parent
639bfd7452
commit
68f3b174d9
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,5 @@
|
|||||||
syntax: glob
|
syntax: glob
|
||||||
sinks/*
|
sinks/*
|
||||||
3rdParty/*
|
|
||||||
build/*
|
build/*
|
||||||
nbproject/*
|
nbproject/*
|
||||||
build_clang
|
build_clang
|
||||||
|
BIN
3rdParty/gtest/gtest-1.7.0.zip
vendored
BIN
3rdParty/gtest/gtest-1.7.0.zip
vendored
Binary file not shown.
@ -64,9 +64,6 @@
|
|||||||
LINKER_LANGUAGE CXX
|
LINKER_LANGUAGE CXX
|
||||||
OUTPUT_NAME g3logger
|
OUTPUT_NAME g3logger
|
||||||
CLEAN_DIRECT_OUTPUT 1
|
CLEAN_DIRECT_OUTPUT 1
|
||||||
CXX_STANDARD 14
|
|
||||||
CXX_STANDARD_REQUIRED YES
|
|
||||||
CXX_EXTENSIONS NO
|
|
||||||
SOVERSION ${VERSION}
|
SOVERSION ${VERSION}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -54,15 +54,17 @@
|
|||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
||||||
cmake_minimum_required (VERSION 3.2)
|
cmake_minimum_required (VERSION 3.2)
|
||||||
ENABLE_LANGUAGE(CXX)
|
|
||||||
|
project (g3log CXX)
|
||||||
|
|
||||||
|
set (CMAKE_CXX_STANDARD 14)
|
||||||
|
set (CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
if(NOT CMAKE_BUILD_TYPE AND NOT (MSVC_IDE OR XCODE))
|
if(NOT CMAKE_BUILD_TYPE AND NOT (MSVC_IDE OR XCODE))
|
||||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type, one of: Release, Debug" FORCE)
|
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type, one of: Release, Debug" FORCE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
project (g3log)
|
|
||||||
|
|
||||||
message( STATUS "Build type: ${CMAKE_BUILD_TYPE}" )
|
message( STATUS "Build type: ${CMAKE_BUILD_TYPE}" )
|
||||||
message( STATUS "Configuration types: ${CMAKE_CONFIGURATION_TYPES}" )
|
message( STATUS "Configuration types: ${CMAKE_CONFIGURATION_TYPES}" )
|
||||||
|
|
||||||
|
16
CMakeLists.txt.in
Normal file
16
CMakeLists.txt.in
Normal file
@ -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 ""
|
||||||
|
)
|
||||||
|
|
@ -301,14 +301,6 @@ cmake .. -G "Visual Studio 15 2017"
|
|||||||
```
|
```
|
||||||
will use a Visual Studio 2017 solution generator, build g3log as a static library, headers and libraries will be installed to `C:\g3log` when installed from source, enable unit testing, but do not build fatal example.
|
will use a Visual Studio 2017 solution generator, build g3log as a static library, headers and libraries will be installed to `C:\g3log` when installed from source, enable unit testing, but do not build fatal example.
|
||||||
|
|
||||||
*Note*: To build the tests, you should uncompress `g3log/3rdParty/gtest/gtest-1.7.0.zip` first. On Linux, you may:
|
|
||||||
```
|
|
||||||
# Suppose you are still in `g3log/build`
|
|
||||||
pushd ../3rdParty/gtest
|
|
||||||
unzip gtest-1.7.0.zip
|
|
||||||
popd
|
|
||||||
```
|
|
||||||
|
|
||||||
MinGW users on Windows may find they should use a different generator:
|
MinGW users on Windows may find they should use a different generator:
|
||||||
```
|
```
|
||||||
cmake .. -G "MinGW Makefiles"
|
cmake .. -G "MinGW Makefiles"
|
||||||
@ -395,7 +387,7 @@ will install the g3log library to `CPACK_PACKAGING_INSTALL_PREFIX`.
|
|||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
By default, tests will not be built. To enable unit testing, you should turn on `ADD_G3LOG_UNIT_TEST`. Besides, you should uncompress `g3log/3rdParty/gtest/gtest-1.7.0.zip`(We talked about it in the `Configuring` section).
|
By default, tests will not be built. To enable unit testing, you should turn on `ADD_G3LOG_UNIT_TEST`.
|
||||||
|
|
||||||
Suppose the build process has completed, then you can run the tests with:
|
Suppose the build process has completed, then you can run the tests with:
|
||||||
```
|
```
|
||||||
|
@ -19,8 +19,6 @@ install:
|
|||||||
|
|
||||||
# scripts to run before build
|
# scripts to run before build
|
||||||
before_build:
|
before_build:
|
||||||
- cd c:\projects\g3log\3rdParty\gtest
|
|
||||||
- 7z x gtest-1.7.0.zip
|
|
||||||
- cd c:\projects\g3log\
|
- cd c:\projects\g3log\
|
||||||
- mkdir build
|
- mkdir build
|
||||||
- cd build
|
- cd build
|
||||||
|
@ -2,12 +2,11 @@
|
|||||||
|
|
||||||
set -ev
|
set -ev
|
||||||
set -x
|
set -x
|
||||||
unzip -o 3rdParty/gtest/gtest-1.7.0.zip -d 3rdParty/gtest
|
|
||||||
|
|
||||||
|
|
||||||
mkdir -p build_travis
|
mkdir -p build_travis
|
||||||
cd build_travis
|
cd build_travis
|
||||||
cmake -DCMAKE_CXX_FLAGS=-std=c++14 -DADD_G3LOG_BENCH_PERFORMANCE=ON -DADD_G3LOG_UNIT_TEST=ON -DCMAKE_INSTALL_PREFIX=./install -DCPACK_PACKAGING_INSTALL_PREFIX=/opt/g3log ..
|
cmake -DADD_G3LOG_BENCH_PERFORMANCE=ON -DADD_G3LOG_UNIT_TEST=ON -DCMAKE_INSTALL_PREFIX=./install -DCPACK_PACKAGING_INSTALL_PREFIX=/opt/g3log ..
|
||||||
cmake --build . --target install
|
cmake --build . --target install
|
||||||
|
|
||||||
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
|
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
|
||||||
|
@ -16,27 +16,47 @@
|
|||||||
# ----- 1) the performance tests were only thoroughly tested on Ubuntu, not windows-
|
# ----- 1) the performance tests were only thoroughly tested on Ubuntu, not windows-
|
||||||
# (g3log windows/linux, but Google's glog only on linux)
|
# (g3log windows/linux, but Google's glog only on linux)
|
||||||
#
|
#
|
||||||
# 2) The unit test were tested windows/linux,. but must be unzipped
|
# 2) The unit test were tested windows/linux
|
||||||
# before it can be "cmake'd" and compiled --- leaving it as OFF for now
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
||||||
|
|
||||||
# Unit test for g3log (cmake -DUSE_G3LOG_UNIT_TEST=ON ..)
|
# Unit test for g3log (cmake -DUSE_G3LOG_UNIT_TEST=ON ..)
|
||||||
# remember to unzip gtest at g3log/3rdParty/gtest
|
|
||||||
option (ADD_G3LOG_UNIT_TEST "g3log unit tests" OFF)
|
option (ADD_G3LOG_UNIT_TEST "g3log unit tests" OFF)
|
||||||
|
|
||||||
|
|
||||||
# 4. create the unit tests for g3log --- ONLY TESTED THE UNIT TEST ON LINUX
|
# 4. create the unit tests for g3log --- ONLY TESTED THE UNIT TEST ON LINUX
|
||||||
# =========================
|
# =========================
|
||||||
IF (ADD_G3LOG_UNIT_TEST)
|
IF (ADD_G3LOG_UNIT_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()
|
||||||
|
|
||||||
set(DIR_UNIT_TEST ${g3log_SOURCE_DIR}/test_unit)
|
set(DIR_UNIT_TEST ${g3log_SOURCE_DIR}/test_unit)
|
||||||
message( STATUS "-DADD_G3LOG_UNIT_TEST=ON" )
|
message( STATUS "-DADD_G3LOG_UNIT_TEST=ON" )
|
||||||
set(GTEST_DIR ${g3log_SOURCE_DIR}/3rdParty/gtest/gtest-1.7.0)
|
|
||||||
set(GTEST_INCLUDE_DIRECTORIES ${GTEST_DIR}/include ${GTEST_DIR} ${GTEST_DIR}/src)
|
|
||||||
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)
|
|
||||||
|
|
||||||
# obs see this: http://stackoverflow.com/questions/9589192/how-do-i-change-the-number-of-template-arguments-supported-by-msvcs-stdtupl
|
# obs see this: http://stackoverflow.com/questions/9589192/how-do-i-change-the-number-of-template-arguments-supported-by-msvcs-stdtupl
|
||||||
# and this: http://stackoverflow.com/questions/2257464/google-test-and-visual-studio-2010-rc
|
# and this: http://stackoverflow.com/questions/2257464/google-test-and-visual-studio-2010-rc
|
||||||
@ -63,7 +83,7 @@
|
|||||||
IF( NOT(MSVC))
|
IF( NOT(MSVC))
|
||||||
set_target_properties(${test} PROPERTIES COMPILE_FLAGS "-isystem -pthread ")
|
set_target_properties(${test} PROPERTIES COMPILE_FLAGS "-isystem -pthread ")
|
||||||
ENDIF( NOT(MSVC))
|
ENDIF( NOT(MSVC))
|
||||||
target_link_libraries(${test} g3logger gtest_170_lib)
|
target_link_libraries(${test} g3logger gtest_main)
|
||||||
add_test( ${test} ${test} )
|
add_test( ${test} ${test} )
|
||||||
ENDFOREACH(test)
|
ENDFOREACH(test)
|
||||||
|
|
||||||
@ -77,7 +97,7 @@
|
|||||||
add_executable(test_dynamic_loaded_shared_lib ${g3log_SOURCE_DIR}/test_main/test_main.cpp ${DIR_UNIT_TEST}/test_linux_dynamic_loaded_sharedlib.cpp)
|
add_executable(test_dynamic_loaded_shared_lib ${g3log_SOURCE_DIR}/test_main/test_main.cpp ${DIR_UNIT_TEST}/test_linux_dynamic_loaded_sharedlib.cpp)
|
||||||
set_target_properties(test_dynamic_loaded_shared_lib PROPERTIES COMPILE_DEFINITIONS "GTEST_HAS_TR1_TUPLE=0")
|
set_target_properties(test_dynamic_loaded_shared_lib PROPERTIES COMPILE_DEFINITIONS "GTEST_HAS_TR1_TUPLE=0")
|
||||||
set_target_properties(test_dynamic_loaded_shared_lib PROPERTIES COMPILE_DEFINITIONS "GTEST_HAS_RTTI=0")
|
set_target_properties(test_dynamic_loaded_shared_lib PROPERTIES COMPILE_DEFINITIONS "GTEST_HAS_RTTI=0")
|
||||||
target_link_libraries(test_dynamic_loaded_shared_lib ${G3LOG_LIBRARY} -ldl gtest_170_lib )
|
target_link_libraries(test_dynamic_loaded_shared_lib ${G3LOG_LIBRARY} -ldl gtest_main)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
ELSE()
|
ELSE()
|
||||||
message( STATUS "-DADD_G3LOG_UNIT_TEST=OFF" )
|
message( STATUS "-DADD_G3LOG_UNIT_TEST=OFF" )
|
||||||
|
Loading…
Reference in New Issue
Block a user