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