Commit d9f0f2b2 authored by Philip Quinn's avatar Philip Quinn

CMake: Add support for `CAPNP_LITE` option (see c772a700).

With CAPNP_LITE=1, the command-line tools will not be built, and the
tests cannot be built without EXTERNAL_CAPNP=1 (BUILD_TESTING=0 needs to
be set if the tests are not desired).
parent bc7113b9
# Options ======================================================================
option(BUILD_TOOLS "Build command-line tools and compiler." ON)
option(BUILD_TESTING "Build unit tests and enable CTest 'check' target." ON)
option(EXTERNAL_CAPNP "Use the system capnp binary, or the one specified in $CAPNP, instead of using the compiled one." OFF)
option(CAPNP_LITE "Compile Cap'n Proto in 'lite mode', in which all reflection APIs (schema.h, dynamic.h, etc.) are not included. Produces a smaller library at the cost of features. All programs built against the library must be compiled with -DCAPNP_LITE. Requires EXTERNAL_CAPNP to build the tests." OFF)
# Check for invalid combinations of build options
if(NOT BUILD_TOOLS AND BUILD_TESTING AND NOT EXTERNAL_CAPNP)
# Not *all* of the tests require the capnp compiler, and those that do could be excluded
# when not building the tools, but it's easier to just have a blanket rule.
message(SEND_ERROR "Tests (BUILD_TESTING) cannot be build without either BUILD_TOOLS or EXTERNAL_CAPNP.")
endif()
if(CAPNP_LITE AND BUILD_TESTING AND NOT EXTERNAL_CAPNP)
# As above, we could exclude only the tests that depend on the compiler.
message(SEND_ERROR "CAPNP_LITE with BUILD_TESTING requires EXTERNAL_CAPNP.")
endif()
if(CAPNP_LITE AND BUILD_TOOLS)
message(WARNING "Command-line tools will not be built with CAPNP_LITE.")
endif()
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.")
set(BUILD_TOOLS TRUE)
if(CAPNP_LITE)
set(CAPNP_LITE_FLAG "-DCAPNP_LITE")
else()
set(CAPNP_LITE_FLAG)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -std=c++11 -pthread")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -std=c++11 -pthread ${CAPNP_LITE_FLAG}")
# Source =======================================================================
add_subdirectory(src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
find_package(CapnProto)
set(CAPNP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR})
# Tests ========================================================================
# kj ==============================================================
add_library(kj
kj/common.c++
kj/units.c++
kj/memory.c++
kj/refcount.c++
kj/array.c++
kj/string.c++
kj/string-tree.c++
kj/exception.c++
kj/debug.c++
kj/arena.c++
kj/io.c++
kj/mutex.c++
kj/thread.c++
kj/main.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
kj/async.c++
kj/async-unix.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
capnp/c++.capnp.c++
capnp/blob.c++
capnp/arena.c++
capnp/layout.c++
capnp/list.c++
capnp/any.c++
capnp/message.c++
capnp/schema.capnp.c++
capnp/schema.c++
capnp/schema-loader.c++
capnp/dynamic.c++
capnp/stringify.c++
capnp/serialize.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-lite.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
capnp/serialize-async.c++
capnp/capability.c++
capnp/dynamic-capability.c++
capnp/rpc.c++
capnp/rpc.capnp.c++
capnp/rpc-twoparty.c++
capnp/rpc-twoparty.capnp.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
capnp/compiler/md5.c++
capnp/compiler/error-reporter.c++
capnp/compiler/lexer.capnp.c++
capnp/compiler/lexer.c++
capnp/compiler/grammar.capnp.c++
capnp/compiler/parser.c++
capnp/compiler/node-translator.c++
capnp/compiler/compiler.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
)
if(BUILD_TOOLS)
add_executable(capnp-tool
capnp/compiler/module-loader.c++
capnp/compiler/capnp.c++
)
target_link_libraries(capnp-tool capnpc capnp kj)
set_target_properties(capnp-tool PROPERTIES OUTPUT_NAME capnp)
add_executable(capnpc_cpp
capnp/compiler/capnpc-c++.c++
)
target_link_libraries(capnpc_cpp capnp kj)
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)
if(BUILD_TESTING)
include(CTest)
# Tests ==============================================================
# Setup CAPNP_GENERATE_CPP for compiling test schemas
find_package(CapnProto QUIET)
set(CAPNP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR})
if(BUILD_TESTING)
# Setup googletest build and library targets (gtest and gtest_main)
include(ExternalProject)
ExternalProject_Add(gtest_build
......@@ -237,114 +36,14 @@ if(BUILD_TESTING)
ExternalProject_Get_Property(gtest_build source_dir)
include_directories(${source_dir}/include)
set(test_capnp_files
capnp/test.capnp
capnp/test-import.capnp
capnp/test-import2.capnp
)
# Setup paths to the schema compiler for generating ${test_capnp_files}
if(NOT EXTERNAL_CAPNP)
set(CAPNP_EXECUTABLE $<TARGET_FILE:capnp-tool>)
set(CAPNPC_CXX_EXECUTABLE $<TARGET_FILE:capnpc_cpp>)
else()
# Allow paths to tools to be set with one of: (1) the CMake variables from the
# the FindCapnProto module; (2) environment variables; or (3) find_program()
if (NOT CAPNP_EXECUTABLE)
if (DEFINED ENV{CAPNP})
set(CAPNP_EXECUTABLE $ENV{CAPNP})
else()
find_program(CAPNP_EXECUTABLE capnp)
endif()
endif()
if(NOT CAPNPC_CXX_EXECUTABLE)
if (DEFINED ENV{CAPNPC_CXX})
set(CAPNPC_CXX_EXECUTABLE $ENV{CAPNPC_CXX})
else()
# Also search in the same directory that `capnp` was found in
get_filename_component(capnp_dir ${CAPNP_EXECUTABLE} DIRECTORY)
find_program(CAPNPC_CXX_EXECUTABLE capnpc-c++ HINTS ${capnp_dir})
endif()
endif()
endif()
set(CAPNPC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/test_capnp)
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})
# Sadly, we can't use the 'test' target, as that's coopted by ctest
add_custom_target(check ${CMAKE_CTEST_COMMAND} -V)
endif() # BUILD_TESTING
add_executable(capnp-tests
kj/common-test.c++
kj/memory-test.c++
kj/refcount-test.c++
kj/array-test.c++
kj/string-test.c++
kj/string-tree-test.c++
kj/exception-test.c++
kj/debug-test.c++
kj/arena-test.c++
kj/units-test.c++
kj/tuple-test.c++
kj/one-of-test.c++
kj/function-test.c++
kj/io-test.c++
kj/mutex-test.c++
kj/threadlocal-test.c++
kj/threadlocal-pthread-test.c++
kj/async-test.c++
kj/async-unix-test.c++
kj/async-io-test.c++
kj/parse/common-test.c++
kj/parse/char-test.c++
capnp/common-test.c++
capnp/blob-test.c++
capnp/endian-test.c++
capnp/endian-fallback-test.c++
capnp/endian-reverse-test.c++
capnp/layout-test.c++
capnp/any-test.c++
capnp/message-test.c++
capnp/capability-test.c++
capnp/schema-test.c++
capnp/schema-loader-test.c++
capnp/dynamic-test.c++
capnp/stringify-test.c++
capnp/encoding-test.c++
capnp/orphan-test.c++
capnp/serialize-test.c++
capnp/serialize-async-test.c++
capnp/serialize-packed-test.c++
capnp/rpc-test.c++
capnp/rpc-twoparty-test.c++
capnp/ez-rpc-test.c++
capnp/test-util.c++
capnp/compiler/lexer-test.c++
capnp/compiler/md5-test.c++
${test_capnp_cpp_files}
${test_capnp_h_files}
)
target_link_libraries(capnp-tests
capnpc
capnp-rpc
capnp
kj-async
kj
gtest
gtest_main
)
# kj ===========================================================================
add_executable(capnp-evolution-tests capnp/compiler/evolution-test.c++)
target_link_libraries(capnp-evolution-tests capnpc capnp kj)
add_subdirectory(kj)
include(CTest)
add_test(NAME capnp-tests-run COMMAND capnp-tests)
add_test(NAME capnp-evolution-tests-run COMMAND capnp-evolution-tests)
# capnp ========================================================================
# Sadly, we can't use the 'test' target, as that's coopted by ctest
add_custom_target(check ${CMAKE_CTEST_COMMAND} -V)
add_dependencies(check capnp-tests)
add_dependencies(check capnp-evolution-tests)
endif() # BUILD_TESTING
add_subdirectory(capnp)
# capnp ========================================================================
set(capnp_sources_lite
c++.capnp.c++
blob.c++
arena.c++
layout.c++
list.c++
any.c++
message.c++
schema.capnp.c++
serialize.c++
serialize-packed.c++
)
set(capnp_sources_heavy
schema.c++
schema-loader.c++
dynamic.c++
stringify.c++
)
if(NOT CAPNP_LITE)
set(capnp_sources ${capnp_sources_lite} ${capnp_sources_heavy})
else()
set(capnp_sources ${capnp_sources_lite})
endif()
set(capnp_headers
c++.capnp.h
common.h
blob.h
endian.h
layout.h
orphan.h
list.h
any.h
message.h
capability.h
dynamic.h
schema.h
schema.capnp.h
schema-lite.h
schema-loader.h
schema-parser.h
pretty-print.h
serialize.h
serialize-async.h
serialize-packed.h
pointer-helpers.h
generated-header-support.h
)
add_library(capnp ${capnp_sources})
target_link_libraries(capnp kj)
install(TARGETS capnp ARCHIVE DESTINATION "${LIB_INSTALL_DIR}")
install(FILES ${capnp_headers} DESTINATION "${INCLUDE_INSTALL_DIR}/capnp")
set(capnp-rpc_sources
serialize-async.c++
capability.c++
dynamic-capability.c++
rpc.c++
rpc.capnp.c++
rpc-twoparty.c++
rpc-twoparty.capnp.c++
ez-rpc.c++
)
set(capnp-rpc_headers
rpc-prelude.h
rpc.h
rpc-twoparty.h
rpc.capnp.h
rpc-twoparty.capnp.h
ez-rpc.h
)
if(NOT CAPNP_LITE)
add_library(capnp-rpc ${capnp-rpc_sources})
target_link_libraries(capnp-rpc kj-async kj)
install(TARGETS capnp-rpc ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
install(FILES ${capnp-rpc_headers} DESTINATION ${INCLUDE_INSTALL_DIR}/capnp)
endif()
# Tools/Compilers ==============================================================
set(capnpc_sources
compiler/md5.c++
compiler/error-reporter.c++
compiler/lexer.capnp.c++
compiler/lexer.c++
compiler/grammar.capnp.c++
compiler/parser.c++
compiler/node-translator.c++
compiler/compiler.c++
schema-parser.c++
)
set(capnpc_headers
c++.capnp
schema.capnp
rpc.capnp
rpc-twoparty.capnp
)
if(NOT CAPNP_LITE)
add_library(capnpc ${capnpc_sources})
target_link_libraries(capnpc capnp kj)
install(TARGETS capnpc ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
install(FILES ${capnpc_headers} DESTINATION ${INCLUDE_INSTALL_DIR}/capnp)
endif()
if(BUILD_TOOLS AND NOT CAPNP_LITE)
add_executable(capnp_tool
compiler/module-loader.c++
compiler/capnp.c++
)
target_link_libraries(capnp_tool capnpc capnp kj)
set_target_properties(capnp_tool PROPERTIES OUTPUT_NAME capnp)
add_executable(capnpc_cpp
compiler/capnpc-c++.c++
)
target_link_libraries(capnpc_cpp capnp kj)
set_target_properties(capnpc_cpp PROPERTIES OUTPUT_NAME capnpc-c++)
add_executable(capnpc_capnp
compiler/capnpc-capnp.c++
)
target_link_libraries(capnpc_capnp capnp kj)
set_target_properties(capnpc_capnp PROPERTIES OUTPUT_NAME capnpc-capnp)
install(TARGETS capnp_tool capnpc_cpp capnpc_capnp RUNTIME DESTINATION "${BIN_INSTALL_DIR}")
# Symlink capnpc -> capnp
install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink capnp ${BIN_INSTALL_DIR}/capnpc)")
endif() # BUILD_TOOLS AND NOT CAPNP_LITE
# Tests ========================================================================
if(BUILD_TESTING)
set(test_capnp_files
test.capnp
test-import.capnp
test-import2.capnp
)
# Setup paths to the schema compiler for generating ${test_capnp_files}
if(NOT EXTERNAL_CAPNP)
set(CAPNP_EXECUTABLE $<TARGET_FILE:capnp_tool>)
set(CAPNPC_CXX_EXECUTABLE $<TARGET_FILE:capnpc_cpp>)
else()
# Allow paths to tools to be set with one of: (1) the CMake variables from the
# the FindCapnProto module; (2) environment variables; or (3) find_program()
if (NOT CAPNP_EXECUTABLE)
if (DEFINED ENV{CAPNP})
set(CAPNP_EXECUTABLE $ENV{CAPNP})
else()
find_program(CAPNP_EXECUTABLE capnp)
endif()
endif()
if(NOT CAPNPC_CXX_EXECUTABLE)
if (DEFINED ENV{CAPNPC_CXX})
set(CAPNPC_CXX_EXECUTABLE $ENV{CAPNPC_CXX})
else()
# Also search in the same directory that `capnp` was found in
get_filename_component(capnp_dir ${CAPNP_EXECUTABLE} DIRECTORY)
find_program(CAPNPC_CXX_EXECUTABLE capnpc-c++ HINTS ${capnp_dir})
endif()
endif()
endif()
# Add "/capnp" to match the path used to import the files in the test sources
set(CAPNPC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/test_capnp/capnp)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/test_capnp) # Note: no "/capnp"
file(MAKE_DIRECTORY ${CAPNPC_OUTPUT_DIR})
capnp_generate_cpp(test_capnp_cpp_files test_capnp_h_files ${test_capnp_files})
if(CAPNP_LITE)
set(test_libraries capnp kj gtest gtest_main)
else()
set(test_libraries capnp capnp-rpc capnpc kj kj-async gtest gtest_main)
endif()
add_executable(capnp-tests
common-test.c++
blob-test.c++
endian-test.c++
endian-fallback-test.c++
endian-reverse-test.c++
layout-test.c++
any-test.c++
message-test.c++
encoding-test.c++
orphan-test.c++
serialize-test.c++
serialize-packed-test.c++
test-util.c++
${test_capnp_cpp_files}
${test_capnp_h_files}
)
target_link_libraries(capnp-tests ${test_libraries})
add_dependencies(check capnp-tests)
add_test(NAME capnp-tests-run COMMAND capnp-tests)
if(NOT CAPNP_LITE)
add_executable(capnp-heavy-tests
capability-test.c++
schema-test.c++
schema-loader-test.c++
dynamic-test.c++
stringify-test.c++
serialize-async-test.c++
rpc-test.c++
rpc-twoparty-test.c++
ez-rpc-test.c++
compiler/lexer-test.c++
compiler/md5-test.c++
test-util.c++
${test_capnp_cpp_files}
${test_capnp_h_files}
)
target_link_libraries(capnp-heavy-tests ${test_libraries})
add_dependencies(check capnp-heavy-tests)
add_test(NAME capnp-heavy-tests-run COMMAND capnp-heavy-tests)
add_executable(capnp-evolution-tests compiler/evolution-test.c++)
target_link_libraries(capnp-evolution-tests capnpc capnp kj)
add_dependencies(check capnp-evolution-tests)
add_test(NAME capnp-evolution-tests-run COMMAND capnp-evolution-tests)
endif() # NOT CAPNP_LITE
endif() # BUILD_TESTING
# kj ===========================================================================
set(kj_sources
common.c++
units.c++
memory.c++
refcount.c++
array.c++
string.c++
string-tree.c++
exception.c++
debug.c++
arena.c++
io.c++
mutex.c++
thread.c++
main.c++
parse/char.c++
)
set(kj_headers
common.h
units.h
memory.h
refcount.h
array.h
vector.h
string.h
string-tree.h
exception.h
debug.h
arena.h
io.h
tuple.h
one-of.h
function.h
mutex.h
thread.h
threadlocal.h
time.h
main.h
windows-sanity.h
)
set(kj-parse_headers
parse/common.h
parse/char.h
)
add_library(kj ${kj_sources})
install(TARGETS kj ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
install(FILES ${kj_headers} DESTINATION ${INCLUDE_INSTALL_DIR}/kj)
install(FILES ${kj-parse_headers} DESTINATION ${INCLUDE_INSTALL_DIR}/kj/parse)
set(kj-async_sources
async.c++
async-unix.c++
async-io.c++
)
set(kj-async_headers
async-prelude.h
async.h
async-inl.h
async-unix.h
async-io.h
)
if(NOT CAPNP_LITE)
add_library(kj-async ${kj-async_sources})
target_link_libraries(kj-async kj)
install(TARGETS kj-async ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
install(FILES ${kj-async_headers} DESTINATION ${INCLUDE_INSTALL_DIR}/kj)
endif()
# Tests ========================================================================
if(BUILD_TESTING)
add_executable(kj-tests
common-test.c++
memory-test.c++
refcount-test.c++
array-test.c++
string-test.c++
string-tree-test.c++
exception-test.c++
debug-test.c++
arena-test.c++
units-test.c++
tuple-test.c++
one-of-test.c++
function-test.c++
io-test.c++
mutex-test.c++
threadlocal-test.c++
threadlocal-pthread-test.c++
)
# TODO: Link with librt on Solaris for sched_yield
target_link_libraries(kj-tests kj gtest gtest_main)
add_dependencies(check kj-tests)
add_test(NAME kj-tests-run COMMAND kj-tests)
if(NOT CAPNP_LITE)
add_executable(kj-heavy-tests
async-test.c++
async-unix-test.c++
async-io-test.c++
parse/common-test.c++
parse/char-test.c++
)
target_link_libraries(kj-heavy-tests kj kj-async gtest gtest_main)
add_dependencies(check kj-heavy-tests)
add_test(NAME kj-heavy-tests-run COMMAND kj-heavy-tests)
endif() # NOT CAPNP_LITE
endif() # BUILD_TESTING
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