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