mirror of
https://github.com/google/googletest.git
synced 2026-07-30 16:26:24 +08:00
Compare commits
3 Commits
87d5176d17
...
c2d6ca32a2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2d6ca32a2 | ||
|
|
a0f06a70e3 | ||
|
|
a073979d8f |
@ -176,14 +176,6 @@ function(cxx_library_with_type name type cxx_flags)
|
||||
set_target_properties(${name}
|
||||
PROPERTIES
|
||||
COMPILE_FLAGS "${cxx_flags}")
|
||||
# Set the output directory for build artifacts.
|
||||
set_target_properties(${name}
|
||||
PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
|
||||
PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
|
||||
COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
|
||||
# Make PDBs match library name.
|
||||
get_target_property(pdb_debug_postfix ${name} DEBUG_POSTFIX)
|
||||
set_target_properties(${name}
|
||||
@ -330,20 +322,37 @@ function(install_project)
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
# Install PDBs.
|
||||
# Install PDBs. Use the target property if set, otherwise fall back to
|
||||
# the CMake variable, and if neither is set skip PDB install.
|
||||
foreach(t ${ARGN})
|
||||
get_target_property(t_pdb_name ${t} COMPILE_PDB_NAME)
|
||||
get_target_property(t_pdb_name_debug ${t} COMPILE_PDB_NAME_DEBUG)
|
||||
get_target_property(t_pdb_output_directory ${t} COMPILE_PDB_OUTPUT_DIRECTORY)
|
||||
if(t_pdb_output_directory MATCHES "-NOTFOUND$")
|
||||
if(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY)
|
||||
set(t_pdb_output_directory "${CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY}")
|
||||
else()
|
||||
set(t_pdb_output_directory "")
|
||||
endif()
|
||||
endif()
|
||||
get_target_property(t_shared_pdb_name ${t} PDB_NAME)
|
||||
get_target_property(t_shared_pdb_name_debug ${t} PDB_NAME_DEBUG)
|
||||
get_target_property(t_shared_pdb_output_directory ${t} PDB_OUTPUT_DIRECTORY)
|
||||
install(FILES
|
||||
"$<$<STREQUAL:$<TARGET_PROPERTY:${t},TYPE>,STATIC_LIBRARY>:${t_pdb_output_directory}/\${CMAKE_INSTALL_CONFIG_NAME}/$<IF:$<CONFIG:Debug>,${t_pdb_name_debug},${t_pdb_name}>.pdb>"
|
||||
"$<$<STREQUAL:$<TARGET_PROPERTY:${t},TYPE>,SHARED_LIBRARY>:${t_shared_pdb_output_directory}/\${CMAKE_INSTALL_CONFIG_NAME}/$<IF:$<CONFIG:Debug>,${t_shared_pdb_name_debug},${t_shared_pdb_name}>.pdb>"
|
||||
COMPONENT "${PROJECT_NAME}"
|
||||
DESTINATION $<IF:$<STREQUAL:$<TARGET_PROPERTY:${t},TYPE>,STATIC_LIBRARY>,${CMAKE_INSTALL_LIBDIR},${CMAKE_INSTALL_BINDIR}>
|
||||
OPTIONAL)
|
||||
if(t_shared_pdb_output_directory MATCHES "-NOTFOUND$")
|
||||
if(CMAKE_PDB_OUTPUT_DIRECTORY)
|
||||
set(t_shared_pdb_output_directory "${CMAKE_PDB_OUTPUT_DIRECTORY}")
|
||||
else()
|
||||
set(t_shared_pdb_output_directory "")
|
||||
endif()
|
||||
endif()
|
||||
if(t_pdb_output_directory OR t_shared_pdb_output_directory)
|
||||
install(FILES
|
||||
"$<$<STREQUAL:$<TARGET_PROPERTY:${t},TYPE>,STATIC_LIBRARY>:${t_pdb_output_directory}/\${CMAKE_INSTALL_CONFIG_NAME}/$<IF:$<CONFIG:Debug>,${t_pdb_name_debug},${t_pdb_name}>.pdb>"
|
||||
"$<$<STREQUAL:$<TARGET_PROPERTY:${t},TYPE>,SHARED_LIBRARY>:${t_shared_pdb_output_directory}/\${CMAKE_INSTALL_CONFIG_NAME}/$<IF:$<CONFIG:Debug>,${t_shared_pdb_name_debug},${t_shared_pdb_name}>.pdb>"
|
||||
COMPONENT "${PROJECT_NAME}"
|
||||
DESTINATION $<IF:$<STREQUAL:$<TARGET_PROPERTY:${t},TYPE>,STATIC_LIBRARY>,${CMAKE_INSTALL_LIBDIR},${CMAKE_INSTALL_BINDIR}>
|
||||
OPTIONAL)
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
# Configure and install pkgconfig files.
|
||||
|
||||
@ -945,13 +945,13 @@ template <typename T>
|
||||
class [[nodiscard]] UniversalPrinter<std::optional<T>> {
|
||||
public:
|
||||
static void Print(const std::optional<T>& value, ::std::ostream* os) {
|
||||
*os << '(';
|
||||
if (!value) {
|
||||
*os << "nullopt";
|
||||
UniversalPrint(std::nullopt, os);
|
||||
} else {
|
||||
*os << '(';
|
||||
UniversalPrint(*value, os);
|
||||
*os << ')';
|
||||
}
|
||||
*os << ')';
|
||||
}
|
||||
};
|
||||
|
||||
@ -961,27 +961,38 @@ class [[nodiscard]] UniversalPrinter<std::nullopt_t> {
|
||||
static void Print(std::nullopt_t, ::std::ostream* os) { *os << "(nullopt)"; }
|
||||
};
|
||||
|
||||
struct UniversalPrinterVisitor {
|
||||
template <typename T>
|
||||
void operator()(const T& arg) const {
|
||||
*os << "'" << GetTypeName<T>() << "(index = " << index << ")' with value ";
|
||||
UniversalPrint(arg, os);
|
||||
}
|
||||
::std::ostream* os;
|
||||
std::size_t index;
|
||||
};
|
||||
|
||||
// Printer for std::variant
|
||||
template <typename... T>
|
||||
class [[nodiscard]] UniversalPrinter<std::variant<T...>> {
|
||||
public:
|
||||
static void Print(const std::variant<T...>& value, ::std::ostream* os) {
|
||||
*os << '(';
|
||||
std::visit(Visitor{os, value.index()}, value);
|
||||
*os << ')';
|
||||
}
|
||||
|
||||
private:
|
||||
struct Visitor {
|
||||
template <typename U>
|
||||
void operator()(const U& u) const {
|
||||
*os << "'" << GetTypeName<U>() << "(index = " << index
|
||||
<< ")' with value ";
|
||||
UniversalPrint(u, os);
|
||||
if (value.valueless_by_exception()) {
|
||||
*os << "(valueless)";
|
||||
} else {
|
||||
*os << '(';
|
||||
std::visit(UniversalPrinterVisitor{os, value.index()}, value);
|
||||
*os << ')';
|
||||
}
|
||||
::std::ostream* os;
|
||||
std::size_t index;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// Printer for std::monostate
|
||||
template <>
|
||||
class [[nodiscard]] UniversalPrinter<std::monostate> {
|
||||
public:
|
||||
static void Print(std::monostate, ::std::ostream* os) {
|
||||
*os << "(monostate)";
|
||||
}
|
||||
};
|
||||
|
||||
// UniversalPrintArray(begin, len, os) prints an array of 'len'
|
||||
|
||||
@ -2030,6 +2030,26 @@ TEST(PrintOneofTest, Basic) {
|
||||
PrintToString(Type(NonPrintable{})));
|
||||
}
|
||||
|
||||
TEST(PrintVariantTest, Monostate) {
|
||||
EXPECT_EQ("(monostate)", PrintToString(std::monostate()));
|
||||
|
||||
#if GTEST_HAS_EXCEPTIONS
|
||||
struct ThrowOnMove {
|
||||
ThrowOnMove() = default;
|
||||
ThrowOnMove(ThrowOnMove&& other) { *this = std::move(other); }
|
||||
ThrowOnMove& operator=(ThrowOnMove&&) {
|
||||
(void)std::vector<bool>().at(0);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
std::variant<std::monostate, ThrowOnMove> v = std::monostate();
|
||||
EXPECT_EQ("('std::monostate(index = 0)' with value (monostate))",
|
||||
PrintToString(v));
|
||||
EXPECT_THROW(v = ThrowOnMove(), std::out_of_range);
|
||||
EXPECT_EQ("(valueless)", PrintToString(v));
|
||||
#endif
|
||||
}
|
||||
|
||||
#if GTEST_INTERNAL_HAS_COMPARE_LIB
|
||||
TEST(PrintOrderingTest, Basic) {
|
||||
EXPECT_EQ("(less)", PrintToString(std::strong_ordering::less));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user