diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6ab80dee..a769419a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,44 +1,11 @@ -#------------------------------------------------------------------------------ -# Build the google test library - -# We compile Google Test ourselves instead of using pre-compiled libraries. -# See the Google Test FAQ "Why is it not recommended to install a -# pre-compiled copy of Google Test (for example, into /usr/local)?" -# at http://code.google.com/p/googletest/wiki/FAQ for more details. -add_library(gmock STATIC - gmock-gtest-all.cc gmock/gmock.h gtest/gtest.h gtest/gtest-spi.h) -target_compile_definitions(gmock PUBLIC GTEST_HAS_STD_WSTRING=1) -target_include_directories(gmock SYSTEM PUBLIC . gmock gtest) - -find_package(Threads) -if (Threads_FOUND) - target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT}) -else () - target_compile_definitions(gmock PUBLIC GTEST_HAS_PTHREAD=0) -endif () - -target_compile_definitions(gmock PUBLIC GTEST_LANG_CXX11=1) - -if (MSVC) - # Disable MSVC warnings of _CRT_INSECURE_DEPRECATE functions. - target_compile_definitions(gmock PRIVATE _CRT_SECURE_NO_WARNINGS) - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # Disable MSVC warnings of POSIX functions. - target_compile_options(gmock PUBLIC -Wno-deprecated-declarations) - endif () -endif () - -# Silence MSVC tr1 deprecation warning in gmock. -target_compile_definitions(gmock - PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING=1) +add_subdirectory(gtest) #------------------------------------------------------------------------------ # Build the actual library tests set(TEST_MAIN_SRC test-main.cc gtest-extra.cc gtest-extra.h util.cc) add_library(test-main STATIC ${TEST_MAIN_SRC}) -target_include_directories(test-main SYSTEM PUBLIC gtest gmock) -target_link_libraries(test-main gmock fmt) +target_link_libraries(test-main gtest fmt) include(CheckCXXCompilerFlag) @@ -75,7 +42,6 @@ function(add_fmt_test name) if (FMT_WERROR) target_compile_options(${name} PRIVATE ${WERROR_FLAG}) endif () - target_include_directories(${name} SYSTEM PUBLIC gtest gmock) add_test(NAME ${name} COMMAND ${name}) endfunction() @@ -122,8 +88,7 @@ if (NOT MSVC_STATIC_RUNTIME) posix-mock-test.cc ../src/format.cc ${TEST_MAIN_SRC}) target_include_directories( posix-mock-test PRIVATE ${PROJECT_SOURCE_DIR}/include) - target_link_libraries(posix-mock-test gmock) - target_include_directories(posix-mock-test SYSTEM PUBLIC gtest gmock) + target_link_libraries(posix-mock-test gtest) if (FMT_PEDANTIC) target_compile_options(posix-mock-test PRIVATE ${PEDANTIC_COMPILE_FLAGS}) endif () @@ -136,8 +101,7 @@ endif () add_fmt_executable(header-only-test header-only-test.cc header-only-test2.cc test-main.cc) -target_link_libraries(header-only-test gmock) -target_include_directories(header-only-test SYSTEM PUBLIC gtest gmock) +target_link_libraries(header-only-test gtest) if (TARGET fmt-header-only) target_link_libraries(header-only-test fmt-header-only) else () diff --git a/test/args-test.cc b/test/args-test.cc index 3fa4f70d..a7421bc5 100644 --- a/test/args-test.cc +++ b/test/args-test.cc @@ -7,7 +7,7 @@ #include "fmt/args.h" -#include "gtest.h" +#include "gtest/gtest.h" TEST(args_test, basic) { auto store = fmt::dynamic_format_arg_store(); diff --git a/test/assert-test.cc b/test/assert-test.cc index d2e5dd07..c74e617e 100644 --- a/test/assert-test.cc +++ b/test/assert-test.cc @@ -10,7 +10,7 @@ // For the license information refer to format.h. #include "fmt/core.h" -#include "gtest.h" +#include "gtest/gtest.h" TEST(assert_test, fail) { #if GTEST_HAS_DEATH_TEST diff --git a/test/compile-test.cc b/test/compile-test.cc index 31db499a..ec8f3a5a 100644 --- a/test/compile-test.cc +++ b/test/compile-test.cc @@ -15,7 +15,7 @@ #include "fmt/chrono.h" #include "fmt/compile.h" -#include "gmock.h" +#include "gmock/gmock.h" #include "gtest-extra.h" #include "util.h" diff --git a/test/core-test.cc b/test/core-test.cc index 3df04618..d5a70291 100644 --- a/test/core-test.cc +++ b/test/core-test.cc @@ -20,7 +20,7 @@ #include // std::string #include // std::is_same -#include "gmock.h" +#include "gmock/gmock.h" #if defined(FMT_COMPILE_TIME_CHECKS) && FMT_COMPILE_TIME_CHECKS # include "fmt/format.h" diff --git a/test/format-impl-test.cc b/test/format-impl-test.cc index 201aa03b..c332a8c2 100644 --- a/test/format-impl-test.cc +++ b/test/format-impl-test.cc @@ -15,7 +15,7 @@ #include "../src/format.cc" #include "fmt/printf.h" -#include "gmock.h" +#include "gmock/gmock.h" #include "gtest-extra.h" #include "util.h" diff --git a/test/format-test.cc b/test/format-test.cc index 1145ac3a..429cd437 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -30,7 +30,7 @@ #undef index -#include "gmock.h" +#include "gmock/gmock.h" #include "gtest-extra.h" #include "mock-allocator.h" #include "util.h" diff --git a/test/gtest-extra.h b/test/gtest-extra.h index 01c70ddb..001155ab 100644 --- a/test/gtest-extra.h +++ b/test/gtest-extra.h @@ -11,7 +11,7 @@ #include #include "fmt/os.h" -#include "gmock.h" +#include "gmock/gmock.h" #define FMT_TEST_THROW_(statement, expected_exception, expected_message, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt new file mode 100644 index 00000000..d82fb5c9 --- /dev/null +++ b/test/gtest/CMakeLists.txt @@ -0,0 +1,33 @@ +#------------------------------------------------------------------------------ +# Build the google test library + +# We compile Google Test ourselves instead of using pre-compiled libraries. +# See the Google Test FAQ "Why is it not recommended to install a +# pre-compiled copy of Google Test (for example, into /usr/local)?" +# at http://code.google.com/p/googletest/wiki/FAQ for more details. +add_library(gtest STATIC + gmock-gtest-all.cc gmock/gmock.h gtest/gtest.h gtest/gtest-spi.h) +target_compile_definitions(gtest PUBLIC GTEST_HAS_STD_WSTRING=1) +target_include_directories(gtest SYSTEM PUBLIC .) + +find_package(Threads) +if (Threads_FOUND) + target_link_libraries(gtest ${CMAKE_THREAD_LIBS_INIT}) +else () + target_compile_definitions(gtest PUBLIC GTEST_HAS_PTHREAD=0) +endif () + +target_compile_definitions(gtest PUBLIC GTEST_LANG_CXX11=1) + +if (MSVC) + # Disable MSVC warnings of _CRT_INSECURE_DEPRECATE functions. + target_compile_definitions(gtest PRIVATE _CRT_SECURE_NO_WARNINGS) + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # Disable MSVC warnings of POSIX functions. + target_compile_options(gtest PUBLIC -Wno-deprecated-declarations) + endif () +endif () + +# Silence MSVC tr1 deprecation warning in gmock. +target_compile_definitions(gtest + PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING=1) diff --git a/test/gmock-gtest-all.cc b/test/gtest/gmock-gtest-all.cc similarity index 100% rename from test/gmock-gtest-all.cc rename to test/gtest/gmock-gtest-all.cc diff --git a/test/gmock/gmock.h b/test/gtest/gmock/gmock.h similarity index 100% rename from test/gmock/gmock.h rename to test/gtest/gmock/gmock.h diff --git a/test/gtest/gtest-spi.h b/test/gtest/gtest/gtest-spi.h similarity index 100% rename from test/gtest/gtest-spi.h rename to test/gtest/gtest/gtest-spi.h diff --git a/test/gtest/gtest.h b/test/gtest/gtest/gtest.h similarity index 100% rename from test/gtest/gtest.h rename to test/gtest/gtest/gtest.h diff --git a/test/locale-test.cc b/test/locale-test.cc index db55923d..2ae9b3bc 100644 --- a/test/locale-test.cc +++ b/test/locale-test.cc @@ -9,7 +9,7 @@ #include -#include "gmock.h" +#include "gmock/gmock.h" using fmt::detail::max_value; diff --git a/test/mock-allocator.h b/test/mock-allocator.h index 513a62e8..d821bca4 100644 --- a/test/mock-allocator.h +++ b/test/mock-allocator.h @@ -9,7 +9,7 @@ #define FMT_MOCK_ALLOCATOR_H_ #include "fmt/format.h" -#include "gmock.h" +#include "gmock/gmock.h" template class mock_allocator { public: diff --git a/test/ostream-test.cc b/test/ostream-test.cc index 68094222..f97dd37f 100644 --- a/test/ostream-test.cc +++ b/test/ostream-test.cc @@ -24,7 +24,7 @@ template <> struct formatter : formatter { #include "fmt/ostream.h" #include "fmt/ranges.h" -#include "gmock.h" +#include "gmock/gmock.h" #include "gtest-extra.h" #include "util.h" diff --git a/test/posix-mock-test.cc b/test/posix-mock-test.cc index a9711c87..a40fbce9 100644 --- a/test/posix-mock-test.cc +++ b/test/posix-mock-test.cc @@ -26,7 +26,7 @@ # undef ERROR #endif -#include "gmock.h" +#include "gmock/gmock.h" #include "gtest-extra.h" #include "util.h" diff --git a/test/ranges-test.cc b/test/ranges-test.cc index 8fee3e14..c0396649 100644 --- a/test/ranges-test.cc +++ b/test/ranges-test.cc @@ -16,7 +16,7 @@ #include #include -#include "gtest.h" +#include "gtest/gtest.h" #if !FMT_GCC_VERSION || FMT_GCC_VERSION >= 601 # define FMT_RANGES_TEST_ENABLE_C_STYLE_ARRAY diff --git a/test/scan-test.cc b/test/scan-test.cc index 962de54c..dcac9337 100644 --- a/test/scan-test.cc +++ b/test/scan-test.cc @@ -11,7 +11,7 @@ #include -#include "gmock.h" +#include "gmock/gmock.h" #include "gtest-extra.h" TEST(ScanTest, ReadText) { diff --git a/test/std-format-test.cc b/test/std-format-test.cc index 916a7c5e..7b51a6ec 100644 --- a/test/std-format-test.cc +++ b/test/std-format-test.cc @@ -1,6 +1,6 @@ #include -#include "gtest.h" +#include "gtest/gtest.h" TEST(StdFormatTest, Escaping) { using namespace std; diff --git a/test/test-assert.h b/test/test-assert.h index 3406e1ba..da0ac321 100644 --- a/test/test-assert.h +++ b/test/test-assert.h @@ -10,7 +10,7 @@ #include -#include "gtest.h" +#include "gtest/gtest.h" class assertion_failure : public std::logic_error { public: diff --git a/test/test-main.cc b/test/test-main.cc index 8db257d6..b69cc500 100644 --- a/test/test-main.cc +++ b/test/test-main.cc @@ -7,7 +7,7 @@ #include -#include "gtest.h" +#include "gtest/gtest.h" #ifdef _WIN32 # include