annotate src/capnproto-0.6.0/c++/CMakeLists.txt @ 148:b4bfdf10c4b3

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