annotate src/capnproto-git-20161025/c++/CMakeLists.txt @ 133:1ac99bfc383d

Add Cap'n Proto source
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 25 Oct 2016 11:17:01 +0100
parents
children
rev   line source
cannam@133 1 project("Cap'n Proto" CXX)
cannam@133 2 cmake_minimum_required(VERSION 3.0)
cannam@133 3 set(VERSION 0.6-dev)
cannam@133 4
cannam@133 5 set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
cannam@133 6
cannam@133 7 include(CheckIncludeFileCXX)
cannam@133 8 include(GNUInstallDirs)
cannam@133 9 if(MSVC)
cannam@133 10 check_include_file_cxx(initializer_list HAS_CXX11)
cannam@133 11 else()
cannam@133 12 check_include_file_cxx(initializer_list HAS_CXX11 "-std=gnu++0x")
cannam@133 13 endif()
cannam@133 14 if(NOT HAS_CXX11)
cannam@133 15 message(SEND_ERROR "Requires a C++11 compiler and standard library.")
cannam@133 16 endif()
cannam@133 17
cannam@133 18 # these arguments are passed to all install(TARGETS) calls
cannam@133 19 set(INSTALL_TARGETS_DEFAULT_ARGS
cannam@133 20 EXPORT CapnProtoTargets
cannam@133 21 ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
cannam@133 22 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
cannam@133 23 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
cannam@133 24 )
cannam@133 25
cannam@133 26 # Options ======================================================================
cannam@133 27
cannam@133 28 option(BUILD_TESTING "Build unit tests and enable CTest 'check' target." ON)
cannam@133 29 option(EXTERNAL_CAPNP "Use the system capnp binary, or the one specified in $CAPNP, instead of using the compiled one." OFF)
cannam@133 30 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 31
cannam@133 32 # Check for invalid combinations of build options
cannam@133 33 if(CAPNP_LITE AND BUILD_TESTING AND NOT EXTERNAL_CAPNP)
cannam@133 34 message(SEND_ERROR "You must set EXTERNAL_CAPNP when using CAPNP_LITE and BUILD_TESTING.")
cannam@133 35 endif()
cannam@133 36
cannam@133 37
cannam@133 38 if(MSVC AND NOT CAPNP_LITE)
cannam@133 39 message(SEND_ERROR "Building with MSVC is only supported with CAPNP_LITE.")
cannam@133 40 endif()
cannam@133 41
cannam@133 42 if(CAPNP_LITE)
cannam@133 43 set(CAPNP_LITE_FLAG "-DCAPNP_LITE")
cannam@133 44 # This flag is attached as PUBLIC target_compile_definition to kj target
cannam@133 45 else()
cannam@133 46 set(CAPNP_LITE_FLAG)
cannam@133 47 endif()
cannam@133 48
cannam@133 49 if(MSVC)
cannam@133 50 # TODO(cleanup): Enable higher warning level in MSVC, but make sure to test
cannam@133 51 # build with that warning level and clean out false positives.
cannam@133 52 else()
cannam@133 53 # Note that it's important to add new CXXFLAGS before ones specified by the
cannam@133 54 # user, so that the user's flags override them. This is particularly
cannam@133 55 # important if -Werror was enabled and then certain warnings need to be
cannam@133 56 # disabled, as is done in super-test.sh.
cannam@133 57 #
cannam@133 58 # We enable a lot of warnings, but then disable some:
cannam@133 59 # * strict-aliasing: We use type-punning in known-safe ways that GCC doesn't
cannam@133 60 # recognize as safe.
cannam@133 61 # * sign-compare: Low S/N ratio.
cannam@133 62 # * unused-parameter: Low S/N ratio.
cannam@133 63 #
cannam@133 64 # We have to use -std=gnu++0x isntead of -std=c++11 because otherwise we lose
cannam@133 65 # GNU extensions that we need.
cannam@133 66 add_compile_options(-std=gnu++0x -Wall -Wextra -Wno-strict-aliasing -Wno-sign-compare -Wno-unused-parameter)
cannam@133 67
cannam@133 68 if (NOT ANDROID)
cannam@133 69 add_compile_options(-pthread)
cannam@133 70 endif()
cannam@133 71 endif()
cannam@133 72
cannam@133 73 # Source =======================================================================
cannam@133 74 include(CapnProtoMacros)
cannam@133 75 add_subdirectory(src)
cannam@133 76
cannam@133 77 # Install ======================================================================
cannam@133 78
cannam@133 79 include(CMakePackageConfigHelpers)
cannam@133 80 write_basic_package_version_file(
cannam@133 81 "${CMAKE_CURRENT_BINARY_DIR}/cmake/CapnProtoConfigVersion.cmake"
cannam@133 82 VERSION ${VERSION}
cannam@133 83 COMPATIBILITY AnyNewerVersion
cannam@133 84 )
cannam@133 85 set(CONFIG_PACKAGE_LOCATION ${CMAKE_INSTALL_LIBDIR}/cmake/CapnProto)
cannam@133 86
cannam@133 87 configure_package_config_file(cmake/CapnProtoConfig.cmake.in
cannam@133 88 ${CMAKE_CURRENT_BINARY_DIR}/cmake/CapnProtoConfig.cmake
cannam@133 89 INSTALL_DESTINATION ${CONFIG_PACKAGE_LOCATION}
cannam@133 90 PATH_VARS CMAKE_INSTALL_FULL_INCLUDEDIR
cannam@133 91 )
cannam@133 92 export(EXPORT CapnProtoTargets
cannam@133 93 FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/CapnProtoTargets.cmake"
cannam@133 94 NAMESPACE CapnProto::
cannam@133 95 )
cannam@133 96 install(EXPORT CapnProtoTargets
cannam@133 97 FILE CapnProtoTargets.cmake
cannam@133 98 NAMESPACE CapnProto::
cannam@133 99 DESTINATION ${CONFIG_PACKAGE_LOCATION}
cannam@133 100 )
cannam@133 101 install(FILES
cannam@133 102 cmake/CapnProtoMacros.cmake
cannam@133 103 ${CMAKE_CURRENT_BINARY_DIR}/cmake/CapnProtoConfig.cmake
cannam@133 104 ${CMAKE_CURRENT_BINARY_DIR}/cmake/CapnProtoConfigVersion.cmake
cannam@133 105 DESTINATION ${CONFIG_PACKAGE_LOCATION}
cannam@133 106 )
cannam@133 107 #install CapnProtoMacros for CapnProtoConfig.cmake build directory consumers
cannam@133 108 configure_file(cmake/CapnProtoMacros.cmake cmake/CapnProtoMacros.cmake COPYONLY)
cannam@133 109
cannam@133 110 if(NOT MSVC) # Don't install pkg-config files when building with MSVC
cannam@133 111 # Variables for pkg-config files
cannam@133 112 set(prefix "${CMAKE_INSTALL_PREFIX}")
cannam@133 113 set(exec_prefix "") # not needed since we use absolute paths in libdir and includedir
cannam@133 114 set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
cannam@133 115 set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
cannam@133 116 set(PTHREAD_CFLAGS "-pthread")
cannam@133 117 set(STDLIB_FLAG) # TODO: Unsupported
cannam@133 118
cannam@133 119 configure_file(kj.pc.in "${CMAKE_CURRENT_BINARY_DIR}/kj.pc" @ONLY)
cannam@133 120 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/kj.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
cannam@133 121
cannam@133 122 configure_file(capnp.pc.in "${CMAKE_CURRENT_BINARY_DIR}/capnp.pc" @ONLY)
cannam@133 123 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/capnp.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
cannam@133 124
cannam@133 125 if(NOT CAPNP_LITE)
cannam@133 126 configure_file(kj-async.pc.in "${CMAKE_CURRENT_BINARY_DIR}/kj-async.pc" @ONLY)
cannam@133 127 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/kj-async.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
cannam@133 128
cannam@133 129 configure_file(capnp-rpc.pc.in "${CMAKE_CURRENT_BINARY_DIR}/capnp-rpc.pc" @ONLY)
cannam@133 130 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/capnp-rpc.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
cannam@133 131
cannam@133 132 configure_file(capnp-json.pc.in "${CMAKE_CURRENT_BINARY_DIR}/capnp-json.pc" @ONLY)
cannam@133 133 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/capnp-json.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
cannam@133 134 endif()
cannam@133 135
cannam@133 136 unset(STDLIB_FLAG)
cannam@133 137 unset(PTHREAD_CFLAGS)
cannam@133 138 unset(includedir)
cannam@133 139 unset(libdir)
cannam@133 140 unset(exec_prefix)
cannam@133 141 unset(prefix)
cannam@133 142 endif()