Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cmake): use template for config.cmake.in #12487

Merged
merged 3 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions cmake/GoogleCloudCppLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@
# `cloud_speech_protos`) that must continue to exist. We add interface
# libraries for these, which link to the desired proto library. See #8022 for
# more details.
# * CROSS_LIB_DEPS: a list of client libraries which this library depends on.
#
function (google_cloud_cpp_add_ga_grpc_library library display_name)
cmake_parse_arguments(
_opt "EXPERIMENTAL" ""
"ADDITIONAL_PROTO_LISTS;BACKWARDS_COMPAT_PROTO_TARGETS" ${ARGN})
"ADDITIONAL_PROTO_LISTS;BACKWARDS_COMPAT_PROTO_TARGETS;CROSS_LIB_DEPS"
${ARGN})
set(library_target "google_cloud_cpp_${library}")
set(mocks_target "google_cloud_cpp_${library}_mocks")
set(protos_target "google_cloud_cpp_${library}_protos")
Expand All @@ -57,6 +59,11 @@ function (google_cloud_cpp_add_ga_grpc_library library display_name)
endif ()
set(DOXYGEN_EXCLUDE_SYMBOLS "internal")
set(DOXYGEN_EXAMPLE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/quickstart")
unset(GOOGLE_CLOUD_CPP_DOXYGEN_EXTRA_INCLUDES)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting with CMake 3.12 we can use list(TRANSFORM ...):

https://cmake.org/cmake/help/latest/command/list.html#transform

set(GOOGLE_CLOUD_CPP_DOXYGEN_EXTRA_INCLUDES "${opt_CROSS_LIB_DEPS}")
list(TRANSFORM
      GOOGLE_CLOUD_CPP_DOXYGEN_EXTRA_INCLUDES
      PREPEND "${PROJECT_BINARY_DIR}/google/cloud/")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, nice. Done.

foreach (lib IN LISTS _opt_CROSS_LIB_DEPS)
list(APPEND GOOGLE_CLOUD_CPP_DOXYGEN_EXTRA_INCLUDES
"${PROJECT_BINARY_DIR}/google/cloud/${lib}")
endforeach ()

unset(mocks_globs)
unset(source_globs)
Expand Down Expand Up @@ -201,7 +208,16 @@ function (google_cloud_cpp_add_ga_grpc_library library display_name)

# Create and install the CMake configuration files.
include(CMakePackageConfigHelpers)
configure_file("config.cmake.in" "${library_target}-config.cmake" @ONLY)
set(GOOGLE_CLOUD_CPP_CONFIG_LIBRARY "${library_target}")
unset(find_dependencies)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, but I am skeptical as to whether this one was an improvement. I briefly explored list(TRANSFORM ... REPLACE ...), but gave up.

foreach (lib IN LISTS _opt_CROSS_LIB_DEPS)
list(APPEND find_dependencies
"find_dependency(google_cloud_cpp_${lib})")
endforeach ()
string(JOIN "\n" GOOGLE_CLOUD_CPP_ADDITIONAL_FIND_DEPENDENCIES
${find_dependencies})
configure_file("${PROJECT_SOURCE_DIR}/cmake/templates/config.cmake.in"
"${library_target}-config.cmake" @ONLY)
write_basic_package_version_file(
"${library_target}-config-version.cmake"
VERSION ${PROJECT_VERSION}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ find_dependency(google_cloud_cpp_googleapis)
find_dependency(google_cloud_cpp_common)
find_dependency(google_cloud_cpp_grpc_utils)
find_dependency(absl)
@GOOGLE_CLOUD_CPP_ADDITIONAL_FIND_DEPENDENCIES@

include("${CMAKE_CURRENT_LIST_DIR}/google_cloud_cpp_alloydb-targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/@GOOGLE_CLOUD_CPP_CONFIG_LIBRARY@-targets.cmake")
22 changes: 0 additions & 22 deletions google/cloud/accessapproval/config.cmake.in

This file was deleted.

22 changes: 0 additions & 22 deletions google/cloud/accesscontextmanager/config.cmake.in

This file was deleted.

22 changes: 0 additions & 22 deletions google/cloud/advisorynotifications/config.cmake.in

This file was deleted.

22 changes: 0 additions & 22 deletions google/cloud/aiplatform/config.cmake.in

This file was deleted.

22 changes: 0 additions & 22 deletions google/cloud/apigateway/config.cmake.in

This file was deleted.

22 changes: 0 additions & 22 deletions google/cloud/apigeeconnect/config.cmake.in

This file was deleted.

22 changes: 0 additions & 22 deletions google/cloud/apikeys/config.cmake.in

This file was deleted.

22 changes: 0 additions & 22 deletions google/cloud/appengine/config.cmake.in

This file was deleted.

22 changes: 0 additions & 22 deletions google/cloud/artifactregistry/config.cmake.in

This file was deleted.

9 changes: 4 additions & 5 deletions google/cloud/asset/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ include(GoogleCloudCppLibrary)

set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "" "v1/")

set(GOOGLE_CLOUD_CPP_DOXYGEN_EXTRA_INCLUDES
"${PROJECT_BINARY_DIR}/google/cloud/accesscontextmanager"
"${PROJECT_BINARY_DIR}/google/cloud/osconfig")

google_cloud_cpp_add_ga_grpc_library(
asset
"Cloud Asset API"
# orgpolicy/v**1** is used *indirectly* by google/cloud/asset, therefore it
# does not appear in protolists/asset.list. In addition, it is not compiled
# by any other library. So, added manually.
ADDITIONAL_PROTO_LISTS
"${EXTERNAL_GOOGLEAPIS_SOURCE}/google/cloud/orgpolicy/v1/orgpolicy.proto")
"${EXTERNAL_GOOGLEAPIS_SOURCE}/google/cloud/orgpolicy/v1/orgpolicy.proto"
CROSS_LIB_DEPS
"accesscontextmanager"
"osconfig")

if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
add_executable(asset_quickstart "quickstart/quickstart.cc")
Expand Down
24 changes: 0 additions & 24 deletions google/cloud/asset/config.cmake.in

This file was deleted.

22 changes: 0 additions & 22 deletions google/cloud/assuredworkloads/config.cmake.in

This file was deleted.

22 changes: 0 additions & 22 deletions google/cloud/automl/config.cmake.in

This file was deleted.

22 changes: 0 additions & 22 deletions google/cloud/baremetalsolution/config.cmake.in

This file was deleted.

22 changes: 0 additions & 22 deletions google/cloud/batch/config.cmake.in

This file was deleted.

Loading