cannam@133: project("Cap'n Proto" CXX) cannam@133: cmake_minimum_required(VERSION 3.0) cannam@133: set(VERSION 0.6-dev) cannam@133: cannam@133: set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") cannam@133: cannam@133: include(CheckIncludeFileCXX) cannam@133: include(GNUInstallDirs) cannam@133: if(MSVC) cannam@133: check_include_file_cxx(initializer_list HAS_CXX11) cannam@133: else() cannam@133: check_include_file_cxx(initializer_list HAS_CXX11 "-std=gnu++0x") cannam@133: endif() cannam@133: if(NOT HAS_CXX11) cannam@133: message(SEND_ERROR "Requires a C++11 compiler and standard library.") cannam@133: endif() cannam@133: cannam@133: # these arguments are passed to all install(TARGETS) calls cannam@133: set(INSTALL_TARGETS_DEFAULT_ARGS cannam@133: EXPORT CapnProtoTargets cannam@133: ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" cannam@133: LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" cannam@133: RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" cannam@133: ) cannam@133: cannam@133: # Options ====================================================================== cannam@133: cannam@133: option(BUILD_TESTING "Build unit tests and enable CTest 'check' target." ON) cannam@133: option(EXTERNAL_CAPNP "Use the system capnp binary, or the one specified in $CAPNP, instead of using the compiled one." OFF) cannam@133: 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." OFF) cannam@133: cannam@133: # Check for invalid combinations of build options cannam@133: if(CAPNP_LITE AND BUILD_TESTING AND NOT EXTERNAL_CAPNP) cannam@133: message(SEND_ERROR "You must set EXTERNAL_CAPNP when using CAPNP_LITE and BUILD_TESTING.") cannam@133: endif() cannam@133: cannam@133: cannam@133: if(MSVC AND NOT CAPNP_LITE) cannam@133: message(SEND_ERROR "Building with MSVC is only supported with CAPNP_LITE.") cannam@133: endif() cannam@133: cannam@133: if(CAPNP_LITE) cannam@133: set(CAPNP_LITE_FLAG "-DCAPNP_LITE") cannam@133: # This flag is attached as PUBLIC target_compile_definition to kj target cannam@133: else() cannam@133: set(CAPNP_LITE_FLAG) cannam@133: endif() cannam@133: cannam@133: if(MSVC) cannam@133: # TODO(cleanup): Enable higher warning level in MSVC, but make sure to test cannam@133: # build with that warning level and clean out false positives. cannam@133: else() cannam@133: # Note that it's important to add new CXXFLAGS before ones specified by the cannam@133: # user, so that the user's flags override them. This is particularly cannam@133: # important if -Werror was enabled and then certain warnings need to be cannam@133: # disabled, as is done in super-test.sh. cannam@133: # cannam@133: # We enable a lot of warnings, but then disable some: cannam@133: # * strict-aliasing: We use type-punning in known-safe ways that GCC doesn't cannam@133: # recognize as safe. cannam@133: # * sign-compare: Low S/N ratio. cannam@133: # * unused-parameter: Low S/N ratio. cannam@133: # cannam@133: # We have to use -std=gnu++0x isntead of -std=c++11 because otherwise we lose cannam@133: # GNU extensions that we need. cannam@133: add_compile_options(-std=gnu++0x -Wall -Wextra -Wno-strict-aliasing -Wno-sign-compare -Wno-unused-parameter) cannam@133: cannam@133: if (NOT ANDROID) cannam@133: add_compile_options(-pthread) cannam@133: endif() cannam@133: endif() cannam@133: cannam@133: # Source ======================================================================= cannam@133: include(CapnProtoMacros) cannam@133: add_subdirectory(src) cannam@133: cannam@133: # Install ====================================================================== cannam@133: cannam@133: include(CMakePackageConfigHelpers) cannam@133: write_basic_package_version_file( cannam@133: "${CMAKE_CURRENT_BINARY_DIR}/cmake/CapnProtoConfigVersion.cmake" cannam@133: VERSION ${VERSION} cannam@133: COMPATIBILITY AnyNewerVersion cannam@133: ) cannam@133: set(CONFIG_PACKAGE_LOCATION ${CMAKE_INSTALL_LIBDIR}/cmake/CapnProto) cannam@133: cannam@133: configure_package_config_file(cmake/CapnProtoConfig.cmake.in cannam@133: ${CMAKE_CURRENT_BINARY_DIR}/cmake/CapnProtoConfig.cmake cannam@133: INSTALL_DESTINATION ${CONFIG_PACKAGE_LOCATION} cannam@133: PATH_VARS CMAKE_INSTALL_FULL_INCLUDEDIR cannam@133: ) cannam@133: export(EXPORT CapnProtoTargets cannam@133: FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/CapnProtoTargets.cmake" cannam@133: NAMESPACE CapnProto:: cannam@133: ) cannam@133: install(EXPORT CapnProtoTargets cannam@133: FILE CapnProtoTargets.cmake cannam@133: NAMESPACE CapnProto:: cannam@133: DESTINATION ${CONFIG_PACKAGE_LOCATION} cannam@133: ) cannam@133: install(FILES cannam@133: cmake/CapnProtoMacros.cmake cannam@133: ${CMAKE_CURRENT_BINARY_DIR}/cmake/CapnProtoConfig.cmake cannam@133: ${CMAKE_CURRENT_BINARY_DIR}/cmake/CapnProtoConfigVersion.cmake cannam@133: DESTINATION ${CONFIG_PACKAGE_LOCATION} cannam@133: ) cannam@133: #install CapnProtoMacros for CapnProtoConfig.cmake build directory consumers cannam@133: configure_file(cmake/CapnProtoMacros.cmake cmake/CapnProtoMacros.cmake COPYONLY) cannam@133: cannam@133: if(NOT MSVC) # Don't install pkg-config files when building with MSVC cannam@133: # Variables for pkg-config files cannam@133: set(prefix "${CMAKE_INSTALL_PREFIX}") cannam@133: set(exec_prefix "") # not needed since we use absolute paths in libdir and includedir cannam@133: set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}") cannam@133: set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}") cannam@133: set(PTHREAD_CFLAGS "-pthread") cannam@133: set(STDLIB_FLAG) # TODO: Unsupported cannam@133: cannam@133: configure_file(kj.pc.in "${CMAKE_CURRENT_BINARY_DIR}/kj.pc" @ONLY) cannam@133: install(FILES "${CMAKE_CURRENT_BINARY_DIR}/kj.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") cannam@133: cannam@133: configure_file(capnp.pc.in "${CMAKE_CURRENT_BINARY_DIR}/capnp.pc" @ONLY) cannam@133: install(FILES "${CMAKE_CURRENT_BINARY_DIR}/capnp.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") cannam@133: cannam@133: if(NOT CAPNP_LITE) cannam@133: configure_file(kj-async.pc.in "${CMAKE_CURRENT_BINARY_DIR}/kj-async.pc" @ONLY) cannam@133: install(FILES "${CMAKE_CURRENT_BINARY_DIR}/kj-async.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") cannam@133: cannam@133: configure_file(capnp-rpc.pc.in "${CMAKE_CURRENT_BINARY_DIR}/capnp-rpc.pc" @ONLY) cannam@133: install(FILES "${CMAKE_CURRENT_BINARY_DIR}/capnp-rpc.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") cannam@133: cannam@133: configure_file(capnp-json.pc.in "${CMAKE_CURRENT_BINARY_DIR}/capnp-json.pc" @ONLY) cannam@133: install(FILES "${CMAKE_CURRENT_BINARY_DIR}/capnp-json.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") cannam@133: endif() cannam@133: cannam@133: unset(STDLIB_FLAG) cannam@133: unset(PTHREAD_CFLAGS) cannam@133: unset(includedir) cannam@133: unset(libdir) cannam@133: unset(exec_prefix) cannam@133: unset(prefix) cannam@133: endif()