PingLiuPing commented on code in PR #936:
URL: https://github.com/apache/iceberg-cpp/pull/936#discussion_r4119391218
##########
example/CMakeLists.txt:
##########
@@ -20,13 +20,79 @@ cmake_minimum_required(VERSION 3.25)
project(example)
-set(CMAKE_CXX_STANDARD 23)
+# C++20 is the minimum standard iceberg-cpp's public headers support, so the
+# example builds as C++20 by default to keep that contract exercised. Set this
to
+# 23 to also check the headers from a C++23 consumer.
+set(ICEBERG_EXAMPLE_CXX_STANDARD
+ 20
+ CACHE STRING "C++ standard used to build the example (20 or 23)")
+set_property(CACHE ICEBERG_EXAMPLE_CXX_STANDARD PROPERTY STRINGS 20 23)
+if(NOT ICEBERG_EXAMPLE_CXX_STANDARD MATCHES "^(20|23)$")
+ message(FATAL_ERROR "ICEBERG_EXAMPLE_CXX_STANDARD must be 20 or 23, got "
+ "'${ICEBERG_EXAMPLE_CXX_STANDARD}'")
+endif()
+
+set(CMAKE_CXX_STANDARD ${ICEBERG_EXAMPLE_CXX_STANDARD})
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_EXTENSIONS OFF)
find_package(iceberg CONFIG REQUIRED COMPONENTS bundle rest)
+if(TARGET iceberg::iceberg_bundle_shared)
+ set(ICEBERG_BUNDLE_TARGET iceberg::iceberg_bundle_shared)
+else()
+ set(ICEBERG_BUNDLE_TARGET iceberg::iceberg_bundle_static)
+endif()
+
+if(TARGET iceberg::iceberg_rest_shared)
+ set(ICEBERG_REST_TARGET iceberg::iceberg_rest_shared)
+else()
+ set(ICEBERG_REST_TARGET iceberg::iceberg_rest_static)
+endif()
+
add_executable(demo_example demo_example.cc)
-target_link_libraries(demo_example
- PRIVATE
"$<IF:$<TARGET_EXISTS:iceberg::iceberg_bundle_shared>,iceberg::iceberg_bundle_shared,iceberg::iceberg_bundle_static>"
-
"$<IF:$<TARGET_EXISTS:iceberg::iceberg_rest_shared>,iceberg::iceberg_rest_shared,iceberg::iceberg_rest_static>"
-)
+target_link_libraries(demo_example PRIVATE ${ICEBERG_BUNDLE_TARGET}
+ ${ICEBERG_REST_TARGET})
+
+# Compile every installed public header as a consumer using
+# ICEBERG_EXAMPLE_CXX_STANDARD. The installed include
+# tree is the public API contract: iceberg_install_all_headers excludes
internal
+# headers before packaging them.
+get_target_property(ICEBERG_BUNDLE_INCLUDE_DIRS ${ICEBERG_BUNDLE_TARGET}
+ INTERFACE_INCLUDE_DIRECTORIES)
+foreach(ICEBERG_INCLUDE_DIR IN LISTS ICEBERG_BUNDLE_INCLUDE_DIRS)
+ if(EXISTS "${ICEBERG_INCLUDE_DIR}/iceberg")
+ set(ICEBERG_PUBLIC_INCLUDE_DIR "${ICEBERG_INCLUDE_DIR}")
+ break()
+ endif()
+endforeach()
+
+if(NOT ICEBERG_PUBLIC_INCLUDE_DIR)
+ message(FATAL_ERROR "Could not locate iceberg's installed public headers")
+endif()
+
+file(GLOB_RECURSE
+ ICEBERG_PUBLIC_HEADERS
+ CONFIGURE_DEPENDS
+ "${ICEBERG_PUBLIC_INCLUDE_DIR}/iceberg/*.h"
+ "${ICEBERG_PUBLIC_INCLUDE_DIR}/iceberg/*.hpp")
+list(SORT ICEBERG_PUBLIC_HEADERS)
+
+set(ICEBERG_PUBLIC_HEADER_CHECK_SOURCE
+ "// Generated from iceberg's installed public headers.\n")
+foreach(ICEBERG_PUBLIC_HEADER IN LISTS ICEBERG_PUBLIC_HEADERS)
+ file(RELATIVE_PATH ICEBERG_PUBLIC_HEADER_RELATIVE_PATH
"${ICEBERG_PUBLIC_INCLUDE_DIR}"
+ "${ICEBERG_PUBLIC_HEADER}")
+ string(APPEND ICEBERG_PUBLIC_HEADER_CHECK_SOURCE
+ "#include <${ICEBERG_PUBLIC_HEADER_RELATIVE_PATH}>\n")
+endforeach()
+string(APPEND ICEBERG_PUBLIC_HEADER_CHECK_SOURCE "\nint main() { return 0;
}\n")
+
+file(GENERATE
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/public_headers_check.cc"
+ CONTENT "${ICEBERG_PUBLIC_HEADER_CHECK_SOURCE}")
+
+add_executable(public_headers_check
"${CMAKE_CURRENT_BINARY_DIR}/public_headers_check.cc")
Review Comment:
Thanks, added src/iceberg/cpp20_compatibility_internal.h and
src/iceberg/test/cpp20_compatibility_test.cc.
src/iceberg/cpp20_compatibility_internal.h is generated by a new python file
ci/generate_public_headers.py, and this script is used in pre-commit to check
that no public headers is missed in cpp20_compatibility_internal.h. It follows
the same rule with `function(iceberg_install_all_headers PATH) ` with one diff:
dropping .hpp since repo has no .hpp files today.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]