Files
cpp-core/c++/cmake/ZapConfig.cmake.in
zeekay d9c73505fa Finish build-system rebrand (capnp->zap) and fix whitespace-desugar bugs
Build system (autotools/CMake/Bazel) capnp->zap rebrand completed so the
c++/ tree configures cleanly: `autoreconf -i && ./configure` succeeds,
emitting Makefile, all zap*.pc / kj*.pc and the Zap CMake config. configure.ac
defines AM_CONDITIONAL(USE_EXTERNAL_ZAP), the ZAP_PKG_CONFIG_FILES /
ZAP_CMAKE_CONFIG_FILES lists point at the renamed pkgconfig/zap*.pc.in and
cmake/Zap*.cmake.in, and Makefile.am's `if USE_EXTERNAL_ZAP` matches. Bazel
loads @zap-cpp//src/zap:cc_zap_library.bzl. Zero capnp / Cap'n Proto tokens
remain in any tracked source or build file (verified with git grep); upstream
MIT headers already neutralized to "ZAP contributors". quick-test.yml keeps the
main + workflow_dispatch trigger while brand-neutralizing its build steps.

Whitespace-significant schema desugar (compiler/desugar.c++) — fix three HIGH
correctness bugs and make the preprocessor total:

  * Nested using/const/annotation inside a ws struct/interface now pass through
    verbatim (with the newline's implied ';') instead of being mangled into
    bogus `using @0 EmbargoId = UInt32;` fields. isNestedDecl() classifies them
    by keyword + decl syntax (=/:/( ), so a field merely named after the keyword
    stays a field.
  * Ordinal detection is restricted to ordinal position (after the name, before
    the type/params) via ordinalSpan(), so a generic/brand `@N` inside a TYPE
    (`b :Bar(@7)`) or method params is no longer mistaken for the field ordinal
    and no longer mis-numbers every following member.
  * Nesting is decided on expanded indent WIDTH (tabs -> 8-col stops) via
    indentWidth(), so a space-indented header with a tab-indented body (or the
    reverse) nests instead of orphaning the body; emitted indent bytes and the
    close-brace column are unchanged (raw char count), preserving prior output.
  * Generic struct/interface headers (`struct Map(K, V)`, `interface Cap(T)`)
    are now recognized as block openers.
  * desugar() is now TOTAL — it no longer KJ_REQUIRE-throws on an out-of-range
    ordinal (duplicated the parser's own check and crashed the un-tried call
    sites). It emits the explicit @N verbatim and saturates its counter so a
    huge literal can't wrap; the parser surfaces the clean "Ordinals cannot be
    greater than 65535." diagnostic at the right file:line:col. Removed the now
    redundant validateAutoOrdinal and the dead kj/debug.h include. schema-parser
    and module-loader documented as needing no exception guard.

desugar-test.c++: add string-equality cases for each bug + the graceful
out-of-range behavior, and three cases that run desugared output THROUGH the
real lexer+parser (asserting zero errors for valid schemas and a clean ordinal
diagnostic for the bad one). Brace back-compat proven byte-identical over the
18-file corpus; sample.ws.zap still desugars to sample.brace.zap exactly.
2026-06-20 00:02:20 -07:00

124 lines
4.4 KiB
CMake

# Zap CMake Package Configuration
#
# When configured and installed, this file enables client projects to find Zap using
# CMake's find_package() command. It adds imported targets in the Zap:: namespace, such as
# Zap::kj, Zap::zap, etc. (one target for each file in pkgconfig/*.pc.in), defines
# the zap_generate_cpp() function, and exposes some variables for compatibility with the original
# FindZap.cmake module.
#
# Example usage:
# find_package(Zap)
# zap_generate_cpp(ZAP_SRCS ZAP_HDRS schema.zap)
# add_executable(foo main.cpp ${ZAP_SRCS})
# target_link_libraries(foo PRIVATE Zap::zap)
# target_include_directories(foo PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
#
# If you are using RPC features, use 'Zap::zap-rpc' in the target_link_libraries() call.
#
# Paths to `zap` and `zapc-c++` are exposed in the following variables:
# ZAP_EXECUTABLE
# Path to the `zap` tool (can be set to override).
# ZAPC_CXX_EXECUTABLE
# Path to the `zapc-c++` tool (can be set to override).
#
# For FindZap.cmake compatibility, the following variables are also provided. Please prefer
# using the imported targets in new CMake code.
# ZAP_INCLUDE_DIRS
# Include directories for the library's headers.
# CANP_LIBRARIES
# The Zap library paths.
# ZAP_LIBRARIES_LITE
# Paths to only the 'lite' libraries.
# ZAP_DEFINITIONS
# Compiler definitions required for building with the library.
# ZAP_FOUND
# Set if the libraries have been located (prefer using Zap_FOUND in new code).
#
@PACKAGE_INIT@
set(Zap_VERSION @VERSION@)
set(ZAP_EXECUTABLE $<TARGET_FILE:Zap::zap_tool>
CACHE FILEPATH "Location of zap executable")
set(ZAPC_CXX_EXECUTABLE $<TARGET_FILE:Zap::zapc_cpp>
CACHE FILEPATH "Location of zapc-c++ executable")
set(ZAP_INCLUDE_DIRECTORY "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@")
# work around http://public.kitware.com/Bug/view.php?id=15258
if(NOT _IMPORT_PREFIX)
set(_IMPORT_PREFIX ${PACKAGE_PREFIX_DIR})
endif()
if (@WITH_OPENSSL@) # WITH_OPENSSL
include(CMakeFindDependencyMacro)
if (CMAKE_VERSION VERSION_LESS 3.9)
# find_dependency() did not support COMPONENTS until CMake 3.9
#
# in practice, this call can be erroneous
# if the user has only libcrypto installed, but not libssl
find_dependency(OpenSSL)
else()
find_dependency(OpenSSL COMPONENTS Crypto SSL)
endif()
endif()
if (@WITH_ZLIB@) # WITH_ZLIB
include(CMakeFindDependencyMacro)
find_dependency(ZLIB)
endif()
if (@_WITH_LIBUCONTEXT@) # _WITH_LIBUCONTEXT
set(forwarded_config_flags)
if(Zap_FIND_QUIETLY)
list(APPEND forwarded_config_flags QUIET)
endif()
if(Zap_FIND_REQUIRED)
list(APPEND forwarded_config_flags REQUIRED)
endif()
# If the consuming project called find_package(Zap) with the QUIET or REQUIRED flags, forward
# them to calls to find_package(PkgConfig) and pkg_check_modules(). Note that find_dependency()
# would do this for us in the former case, but there is no such forwarding wrapper for
# pkg_check_modules().
find_package(PkgConfig ${forwarded_config_flags})
if(NOT ${PkgConfig_FOUND})
# If we're here, the REQUIRED flag must not have been passed, else we would have had a fatal
# error. Nevertheless, a diagnostic for this case is probably nice.
if(NOT Zap_FIND_QUIETLY)
message(WARNING "pkg-config cannot be found")
endif()
set(Zap_FOUND OFF)
return()
endif()
if (CMAKE_VERSION VERSION_LESS 3.6)
# CMake >= 3.6 required due to the use of IMPORTED_TARGET
message(SEND_ERROR "libucontext support requires CMake >= 3.6.")
endif()
pkg_check_modules(libucontext IMPORTED_TARGET ${forwarded_config_flags} libucontext)
endif()
include("${CMAKE_CURRENT_LIST_DIR}/ZapTargets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/ZapMacros.cmake")
# FindZap.cmake provides dependency information via several ZAP_-prefixed variables. New
# code should not rely on these variables, but prefer linking directly to the imported targets we
# now provide. However, we should still set these variables to ease the transition for projects
# which currently depend on the find-module.
set(ZAP_INCLUDE_DIRS ${ZAP_INCLUDE_DIRECTORY})
# No need to list all libraries, just the leaves of the dependency tree.
set(ZAP_LIBRARIES_LITE Zap::zap)
set(ZAP_LIBRARIES Zap::zap-rpc Zap::zap-json
Zap::kj-http)
set(ZAP_DEFINITIONS)
if(TARGET Zap::zap AND NOT TARGET Zap::zap-rpc)
set(ZAP_DEFINITIONS -DZAP_LITE)
endif()
set(ZAP_FOUND ${Zap_FOUND})