Commit d70d9a66 authored by Kenton Varda's avatar Kenton Varda

Merge branch 'master' of github.com:kentonv/capnproto

parents 817576c6 4ab4080b
project("Cap'n Proto" CXX)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
add_subdirectory(c++)
project(Private)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) option(BUILD_TOOLS "Build command-line tools and compiler." ON)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) option(BUILD_TESTING "Build unit tests and enable CTest 'check' target." ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) option(EXTERNAL_CAPNP "Use the system capnp binary, or the one specified in $CAPNP, instead of using the compiled one." OFF)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused-parameter -std=c++11") if (NOT BUILD_TOOLS AND BUILD_TESTING AND NOT EXTERNAL_CAPNP)
message(WARNING "Forcing BUILD_TOOLS to ON; required by BUILD_TESTING without EXTERNAL_CAPNP.")
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gtest" AND IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/gtest") set(BUILD_TOOLS TRUE)
add_subdirectory(gtest)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/gtest/include)
else()
message(FATAL_ERROR "Please use setup-cmake.sh to download gtest before running the cmake build")
endif() endif()
include(CTest) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -std=c++11 -pthread")
add_subdirectory(src) add_subdirectory(src)
#! /usr/bin/env bash
set -euo pipefail
if [ ! -e gtest ]; then
echo "================================================================================"
echo "Fetching Google Test code..."
echo "================================================================================"
svn checkout http://googletest.googlecode.com/svn/tags/release-1.7.0 gtest
fi
echo "================================================================================"
echo "Done"
echo "================================================================================"
echo
echo "Ready to run cmake (no support for installing yet). For example:"
echo " mkdir build && cd build && cmake .. -G 'Unix Makefiles' && make -j6 check"
project(Private)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused-parameter -std=c++11")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR})
find_package(CapnProto)
set(CAPNP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR})
# kj ==============================================================
add_library(kj add_library(kj
kj/common.c++ kj/common.c++
kj/units.c++ kj/units.c++
...@@ -22,12 +23,48 @@ add_library(kj ...@@ -22,12 +23,48 @@ add_library(kj
kj/main.c++ kj/main.c++
kj/parse/char.c++ kj/parse/char.c++
) )
set(kj_headers
kj/common.h
kj/units.h
kj/memory.h
kj/refcount.h
kj/array.h
kj/vector.h
kj/string.h
kj/string-tree.h
kj/exception.h
kj/debug.h
kj/arena.h
kj/io.h
kj/tuple.h
kj/one-of.h
kj/function.h
kj/mutex.h
kj/thread.h
kj/threadlocal.h
kj/time.h
kj/main.h
)
set(kj-parse_headers
kj/parse/common.h
kj/parse/char.h
)
add_library(kj-async add_library(kj-async
kj/async.c++ kj/async.c++
kj/async-unix.c++ kj/async-unix.c++
kj/async-io.c++ kj/async-io.c++
) )
target_link_libraries(kj-async kj)
set(kj-async_headers
kj/async-prelude.h
kj/async.h
kj/async-inl.h
kj/async-unix.h
kj/async-io.h
)
# capnp ==============================================================
add_library(capnp add_library(capnp
capnp/c++.capnp.c++ capnp/c++.capnp.c++
...@@ -45,6 +82,30 @@ add_library(capnp ...@@ -45,6 +82,30 @@ add_library(capnp
capnp/serialize.c++ capnp/serialize.c++
capnp/serialize-packed.c++ capnp/serialize-packed.c++
) )
target_link_libraries(capnp kj)
set(capnp_headers
capnp/c++.capnp.h
capnp/common.h
capnp/blob.h
capnp/endian.h
capnp/layout.h
capnp/orphan.h
capnp/list.h
capnp/any.h
capnp/message.h
capnp/capability.h
capnp/schema.capnp.h
capnp/schema.h
capnp/schema-loader.h
capnp/schema-parser.h
capnp/dynamic.h
capnp/pretty-print.h
capnp/serialize.h
capnp/serialize-async.h
capnp/serialize-packed.h
capnp/pointer-helpers.h
capnp/generated-header-support.h
)
add_library(capnp-rpc add_library(capnp-rpc
capnp/serialize-async.c++ capnp/serialize-async.c++
...@@ -56,6 +117,17 @@ add_library(capnp-rpc ...@@ -56,6 +117,17 @@ add_library(capnp-rpc
capnp/rpc-twoparty.capnp.c++ capnp/rpc-twoparty.capnp.c++
capnp/ez-rpc.c++ capnp/ez-rpc.c++
) )
target_link_libraries(capnp-rpc kj-async kj)
set(capnp-rpc_headers
capnp/rpc-prelude.h
capnp/rpc.h
capnp/rpc-twoparty.h
capnp/rpc.capnp.h
capnp/rpc-twoparty.capnp.h
capnp/ez-rpc.h
)
# Tools/Compilers ==============================================================
add_library(capnpc add_library(capnpc
capnp/compiler/md5.c++ capnp/compiler/md5.c++
...@@ -68,54 +140,142 @@ add_library(capnpc ...@@ -68,54 +140,142 @@ add_library(capnpc
capnp/compiler/compiler.c++ capnp/compiler/compiler.c++
capnp/schema-parser.c++ capnp/schema-parser.c++
) )
target_link_libraries(capnpc capnp kj)
set(capnpc_headers
capnp/c++.capnp
capnp/schema.capnp
capnp/rpc.capnp
capnp/rpc-twoparty.capnp
)
add_executable(capnp-tool if(BUILD_TOOLS)
add_executable(capnp-tool
capnp/compiler/module-loader.c++ capnp/compiler/module-loader.c++
capnp/compiler/capnp.c++ capnp/compiler/capnp.c++
) )
target_link_libraries(capnp-tool capnpc capnp kj) target_link_libraries(capnp-tool capnpc capnp kj)
set_target_properties(capnp-tool PROPERTIES OUTPUT_NAME capnp) set_target_properties(capnp-tool PROPERTIES OUTPUT_NAME capnp)
add_executable(capnpc_cpp add_executable(capnpc_cpp
capnp/compiler/capnpc-c++.c++ capnp/compiler/capnpc-c++.c++
) )
target_link_libraries(capnpc_cpp capnp kj) target_link_libraries(capnpc_cpp capnp kj)
set_target_properties(capnpc_cpp PROPERTIES OUTPUT_NAME capnpc-c++) set_target_properties(capnpc_cpp PROPERTIES OUTPUT_NAME capnpc-c++)
add_executable(capnpc_capnp
capnp/compiler/capnpc-capnp.c++
)
target_link_libraries(capnpc_capnp capnp kj)
set_target_properties(capnpc_capnp PROPERTIES OUTPUT_NAME capnpc-capnp)
endif() # BUILD_TOOLS
# Install ==============================================================
if(BUILD_TOOLS)
export(TARGETS capnp capnp-tool capnp-rpc capnpc capnpc_cpp capnpc_capnp kj kj-async
FILE ${CMAKE_CURRENT_BINARY_DIR}/capnp-config.cmake
)
else()
export(TARGETS capnp capnp-rpc capnpc kj kj-async
FILE ${CMAKE_CURRENT_BINARY_DIR}/capnp-config.cmake
)
endif()
export(PACKAGE capnp)
if(BUILD_TOOLS)
install(TARGETS capnp capnp-tool capnp-rpc capnpc capnpc_cpp capnpc_capnp kj kj-async
EXPORT capnp
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
# Symlink capnpc -> capnp
install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink capnp ${CMAKE_INSTALL_PREFIX}/bin/capnpc)")
else()
install(TARGETS capnp capnp-rpc capnpc kj kj-async
EXPORT capnp
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
endif()
install(FILES ${kj_headers} DESTINATION include/kj)
install(FILES ${kj-async_headers} DESTINATION include/kj)
install(FILES ${kj-parse_headers} DESTINATION include/kj/parse)
install(FILES ${capnp_headers} DESTINATION include/capnp)
install(FILES ${capnp-rpc_headers} DESTINATION include/capnp)
install(FILES ${capnpc_headers} DESTINATION include/capnp)
# Tests ==============================================================
if(BUILD_TESTING)
# Setup googletest build and library targets (gtest and gtest_main)
include(ExternalProject)
ExternalProject_Add(gtest_build
URL http://googletest.googlecode.com/files/gtest-1.7.0.zip
URL_HASH SHA1=f85f6d2481e2c6c4a18539e391aa4ea8ab0394af
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
INSTALL_COMMAND "" # Disable install
)
ExternalProject_Get_Property(gtest_build binary_dir)
set(test_capnp_files add_library(gtest UNKNOWN IMPORTED)
set_property(TARGET gtest
PROPERTY IMPORTED_LOCATION ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest.a
)
add_dependencies(gtest gtest_build)
add_library(gtest_main UNKNOWN IMPORTED)
set_property(TARGET gtest_main
PROPERTY IMPORTED_LOCATION ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main.a
)
add_dependencies(gtest_main gtest)
ExternalProject_Get_Property(gtest_build source_dir)
include_directories(${source_dir}/include)
set(test_capnp_files
capnp/test.capnp capnp/test.capnp
capnp/test-import.capnp capnp/test-import.capnp
capnp/test-import2.capnp capnp/test-import2.capnp
) )
set(test_capnp_cpp_files) # Setup paths to the schema compiler for generating ${test_capnp_files}
set(test_capnp_header_files) if(NOT EXTERNAL_CAPNP)
set(test_capnp_capnp_files) set(CAPNP_EXECUTABLE $<TARGET_FILE:capnp-tool>)
set(CAPNPC_CXX_EXECUTABLE $<TARGET_FILE:capnpc_cpp>)
foreach(_file ${test_capnp_files}) else()
list(APPEND test_capnp_cpp_files ${CMAKE_CURRENT_BINARY_DIR}/${_file}.c++) # Allow paths to tools to be set with one of: (1) the CMake variables from the
list(APPEND test_capnp_header_files ${CMAKE_CURRENT_BINARY_DIR}/${_file}.h) # the FindCapnProto module; (2) environment variables; or (3) find_program()
get_filename_component(_capnp_abs ${_file} ABSOLUTE) if (NOT CAPNP_EXECUTABLE)
list(APPEND test_capnp_capnp_files ${_capnp_abs}) if (DEFINED ENV{CAPNP})
set_source_files_properties( set(CAPNP_EXECUTABLE $ENV{CAPNP})
${CMAKE_CURRENT_BINARY_DIR}/${_file}.capnp.c++ else()
PROPERTIES GENERATED TRUE) find_program(CAPNP_EXECUTABLE capnp)
endforeach() endif()
endif()
add_custom_command(
OUTPUT if(NOT CAPNPC_CXX_EXECUTABLE)
${test_capnp_cpp_files} if (DEFINED ENV{CAPNPC_CXX})
${test_capnp_header_files} set(CAPNPC_CXX_EXECUTABLE $ENV{CAPNPC_CXX})
COMMAND capnp-tool compile else()
-o $<TARGET_FILE:capnpc_cpp> # Also search in the same directory that `capnp` was found in
--src-prefix=${CMAKE_CURRENT_SOURCE_DIR} get_filename_component(capnp_dir ${CAPNP_EXECUTABLE} DIRECTORY)
-I${CMAKE_CURRENT_SOURCE_DIR} find_program(CAPNPC_CXX_EXECUTABLE capnpc-c++ HINTS ${capnp_dir})
${test_capnp_capnp_files} endif()
DEPENDS capnp-tool capnpc_cpp ${test_capnp_files}) endif()
add_library(capnp_test_lib ${test_capnp_cpp_files}) endif()
include_directories(${CMAKE_CURRENT_BINARY_DIR})
set(CAPNPC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/test_capnp)
add_executable(capnp-tests file(MAKE_DIRECTORY ${CAPNPC_OUTPUT_DIR})
capnp_generate_cpp(test_capnp_cpp_files test_capnp_h_files ${test_capnp_files})
include_directories(${CAPNPC_OUTPUT_DIR})
add_executable(capnp-tests
kj/common-test.c++ kj/common-test.c++
kj/memory-test.c++ kj/memory-test.c++
kj/refcount-test.c++ kj/refcount-test.c++
...@@ -162,9 +322,10 @@ add_executable(capnp-tests ...@@ -162,9 +322,10 @@ add_executable(capnp-tests
capnp/test-util.c++ capnp/test-util.c++
capnp/compiler/lexer-test.c++ capnp/compiler/lexer-test.c++
capnp/compiler/md5-test.c++ capnp/compiler/md5-test.c++
) ${test_capnp_cpp_files}
target_link_libraries(capnp-tests ${test_capnp_h_files}
capnp_test_lib )
target_link_libraries(capnp-tests
capnpc capnpc
capnp-rpc capnp-rpc
capnp capnp
...@@ -172,24 +333,17 @@ target_link_libraries(capnp-tests ...@@ -172,24 +333,17 @@ target_link_libraries(capnp-tests
kj kj
gtest gtest
gtest_main gtest_main
) )
add_executable(capnp-evolution-tests capnp/compiler/evolution-test.c++) add_executable(capnp-evolution-tests capnp/compiler/evolution-test.c++)
target_link_libraries(capnp-evolution-tests target_link_libraries(capnp-evolution-tests capnpc capnp kj)
capnp_test_lib
capnpc
capnp-rpc
capnp
kj-async
kj
gtest
gtest_main
)
add_test(NAME capnp-tests-run COMMAND capnp-tests) include(CTest)
add_test(NAME capnp-evolution-tests-run COMMAND capnp-evolution-tests) add_test(NAME capnp-tests-run COMMAND capnp-tests)
add_test(NAME capnp-evolution-tests-run COMMAND capnp-evolution-tests)
# Sadly, we can't use the 'test' target, as that's coopted by ctest # Sadly, we can't use the 'test' target, as that's coopted by ctest
add_custom_target(check ${CMAKE_CTEST_COMMAND} -V) add_custom_target(check ${CMAKE_CTEST_COMMAND} -V)
add_dependencies(check capnp-tests) add_dependencies(check capnp-tests)
add_dependencies(check capnp-evolution-tests) add_dependencies(check capnp-evolution-tests)
endif() # BUILD_TESTING
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#if _WIN32
#define strerror_r(errno,buf,len) strerror_s(buf,len,errno)
#endif
namespace kj { namespace kj {
namespace _ { // private namespace _ { // private
......
...@@ -110,6 +110,11 @@ ...@@ -110,6 +110,11 @@
#include "string.h" #include "string.h"
#include "exception.h" #include "exception.h"
#ifdef ERROR
// This is problematic because windows.h #defines ERROR, which we use in an enum here.
#error "Make sure to to undefine ERROR (or just #include <kj/windows-sanity.h>) before this file"
#endif
namespace kj { namespace kj {
#define KJ_LOG(severity, ...) \ #define KJ_LOG(severity, ...) \
......
...@@ -83,7 +83,7 @@ String getStackSymbols(ArrayPtr<void* const> trace) { ...@@ -83,7 +83,7 @@ String getStackSymbols(ArrayPtr<void* const> trace) {
#elif __APPLE__ #elif __APPLE__
// The Mac OS X equivalent of addr2line is atos. // The Mac OS X equivalent of addr2line is atos.
// (Internally, it uses the private CoreSymbolication.framework library.) // (Internally, it uses the private CoreSymbolication.framework library.)
p = popen(str("atos -d -p ", getpid(), ' ', strArray(trace, " ")).cStr(), "r"); p = popen(str("xcrun atos -p ", getpid(), ' ', strArray(trace, " ")).cStr(), "r");
#endif #endif
if (p == nullptr) { if (p == nullptr) {
......
...@@ -28,7 +28,13 @@ ...@@ -28,7 +28,13 @@
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
#if _WIN32
#include <windows.h>
#include <io.h>
#else
#include <sys/uio.h> #include <sys/uio.h>
#endif
namespace kj { namespace kj {
...@@ -60,12 +66,53 @@ void TopLevelProcessContext::exit() { ...@@ -60,12 +66,53 @@ void TopLevelProcessContext::exit() {
static void writeLineToFd(int fd, StringPtr message) { static void writeLineToFd(int fd, StringPtr message) {
// Write the given message to the given file descriptor with a trailing newline iff the message // Write the given message to the given file descriptor with a trailing newline iff the message
// is non-empty and doesn't already have a trailing newline. We use writev() to do this in a // is non-empty and doesn't already have a trailing newline. We use writev() to do this in a
// single system call without any copying. // single system call without any copying (OS permitting).
if (message.size() == 0) { if (message.size() == 0) {
return; return;
} }
#if _WIN32
KJ_STACK_ARRAY(char, newlineExpansionBuffer, 2 * (message.size() + 1), 128, 512);
char* p = newlineExpansionBuffer.begin();
for(char ch : message) {
if(ch == '\n') {
*(p++) = '\r';
}
*(p++) = ch;
}
if(!message.endsWith("\n")) {
*(p++) = '\r';
*(p++) = '\n';
}
size_t newlineExpandedSize = p - newlineExpansionBuffer.begin();
KJ_ASSERT(newlineExpandedSize <= newlineExpansionBuffer.size());
HANDLE handle = reinterpret_cast<HANDLE>(_get_osfhandle(fd));
DWORD consoleMode;
bool redirectedToFile = !GetConsoleMode(handle, &consoleMode);
DWORD writtenSize;
if(redirectedToFile) {
WriteFile(handle, newlineExpansionBuffer.begin(), newlineExpandedSize, &writtenSize, nullptr);
} else {
KJ_STACK_ARRAY(wchar_t, buffer, newlineExpandedSize, 128, 512);
size_t finalSize = MultiByteToWideChar(
CP_UTF8,
0,
newlineExpansionBuffer.begin(),
newlineExpandedSize,
buffer.begin(),
buffer.size());
KJ_ASSERT(finalSize <= buffer.size());
WriteConsoleW(handle, buffer.begin(), finalSize, &writtenSize, nullptr);
}
#else
// Unfortunately the writev interface requires non-const pointers even though it won't modify // Unfortunately the writev interface requires non-const pointers even though it won't modify
// the data. // the data.
struct iovec vec[2]; struct iovec vec[2];
...@@ -109,6 +156,7 @@ static void writeLineToFd(int fd, StringPtr message) { ...@@ -109,6 +156,7 @@ static void writeLineToFd(int fd, StringPtr message) {
} }
} }
} }
#endif
} }
void TopLevelProcessContext::warning(StringPtr message) { void TopLevelProcessContext::warning(StringPtr message) {
......
// Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors
// Licensed under the MIT License:
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef KJ_WINDOWS_SANITY_H_
#define KJ_WINDOWS_SANITY_H_
#ifndef _INC_WINDOWS
#error "windows.h needs to be included before kj/windows-sanity.h (or perhaps you don't need either?)"
#endif
namespace win32 {
const auto ERROR_ = ERROR;
#undef ERROR
const auto ERROR = ERROR_;
}
using win32::ERROR;
#endif // KJ_WINDOWS_SANITY_H_
#
# Finds the Cap'n Proto libraries, and compiles schema files.
#
# Configuration variables (optional):
# CAPNPC_OUTPUT_DIR
# Directory to place compiled schema sources (default: the same directory as the schema file).
# CAPNPC_IMPORT_DIRS
# List of additional include directories for the schema compiler.
# (CMAKE_CURRENT_SOURCE_DIR and CAPNP_INCLUDE_DIRS are always included.)
# CAPNPC_SRC_PREFIX
# Schema file source prefix (default: CMAKE_CURRENT_SOURCE_DIR).
# CAPNPC_FLAGS
# Additional flags to pass to the schema compiler.
#
# Variables that are discovered:
# CAPNP_EXECUTABLE
# Path to the `capnp` tool (can be set to override).
# CAPNPC_CXX_EXECUTABLE
# Path to the `capnpc-c++` tool (can be set to override).
# CAPNP_INCLUDE_DIRS
# Include directories for the library's headers (can be set to override).
# CAPNP_LIBRARIES
# The necessary library paths to link with.
# CAPNP_FOUND
# Set if the libraries have been located.
#
# Example usage:
#
# find_package(CapnProto REQUIRED)
# include_directories(${CAPNP_INCLUDE_DIRS})
#
# capnp_generate_cpp(CAPNP_SRCS CAPNP_HDRS schema.capnp)
# add_executable(a a.cc ${CAPNP_SRCS} ${CAPNP_HDRS})
# target_link_library(a ${CAPNP_LIBRARIES})
#
# For out-of-source builds:
#
# set(CAPNPC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
# include_directories(${CAPNPC_OUTPUT_DIR})
# capnp_generate_cpp(...)
#
function(CAPNP_GENERATE_CPP SOURCES HEADERS)
if(NOT ARGN)
message(SEND_ERROR "CAPNP_GENERATE_CPP() called without any source files.")
endif()
if(NOT CAPNP_EXECUTABLE)
message(SEND_ERROR "Could not locate capnp executable (CAPNP_EXECUTABLE).")
endif()
if(NOT CAPNPC_CXX_EXECUTABLE)
message(SEND_ERROR "Could not locate capnpc-c++ executable (CAPNPC_CXX_EXECUTABLE).")
endif()
if(NOT CAPNP_INCLUDE_DIRS)
message(SEND_ERROR "Could not locate capnp header files (CAPNP_INCLUDE_DIRS).")
endif()
# Default compiler includes
set(include_path -I ${CMAKE_CURRENT_SOURCE_DIR} -I ${CAPNP_INCLUDE_DIRS})
if(DEFINED CAPNPC_IMPORT_DIRS)
# Append each directory as a series of '-I' flags in ${include_path}
foreach(directory ${CAPNPC_IMPORT_DIRS})
get_filename_component(absolute_path ${directory} ABSOLUTE)
list(APPEND include_path -I ${absolute_path})
endforeach()
endif()
if(DEFINED CAPNPC_OUTPUT_DIR)
# Prepend a ':' to get the format for the '-o' flag right
set(output_dir ":${CAPNPC_OUTPUT_DIR}")
else()
set(output_dir)
endif()
if(NOT DEFINED CAPNPC_SRC_PREFIX)
set(CAPNPC_SRC_PREFIX ${CMAKE_CURRENT_SOURCE_DIR})
endif()
get_filename_component(CAPNPC_SRC_PREFIX ${CAPNPC_SRC_PREFIX} ABSOLUTE)
set(${SOURCES})
set(${HEADERS})
foreach(schema_file ${ARGN})
get_filename_component(file_path ${schema_file} ABSOLUTE)
get_filename_component(file_dir ${file_path} DIRECTORY)
# Figure out where the output files will go
if (NOT DEFINED CAPNPC_OUTPUT_DIR)
set(output_base ${file_path})
else()
# Output files are placed in CAPNPC_OUTPUT_DIR, at a location as if they were
# relative to CAPNPC_SRC_PREFIX.
string(LENGTH ${CAPNPC_SRC_PREFIX} prefix_len)
string(SUBSTRING ${file_path} 0 ${prefix_len} output_prefix)
if(NOT ${CAPNPC_SRC_PREFIX} STREQUAL ${output_prefix})
message(SEND_ERROR "Could not determine output path for '${schema_file}' ('${file_path}') with source prefix '${CAPNPC_SRC_PREFIX}' into '${CAPNPC_OUTPUT_DIR}'.")
endif()
string(SUBSTRING ${file_path} ${prefix_len} -1 output_path)
set(output_base ${CAPNPC_OUTPUT_DIR}${output_path})
endif()
add_custom_command(
OUTPUT "${output_base}.c++" "${output_base}.h"
COMMAND ${CAPNP_EXECUTABLE}
ARGS compile
-o ${CAPNPC_CXX_EXECUTABLE}${output_dir}
--src-prefix ${CAPNPC_SRC_PREFIX}
${include_path}
${CAPNPC_FLAGS}
${file_path}
DEPENDS ${schema_file}
COMMENT "Compiling Cap'n Proto schema ${schema_file}"
VERBATIM
)
list(APPEND ${SOURCES} "${output_base}.c++")
list(APPEND ${HEADERS} "${output_base}.h")
endforeach()
set_source_files_properties(${${SOURCES}} ${${HEADERS}} PROPERTIES GENERATED TRUE)
set(${SOURCES} ${${SOURCES}} PARENT_SCOPE)
set(${HEADERS} ${${HEADERS}} PARENT_SCOPE)
endfunction()
find_library(CAPNP_LIB_KJ kj)
find_library(CAPNP_LIB_KJ-ASYNC kj-async)
find_library(CAPNP_LIB_CAPNP capnp)
find_library(CAPNP_LIB_CAPNP-RPC capnp-rpc)
find_library(CAPNP_LIB_CAPNPC capnpc)
mark_as_advanced(CAPNP_LIB_KJ CAPNP_LIB_KJ-ASYNC CAPNP_LIB_CAPNP CAPNP_LIB_CAPNP-RPC CAPNP_LIB_CAPNPC)
set(CAPNP_LIBRARIES
${CAPNP_LIB_KJ}
${CAPNP_LIB_KJ-ASYNC}
${CAPNP_LIB_CAPNP}
${CAPNP_LIB_CAPNP-RPC}
${CAPNP_LIB_CAPNPC}
)
find_path(CAPNP_INCLUDE_DIRS capnp/generated-header-support.h)
find_program(CAPNP_EXECUTABLE
NAMES capnp
DOC "Cap'n Proto Command-line Tool"
)
find_program(CAPNPC_CXX_EXECUTABLE
NAMES capnpc-c++
DOC "Capn'n Proto C++ Compiler"
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment