mirror of
https://github.com/zap-proto/cpp-core.git
synced 2026-10-30 15:06:00 +00:00
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.
222 lines
8.8 KiB
CMake
222 lines
8.8 KiB
CMake
# This CMake script adds imported targets for each shared library and executable distributed by
|
|
# Zap's autotools build.
|
|
#
|
|
# This file IS NOT USED by the CMake build! The CMake build generates its own version of this script
|
|
# from its set of exported targets. I used such a generated script as a reference when writing this
|
|
# one.
|
|
#
|
|
# The set of library targets provided by this script is automatically generated from the list of .pc
|
|
# files maintained in configure.ac. The set of executable targets is hard-coded in this file.
|
|
#
|
|
# You can request that this script print debugging information by invoking cmake with:
|
|
#
|
|
# -DZap_DEBUG=ON
|
|
#
|
|
# TODO(someday): Distinguish between debug and release builds. I.e., set IMPORTED_LOCATION_RELEASE
|
|
# rather than IMPORTED_LOCATION, etc., if this installation was configured as a release build. But
|
|
# how do we tell? grep for -g in CXXFLAGS?
|
|
|
|
if(CMAKE_VERSION VERSION_LESS 3.1)
|
|
message(FATAL_ERROR "CMake >= 3.1 required")
|
|
endif()
|
|
|
|
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()
|
|
|
|
function(_zap_import_pkg_config_target target)
|
|
# Add an imported library target named Zap::${target}, using the output of various
|
|
# invocations of `pkg-config ${target}`. The generated imported library target tries to mimic the
|
|
# behavior of a real CMake-generated imported target as closely as possible.
|
|
#
|
|
# Usage: _zap_import_pkg_config_target(target <all Zap targets>)
|
|
|
|
set(all_targets ${ARGN})
|
|
|
|
pkg_check_modules(${target} ${forwarded_config_flags} ${target})
|
|
|
|
if(NOT ${${target}_FOUND})
|
|
if(NOT Zap_FIND_QUIETLY)
|
|
message(WARNING "ZapConfig.cmake was configured to search for ${target}.pc, but pkg-config cannot find it. Ignoring this target.")
|
|
endif()
|
|
return()
|
|
endif()
|
|
|
|
if(Zap_DEBUG)
|
|
# Dump the information pkg-config discovered.
|
|
foreach(var VERSION LIBRARY_DIRS LIBRARIES LDFLAGS_OTHER INCLUDE_DIRS CFLAGS_OTHER)
|
|
message(STATUS "${target}_${var} = ${${target}_${var}}")
|
|
endforeach()
|
|
endif()
|
|
|
|
if(NOT ${${target}_VERSION} VERSION_EQUAL ${Zap_VERSION})
|
|
if(NOT Zap_FIND_QUIETLY)
|
|
message(WARNING "ZapConfig.cmake was configured to search for version ${Zap_VERSION}, but ${target} version ${${target}_VERSION} was found. Ignoring this target.")
|
|
endif()
|
|
return()
|
|
endif()
|
|
|
|
# Make an educated guess as to what the target's .so and .a filenames must be.
|
|
set(target_name_shared
|
|
${CMAKE_SHARED_LIBRARY_PREFIX}${target}-${Zap_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX})
|
|
set(target_name_static
|
|
${CMAKE_STATIC_LIBRARY_PREFIX}${target}${CMAKE_STATIC_LIBRARY_SUFFIX})
|
|
|
|
# Find the actual target's file. find_library() sets a cache variable, so I made the variable name
|
|
# unique-ish.
|
|
find_library(Zap_${target}_IMPORTED_LOCATION
|
|
NAMES ${target_name_shared} ${target_name_static} # prefer libfoo-version.so over libfoo.a
|
|
PATHS ${${target}_LIBRARY_DIRS}
|
|
NO_DEFAULT_PATH
|
|
)
|
|
# If the installed version of Zap is in a system location, pkg-config will not have filled
|
|
# in ${target}_LIBRARY_DIRS. To account for this, fall back to a regular search.
|
|
find_library(Zap_${target}_IMPORTED_LOCATION
|
|
NAMES ${target_name_shared} ${target_name_static} # prefer libfoo-version.so over libfoo.a
|
|
)
|
|
|
|
if(NOT Zap_${target}_IMPORTED_LOCATION)
|
|
# Not an error if the library doesn't exist -- we may have found a lite mode installation.
|
|
if(Zap_DEBUG)
|
|
message(STATUS "${target} library does not exist")
|
|
endif()
|
|
return()
|
|
endif()
|
|
|
|
# Record some information about this target -- shared versus static, location and soname -- which
|
|
# we'll use to build our imported target later.
|
|
|
|
set(target_location ${Zap_${target}_IMPORTED_LOCATION})
|
|
get_filename_component(target_name "${target_location}" NAME)
|
|
|
|
set(target_type STATIC)
|
|
set(imported_soname_property)
|
|
if(target_name STREQUAL ${target_name_shared})
|
|
set(target_type SHARED)
|
|
set(imported_soname_property IMPORTED_SONAME ${target_name})
|
|
endif()
|
|
|
|
# Each library dependency of the target is either the target itself, a sibling Zap
|
|
# library, or a system library. We ignore the first case by removing this target from the
|
|
# dependencies. The remaining dependencies are either passed through or, if they are a sibling
|
|
# Zap library, prefixed with `Zap::`.
|
|
set(dependencies ${${target}_LIBRARIES})
|
|
list(REMOVE_ITEM dependencies ${target})
|
|
set(target_interface_libs)
|
|
foreach(dependency ${dependencies})
|
|
list(FIND all_targets ${dependency} target_index)
|
|
# TODO(cleanup): CMake >= 3.3 lets us write: `if(NOT ${dependency} IN_LIST all_targets)`
|
|
if(target_index EQUAL -1)
|
|
list(APPEND target_interface_libs ${dependency})
|
|
else()
|
|
list(APPEND target_interface_libs Zap::${dependency})
|
|
endif()
|
|
endforeach()
|
|
|
|
add_library(Zap::${target} ${target_type} IMPORTED)
|
|
set_target_properties(Zap::${target} PROPERTIES
|
|
${imported_soname_property}
|
|
IMPORTED_LOCATION "${target_location}"
|
|
# TODO(cleanup): Use cxx_std_14 once it's safe to require cmake 3.8.
|
|
INTERFACE_COMPILE_FEATURES "cxx_generic_lambdas"
|
|
INTERFACE_COMPILE_OPTIONS "${${target}_CFLAGS_OTHER}"
|
|
INTERFACE_INCLUDE_DIRECTORIES "${${target}_INCLUDE_DIRS}"
|
|
|
|
# I'm dumping LDFLAGS_OTHER in with the libraries because there exists no
|
|
# INTERFACE_LINK_OPTIONS. See https://gitlab.kitware.com/cmake/cmake/issues/16543.
|
|
INTERFACE_LINK_LIBRARIES "${target_interface_libs};${${target}_LDFLAGS_OTHER}"
|
|
)
|
|
|
|
if(Zap_DEBUG)
|
|
# Dump all the properties we generated for the imported target.
|
|
foreach(prop
|
|
IMPORTED_LOCATION
|
|
IMPORTED_SONAME
|
|
INTERFACE_COMPILE_FEATURES
|
|
INTERFACE_COMPILE_OPTIONS
|
|
INTERFACE_INCLUDE_DIRECTORIES
|
|
INTERFACE_LINK_LIBRARIES)
|
|
get_target_property(value Zap::${target} ${prop})
|
|
message(STATUS "Zap::${target} ${prop} = ${value}")
|
|
endforeach()
|
|
endif()
|
|
endfunction()
|
|
|
|
# ========================================================================================
|
|
# Imported library targets
|
|
|
|
# Build a list of targets to search for from the list of .pc files.
|
|
# I.e. [somewhere/foo.pc, somewhere/bar.pc] -> [foo, bar]
|
|
set(library_targets)
|
|
foreach(filename ${ZAP_PKG_CONFIG_FILES})
|
|
get_filename_component(target ${filename} NAME_WE)
|
|
list(APPEND library_targets ${target})
|
|
endforeach()
|
|
|
|
# Try to add an imported library target Zap::foo for each foo.pc distributed with Zap.
|
|
foreach(target ${library_targets})
|
|
_zap_import_pkg_config_target(${target} ${library_targets})
|
|
endforeach()
|
|
|
|
# Handle lite-mode and no libraries found cases. It is tempting to set a Zap_LITE variable
|
|
# here, but the real CMake-generated implementation does no such thing -- we'd need to set it in
|
|
# ZapConfig.cmake.in itself.
|
|
if(TARGET Zap::zap AND TARGET Zap::kj)
|
|
if(NOT TARGET Zap::zap-rpc)
|
|
if(NOT Zap_FIND_QUIETLY)
|
|
message(STATUS "Found an installation of Zap lite. Executable and library targets beyond libkj and libzap will be unavailable.")
|
|
endif()
|
|
# Lite mode doesn't include the executables, so return here.
|
|
return()
|
|
endif()
|
|
else()
|
|
# If we didn't even find zap or kj, then we didn't find anything usable.
|
|
set(Zap_FOUND OFF)
|
|
return()
|
|
endif()
|
|
|
|
# ========================================================================================
|
|
# Imported executable targets
|
|
|
|
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
|
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
|
|
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
|
|
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
|
|
|
|
# Add executable targets for the zap compiler and plugins. This list must be kept manually in sync
|
|
# with the rest of the project.
|
|
|
|
add_executable(Zap::zap_tool IMPORTED)
|
|
set_target_properties(Zap::zap_tool PROPERTIES
|
|
IMPORTED_LOCATION "${_IMPORT_PREFIX}/bin/zap${CMAKE_EXECUTABLE_SUFFIX}"
|
|
)
|
|
|
|
add_executable(Zap::zapc_cpp IMPORTED)
|
|
set_target_properties(Zap::zapc_cpp PROPERTIES
|
|
IMPORTED_LOCATION "${_IMPORT_PREFIX}/bin/zapc-c++${CMAKE_EXECUTABLE_SUFFIX}"
|
|
)
|
|
|
|
add_executable(Zap::zapc_zap IMPORTED)
|
|
set_target_properties(Zap::zapc_zap PROPERTIES
|
|
IMPORTED_LOCATION "${_IMPORT_PREFIX}/bin/zapc-zap${CMAKE_EXECUTABLE_SUFFIX}"
|
|
)
|