Skip to content

Commit

Permalink
feat: ability to skip installing mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
dbolduc committed Feb 27, 2024
1 parent aea43f6 commit c5b414f
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 59 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ cmake_dependent_option(
ON "GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS;BUILD_TESTING" OFF)
mark_as_advanced(GOOGLE_CLOUD_CPP_ENABLE_EXAMPLES)

option(GOOGLE_CLOUD_CPP_WITH_MOCKS
"Install the google-cloud-cpp mocking libraries." ON)
mark_as_advanced(GOOGLE_CLOUD_CPP_WITH_MOCKS)

# Add any subdirectories configured in the application.

# `docfx/` must be included before any library directories. The tool is used to
Expand Down
14 changes: 11 additions & 3 deletions cmake/GoogleCloudCppCommon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@ endfunction ()
function (google_cloud_cpp_install_mocks library display_name)
set(library_target "google_cloud_cpp_${library}")
set(mocks_target "google_cloud_cpp_${library}_mocks")

# Always install the mock headers. These are harmless, in the sense that
# they will not cause build failures in environments without GoogleTest. The
# same is not true about the mocking libraries which link GoogleTest.
google_cloud_cpp_install_headers("${mocks_target}"
"include/google/cloud/${library}")

if (NOT GOOGLE_CLOUD_CPP_WITH_MOCKS)
# Only install modules for the mock libraries if they are requested.
return()
endif ()
install(
EXPORT ${mocks_target}-targets
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${mocks_target}"
Expand All @@ -173,9 +184,6 @@ function (google_cloud_cpp_install_mocks library display_name)
EXPORT ${mocks_target}-targets
COMPONENT google_cloud_cpp_development)

google_cloud_cpp_install_headers("${mocks_target}"
"include/google/cloud/${library}")

google_cloud_cpp_add_pkgconfig(
${library}_mocks "${display_name} Mocks"
"Mocks for the ${display_name} C++ Client Library" "${library_target}"
Expand Down
57 changes: 30 additions & 27 deletions google/cloud/google_cloud_cpp_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -290,40 +290,43 @@ target_compile_options(google_cloud_cpp_mocks
INTERFACE ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG})
add_library(google-cloud-cpp::mocks ALIAS google_cloud_cpp_mocks)

# Export the CMake targets to make it easy to create configuration files.
install(
EXPORT google_cloud_cpp_mocks-targets
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_mocks"
COMPONENT google_cloud_cpp_development)

install(
TARGETS google_cloud_cpp_mocks
EXPORT google_cloud_cpp_mocks-targets
COMPONENT google_cloud_cpp_development)
install(
FILES ${google_cloud_cpp_mocks_hdrs}
DESTINATION "include/google/cloud/mocks"
COMPONENT google_cloud_cpp_development)

google_cloud_cpp_add_pkgconfig(
"mocks" "Google Cloud C++ Testing Library"
"Helpers for testing the Google Cloud C++ Client Libraries"
"google_cloud_cpp_common" "gmock_main")
if (GOOGLE_CLOUD_CPP_WITH_MOCKS)
# Export the CMake targets to make it easy to create configuration files.
install(
EXPORT google_cloud_cpp_mocks-targets
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_mocks"
COMPONENT google_cloud_cpp_development)

# Create and install the CMake configuration files.
configure_file("mocks-config.cmake.in" "google_cloud_cpp_mocks-config.cmake"
@ONLY)
write_basic_package_version_file(
"google_cloud_cpp_mocks-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY ExactVersion)
install(
TARGETS google_cloud_cpp_mocks
EXPORT google_cloud_cpp_mocks-targets
COMPONENT google_cloud_cpp_development)

install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_mocks-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_mocks-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_mocks"
COMPONENT google_cloud_cpp_development)
google_cloud_cpp_add_pkgconfig(
"mocks" "Google Cloud C++ Testing Library"
"Helpers for testing the Google Cloud C++ Client Libraries"
"google_cloud_cpp_common" "gmock_main")

# Create and install the CMake configuration files.
configure_file("mocks-config.cmake.in"
"google_cloud_cpp_mocks-config.cmake" @ONLY)
write_basic_package_version_file(
"google_cloud_cpp_mocks-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY ExactVersion)

install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_mocks-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_mocks-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_mocks"
COMPONENT google_cloud_cpp_development)
endif ()

if (BUILD_TESTING)
include(FindBenchmarkWithWorkarounds)
Expand Down
60 changes: 31 additions & 29 deletions google/cloud/storage/google_cloud_cpp_storage_grpc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -246,42 +246,44 @@ target_compile_options(google_cloud_cpp_storage_grpc_mocks
add_library(google-cloud-cpp::experimental-storage_grpc_mocks ALIAS
google_cloud_cpp_storage_grpc_mocks)

install(
EXPORT storage_grpc_mocks-targets
DESTINATION
"${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_storage_grpc_mocks"
COMPONENT google_cloud_cpp_development)

install(
TARGETS google_cloud_cpp_storage_grpc_mocks
EXPORT storage_grpc_mocks-targets
COMPONENT google_cloud_cpp_development)

install(
FILES ${google_cloud_cpp_storage_grpc_mocks_hdrs}
DESTINATION "include/google/cloud/storage/mocks"
COMPONENT google_cloud_cpp_development)

google_cloud_cpp_add_pkgconfig(
storage_grpc_mocks "Google Cloud Storage (gRPC) Mocks"
"Mocks for the Google Cloud Storage (gRPC) C++ Client Library"
"google_cloud_cpp_storage" " gmock_main")
if (GOOGLE_CLOUD_CPP_WITH_MOCKS)
install(
EXPORT storage_grpc_mocks-targets
DESTINATION
"${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_storage_grpc_mocks"
COMPONENT google_cloud_cpp_development)

# Create and install the CMake configuration files.
configure_file("mocks-config.cmake.in"
"google_cloud_cpp_storage_grpc_mocks-config.cmake" @ONLY)
write_basic_package_version_file(
"google_cloud_cpp_storage_grpc_mocks-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY ExactVersion)
install(
TARGETS google_cloud_cpp_storage_grpc_mocks
EXPORT storage_grpc_mocks-targets
COMPONENT google_cloud_cpp_development)

install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_storage_grpc_mocks-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_storage_grpc_mocks-config-version.cmake"
DESTINATION
"${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_storage_grpc_mocks"
COMPONENT google_cloud_cpp_development)
google_cloud_cpp_add_pkgconfig(
storage_grpc_mocks "Google Cloud Storage (gRPC) Mocks"
"Mocks for the Google Cloud Storage (gRPC) C++ Client Library"
"google_cloud_cpp_storage" " gmock_main")

# Create and install the CMake configuration files.
configure_file("mocks-config.cmake.in"
"google_cloud_cpp_storage_grpc_mocks-config.cmake" @ONLY)
write_basic_package_version_file(
"google_cloud_cpp_storage_grpc_mocks-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY ExactVersion)

install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_storage_grpc_mocks-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_storage_grpc_mocks-config-version.cmake"
DESTINATION
"${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_storage_grpc_mocks"
COMPONENT google_cloud_cpp_development)
endif ()

if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_STORAGE_ENABLE_GRPC)
# This is a bit weird, we add an additional link library to
Expand Down

0 comments on commit c5b414f

Please sign in to comment.