annotate src/capnproto-git-20161025/c++/CMakeLists.txt @ 83:ae30d91d2ffe

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