Commit ae36935d authored by Philip Quinn's avatar Philip Quinn

Support disabling builds of the command-line tools and unit tests, and using an external compiler.

parent 4157aa8f
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)
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)
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")
add_subdirectory(src) add_subdirectory(src)
...@@ -148,41 +148,57 @@ set(capnpc_headers ...@@ -148,41 +148,57 @@ set(capnpc_headers
capnp/rpc-twoparty.capnp capnp/rpc-twoparty.capnp
) )
add_executable(capnp-tool if(BUILD_TOOLS)
capnp/compiler/module-loader.c++ add_executable(capnp-tool
capnp/compiler/capnp.c++ 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) 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++ 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++) 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++ 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) target_link_libraries(capnpc_capnp capnp kj)
set_target_properties(capnpc_capnp PROPERTIES OUTPUT_NAME capnpc-capnp)
endif() # BUILD_TOOLS
# Install ============================================================== # Install ==============================================================
export(TARGETS capnp capnp-tool capnp-rpc capnpc capnpc_cpp capnpc_capnp kj kj-async if(BUILD_TOOLS)
FILE ${CMAKE_CURRENT_BINARY_DIR}/capnp-config.cmake 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) export(PACKAGE capnp)
install(TARGETS capnp capnp-tool capnp-rpc capnpc capnpc_cpp capnpc_capnp kj kj-async if(BUILD_TOOLS)
EXPORT capnp install(TARGETS capnp capnp-tool capnp-rpc capnpc capnpc_cpp capnpc_capnp kj kj-async
RUNTIME DESTINATION bin EXPORT capnp
LIBRARY DESTINATION lib RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib 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)") # 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_headers} DESTINATION include/kj)
install(FILES ${kj-async_headers} DESTINATION include/kj) install(FILES ${kj-async_headers} DESTINATION include/kj)
...@@ -193,115 +209,141 @@ install(FILES ${capnpc_headers} DESTINATION include/capnp) ...@@ -193,115 +209,141 @@ install(FILES ${capnpc_headers} DESTINATION include/capnp)
# Tests ============================================================== # Tests ==============================================================
# Setup googletest build and library targets (gtest and gtest_main) if(BUILD_TESTING)
include(ExternalProject) # Setup googletest build and library targets (gtest and gtest_main)
ExternalProject_Add(gtest_build include(ExternalProject)
URL http://googletest.googlecode.com/files/gtest-1.7.0.zip ExternalProject_Add(gtest_build
URL_HASH SHA1=f85f6d2481e2c6c4a18539e391aa4ea8ab0394af URL http://googletest.googlecode.com/files/gtest-1.7.0.zip
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} URL_HASH SHA1=f85f6d2481e2c6c4a18539e391aa4ea8ab0394af
INSTALL_COMMAND "" # Disable install CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
) INSTALL_COMMAND "" # Disable install
)
ExternalProject_Get_Property(gtest_build binary_dir)
ExternalProject_Get_Property(gtest_build binary_dir)
add_library(gtest UNKNOWN IMPORTED)
set_property(TARGET gtest add_library(gtest UNKNOWN IMPORTED)
PROPERTY IMPORTED_LOCATION ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest.a set_property(TARGET gtest
) PROPERTY IMPORTED_LOCATION ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest.a
add_dependencies(gtest gtest_build) )
add_dependencies(gtest gtest_build)
add_library(gtest_main UNKNOWN IMPORTED)
set_property(TARGET gtest_main add_library(gtest_main UNKNOWN IMPORTED)
PROPERTY IMPORTED_LOCATION ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main.a set_property(TARGET gtest_main
) PROPERTY IMPORTED_LOCATION ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main.a
add_dependencies(gtest_main gtest) )
add_dependencies(gtest_main gtest)
ExternalProject_Get_Property(gtest_build source_dir)
include_directories(${source_dir}/include) ExternalProject_Get_Property(gtest_build source_dir)
include_directories(${source_dir}/include)
set(test_capnp_files
capnp/test.capnp set(test_capnp_files
capnp/test-import.capnp capnp/test.capnp
capnp/test-import2.capnp capnp/test-import.capnp
) capnp/test-import2.capnp
)
set(CAPNP_EXECUTABLE $<TARGET_FILE:capnp-tool>)
set(CAPNPC_CXX_EXECUTABLE $<TARGET_FILE:capnpc_cpp>) # Setup paths to the schema compiler for generating ${test_capnp_files}
set(CAPNPC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/test_capnp) if(NOT EXTERNAL_CAPNP)
file(MAKE_DIRECTORY ${CAPNPC_OUTPUT_DIR}) set(CAPNP_EXECUTABLE $<TARGET_FILE:capnp-tool>)
set(CAPNPC_CXX_EXECUTABLE $<TARGET_FILE:capnpc_cpp>)
capnp_generate_cpp(test_capnp_cpp_files test_capnp_h_files ${test_capnp_files}) else()
# Allow paths to tools to be set with one of: (1) the CMake variables from the
include_directories(${CAPNPC_OUTPUT_DIR}) # the FindCapnProto module; (2) environment variables; or (3) find_program()
if (NOT CAPNP_EXECUTABLE)
add_executable(capnp-tests if (DEFINED ENV{CAPNP})
kj/common-test.c++ set(CAPNP_EXECUTABLE $ENV{CAPNP})
kj/memory-test.c++ else()
kj/refcount-test.c++ find_program(CAPNP_EXECUTABLE capnp)
kj/array-test.c++ endif()
kj/string-test.c++ endif()
kj/string-tree-test.c++
kj/exception-test.c++ if(NOT CAPNPC_CXX_EXECUTABLE)
kj/debug-test.c++ if (DEFINED ENV{CAPNPC_CXX})
kj/arena-test.c++ set(CAPNPC_CXX_EXECUTABLE $ENV{CAPNPC_CXX})
kj/units-test.c++ else()
kj/tuple-test.c++ # Also search in the same directory that `capnp` was found in
kj/one-of-test.c++ get_filename_component(capnp_dir ${CAPNP_EXECUTABLE} DIRECTORY)
kj/function-test.c++ find_program(CAPNPC_CXX_EXECUTABLE capnpc-c++ HINTS ${capnp_dir})
kj/io-test.c++ endif()
kj/mutex-test.c++ endif()
kj/threadlocal-test.c++ endif()
kj/threadlocal-pthread-test.c++
kj/async-test.c++ set(CAPNPC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/test_capnp)
kj/async-unix-test.c++ file(MAKE_DIRECTORY ${CAPNPC_OUTPUT_DIR})
kj/async-io-test.c++
kj/parse/common-test.c++ capnp_generate_cpp(test_capnp_cpp_files test_capnp_h_files ${test_capnp_files})
kj/parse/char-test.c++
capnp/common-test.c++ include_directories(${CAPNPC_OUTPUT_DIR})
capnp/blob-test.c++
capnp/endian-test.c++ add_executable(capnp-tests
capnp/endian-fallback-test.c++ kj/common-test.c++
capnp/endian-reverse-test.c++ kj/memory-test.c++
capnp/layout-test.c++ kj/refcount-test.c++
capnp/any-test.c++ kj/array-test.c++
capnp/message-test.c++ kj/string-test.c++
capnp/capability-test.c++ kj/string-tree-test.c++
capnp/schema-test.c++ kj/exception-test.c++
capnp/schema-loader-test.c++ kj/debug-test.c++
capnp/dynamic-test.c++ kj/arena-test.c++
capnp/stringify-test.c++ kj/units-test.c++
capnp/encoding-test.c++ kj/tuple-test.c++
capnp/orphan-test.c++ kj/one-of-test.c++
capnp/serialize-test.c++ kj/function-test.c++
capnp/serialize-async-test.c++ kj/io-test.c++
capnp/serialize-packed-test.c++ kj/mutex-test.c++
capnp/rpc-test.c++ kj/threadlocal-test.c++
capnp/rpc-twoparty-test.c++ kj/threadlocal-pthread-test.c++
capnp/ez-rpc-test.c++ kj/async-test.c++
capnp/test-util.c++ kj/async-unix-test.c++
capnp/compiler/lexer-test.c++ kj/async-io-test.c++
capnp/compiler/md5-test.c++ kj/parse/common-test.c++
${test_capnp_cpp_files} kj/parse/char-test.c++
${test_capnp_h_files} capnp/common-test.c++
) capnp/blob-test.c++
target_link_libraries(capnp-tests capnp/endian-test.c++
capnpc capnp/endian-fallback-test.c++
capnp-rpc capnp/endian-reverse-test.c++
capnp capnp/layout-test.c++
kj-async capnp/any-test.c++
kj capnp/message-test.c++
gtest capnp/capability-test.c++
gtest_main capnp/schema-test.c++
) capnp/schema-loader-test.c++
capnp/dynamic-test.c++
add_executable(capnp-evolution-tests capnp/compiler/evolution-test.c++) capnp/stringify-test.c++
target_link_libraries(capnp-evolution-tests capnpc capnp kj) capnp/encoding-test.c++
capnp/orphan-test.c++
include(CTest) capnp/serialize-test.c++
add_test(NAME capnp-tests-run COMMAND capnp-tests) capnp/serialize-async-test.c++
add_test(NAME capnp-evolution-tests-run COMMAND capnp-evolution-tests) capnp/serialize-packed-test.c++
capnp/rpc-test.c++
# Sadly, we can't use the 'test' target, as that's coopted by ctest capnp/rpc-twoparty-test.c++
add_custom_target(check ${CMAKE_CTEST_COMMAND} -V) capnp/ez-rpc-test.c++
add_dependencies(check capnp-tests) capnp/test-util.c++
add_dependencies(check capnp-evolution-tests) 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
)
add_executable(capnp-evolution-tests capnp/compiler/evolution-test.c++)
target_link_libraries(capnp-evolution-tests capnpc capnp kj)
include(CTest)
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
add_custom_target(check ${CMAKE_CTEST_COMMAND} -V)
add_dependencies(check capnp-tests)
add_dependencies(check capnp-evolution-tests)
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