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