diff --git a/.gitignore b/.gitignore index 5fb7b4f..bffe4ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ syntax: glob sinks/* -3rdParty/* build/* nbproject/* build_clang diff --git a/3rdParty/gtest/gtest-1.7.0.zip b/3rdParty/gtest/gtest-1.7.0.zip deleted file mode 100644 index 86f5fd0..0000000 Binary files a/3rdParty/gtest/gtest-1.7.0.zip and /dev/null differ diff --git a/Build.cmake b/Build.cmake index d57845b..2cea720 100644 --- a/Build.cmake +++ b/Build.cmake @@ -64,9 +64,6 @@ LINKER_LANGUAGE CXX OUTPUT_NAME g3logger CLEAN_DIRECT_OUTPUT 1 - CXX_STANDARD 14 - CXX_STANDARD_REQUIRED YES - CXX_EXTENSIONS NO SOVERSION ${VERSION} ) diff --git a/CMakeLists.txt b/CMakeLists.txt index 183b2eb..ffcc480 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,15 +54,17 @@ # ============================================================================ 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)) set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type, one of: Release, Debug" FORCE) endif() -project (g3log) - message( STATUS "Build type: ${CMAKE_BUILD_TYPE}" ) message( STATUS "Configuration types: ${CMAKE_CONFIGURATION_TYPES}" ) diff --git a/CMakeLists.txt.in b/CMakeLists.txt.in new file mode 100644 index 0000000..4b14f8d --- /dev/null +++ b/CMakeLists.txt.in @@ -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 "" +) + diff --git a/README.markdown b/README.markdown index ed3900f..fd02e95 100644 --- a/README.markdown +++ b/README.markdown @@ -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. -*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: ``` cmake .. -G "MinGW Makefiles" @@ -395,7 +387,7 @@ will install the g3log library to `CPACK_PACKAGING_INSTALL_PREFIX`. ## 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: ``` diff --git a/appveyor.yml b/appveyor.yml index be33757..26d0596 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -19,8 +19,6 @@ install: # scripts to run before build before_build: - - cd c:\projects\g3log\3rdParty\gtest - - 7z x gtest-1.7.0.zip - cd c:\projects\g3log\ - mkdir build - cd build diff --git a/scripts/buildAndRunTests.sh b/scripts/buildAndRunTests.sh index 898dead..04f2a81 100755 --- a/scripts/buildAndRunTests.sh +++ b/scripts/buildAndRunTests.sh @@ -2,12 +2,11 @@ set -ev set -x -unzip -o 3rdParty/gtest/gtest-1.7.0.zip -d 3rdParty/gtest mkdir -p 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 if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then diff --git a/test_unit/Test.cmake b/test_unit/Test.cmake index bf94dd5..9338f0b 100644 --- a/test_unit/Test.cmake +++ b/test_unit/Test.cmake @@ -16,27 +16,47 @@ # ----- 1) the performance tests were only thoroughly tested on Ubuntu, not windows- # (g3log windows/linux, but Google's glog only on linux) # - # 2) The unit test were tested windows/linux,. but must be unzipped - # before it can be "cmake'd" and compiled --- leaving it as OFF for now + # 2) The unit test were tested windows/linux # ============================================================================ # 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) # 4. create the unit tests for g3log --- ONLY TESTED THE UNIT TEST ON LINUX # ========================= 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) 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 # and this: http://stackoverflow.com/questions/2257464/google-test-and-visual-studio-2010-rc @@ -63,7 +83,7 @@ IF( NOT(MSVC)) set_target_properties(${test} PROPERTIES COMPILE_FLAGS "-isystem -pthread ") ENDIF( NOT(MSVC)) - target_link_libraries(${test} g3logger gtest_170_lib) + target_link_libraries(${test} g3logger gtest_main) add_test( ${test} ${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) 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") - 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() ELSE() message( STATUS "-DADD_G3LOG_UNIT_TEST=OFF" )