cpack: fix packaging directory for CMake <=3.11
[awesomized/libmemcached] / src / libmemcached / CMakeLists.txt
1 find_package(FLEX)
2 find_package(BISON 2.3)
3
4 if("${BISON_VERSION}" VERSION_GREATER_EQUAL 3.0)
5 set(BISON_WARNINGS -Wno-deprecated)
6 endif()
7
8 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/csl)
9 bison_target(CSL_PARSER csl/parser.yy ${CMAKE_CURRENT_BINARY_DIR}/csl/parser.cc
10 DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/csl/parser.h
11 COMPILE_FLAGS ${BISON_WARNINGS}
12 )
13 set_source_files_properties(${BISON_CSL_PARSER_OUTPUTS} PROPERTIES
14 SKIP_UNITY_BUILD_INCLUSION ON)
15 if(NOT HAVE_UNISTD_H)
16 set(FLEX_FLAGS --nounistd)
17 endif()
18 flex_target(CSL_SCANNER csl/scanner.l ${CMAKE_CURRENT_BINARY_DIR}/csl/scanner.cc
19 DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/csl/scanner.h
20 COMPILE_FLAGS "${FLEX_FLAGS}"
21 )
22 set_source_files_properties(${FLEX_CSL_SCANNER_OUTPUTS} PROPERTIES
23 SKIP_UNITY_BUILD_INCLUSION ON)
24 add_flex_bison_dependency(CSL_SCANNER CSL_PARSER)
25
26 set(libmemcached_sources
27 csl/context.cc
28 ${FLEX_CSL_SCANNER_OUTPUTS}
29 ${BISON_CSL_PARSER_OUTPUTS}
30 allocators.cc
31 analyze.cc
32 array.cc
33 auto.cc
34 backtrace.cc
35 behavior.cc
36 byteorder.cc
37 callback.cc
38 common.h
39 connect.cc
40 delete.cc
41 do.cc
42 dump.cc
43 encoding_key.cc
44 error.cc
45 exist.cc
46 fetch.cc
47 flag.cc
48 flush.cc
49 flush_buffers.cc
50 get.cc
51 hash.cc
52 hosts.cc
53 initialize_query.cc
54 instance.cc
55 io.cc
56 key.cc
57 memcached.cc
58 namespace.cc
59 options.cc
60 parse.cc
61 purge.cc
62 quit.cc
63 response.cc
64 result.cc
65 sasl.cc
66 server.cc
67 server_list.cc
68 stats.cc
69 storage.cc
70 strerror.cc
71 string.cc
72 touch.cc
73 udp.cc
74 verbosity.cc
75 version.cc
76 virtual_bucket.cc)
77
78 check_cxx_compiler_flag(-Wno-deprecated-register W_NO_DEPRECATED_REGISTER)
79
80 if(W_NO_DEPRECATED_REGISTER)
81 set_source_files_properties(
82 ${FLEX_CSL_SCANNER_OUTPUTS}
83 ${BISON_CSL_PARSER_OUTPUTS}
84 PROPERTIES COMPILE_OPTIONS -Wno-deprecated-register
85 )
86 endif()
87
88 add_library(libmemcached SHARED)
89 add_library(memcached ALIAS libmemcached)
90 set_target_properties(libmemcached PROPERTIES
91 CXX_STANDARD ${CXX_STANDARD}
92 LIBRARY_OUTPUT_NAME memcached
93 LIBRARY_OUTPUT_NAME_DEBUG memcached-dbg
94 SOVERSION ${LIBMEMCACHED_SO_SOVERSION}
95 VERSION ${LIBMEMCACHED_SO_VERSION})
96 target_compile_definitions(libmemcached PRIVATE -DBUILDING_LIBMEMCACHED)
97 target_link_libraries(libmemcached PUBLIC libhashkit Threads::Threads ${CMAKE_DL_LIBS})
98 target_link_libraries(libmemcached PRIVATE p9y)
99 if(MSVC)
100 target_link_libraries(libmemcached PUBLIC wsock32 ws2_32)
101 endif()
102 if(HAVE_BACKTRACE)
103 target_link_libraries(libmemcached PUBLIC ${BACKTRACE})
104 endif()
105 if(HAVE_LIBSASL)
106 target_link_libraries(libmemcached PUBLIC ${LIBSASL})
107 endif()
108 if(CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
109 # see https://docs.oracle.com/cd/E77782_01/html/E77789/bkamq.html#OSSCPgrxeu
110 target_link_libraries(libmemcached INTERFACE stdc++ gcc_s CrunG3 c)
111 endif()
112 target_include_directories(libmemcached PRIVATE
113 ${CMAKE_SOURCE_DIR}/src
114 ${CMAKE_BINARY_DIR}/src
115 ${CMAKE_BINARY_DIR})
116 target_include_directories(libmemcached PUBLIC
117 $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
118 $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
119 $<INSTALL_INTERFACE:include>)
120
121 enable_dtrace_for(libmemcached libmemcached_probes.d dtrace_probes.h)
122
123 install(TARGETS libmemcached EXPORT libmemcached-targets
124 RUNTIME COMPONENT bin DESTINATION ${CMAKE_INSTALL_BINDIR}
125 ARCHIVE COMPONENT lib DESTINATION ${CMAKE_INSTALL_LIBDIR}
126 LIBRARY COMPONENT lib DESTINATION ${CMAKE_INSTALL_LIBDIR}
127 ${TARGET_NAMELINK_COMPONENT}
128 )
129 export(EXPORT libmemcached-targets NAMESPACE libmemcached::)
130 install(EXPORT libmemcached-targets NAMESPACE libmemcached::
131 COMPONENT dev
132 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
133
134 install_public_headers(
135 libmemcached
136
137 memcached.h
138 memcached.hpp
139 util.h
140 )
141
142 target_sources(libmemcached PRIVATE
143 ${libmemcached_sources}
144 ${libmemcached_includes})
145
146 # TODO: do we really need this?
147
148 add_library(libmemcachedinternal STATIC)
149 add_library(memcachedinternal ALIAS libmemcachedinternal)
150 set_target_properties(libmemcachedinternal PROPERTIES CXX_STANDARD ${CXX_STANDARD} LIBRARY_OUTPUT_NAME memcachedinternal)
151 target_compile_definitions(libmemcachedinternal PRIVATE -DBUILDING_LIBMEMCACHEDINTERNAL)
152 target_link_libraries(libmemcachedinternal PUBLIC libhashkit Threads::Threads ${CMAKE_DL_LIBS})
153 target_link_libraries(libmemcachedinternal PRIVATE p9y)
154 if(MSVC OR MINGW)
155 target_link_libraries(libmemcached PUBLIC wsock32 ws2_32)
156 endif()
157 if(HAVE_LIBSASL)
158 target_link_libraries(libmemcachedinternal PUBLIC ${LIBSASL})
159 endif()
160 if(HAVE_BACKTRACE)
161 target_link_libraries(libmemcachedinternal PUBLIC ${BACKTRACE})
162 endif()
163 target_include_directories(libmemcachedinternal PRIVATE
164 ${CMAKE_SOURCE_DIR}/src
165 ${CMAKE_BINARY_DIR}/src
166 ${CMAKE_BINARY_DIR})
167 target_include_directories(libmemcachedinternal PUBLIC
168 $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
169 $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
170 $<INSTALL_INTERFACE:include>)
171
172 enable_dtrace_for(libmemcachedinternal libmemcached_probes.d dtrace_probes.h)
173
174 # let libmemcached depend on libmemcachedinternal to ensure that they do not
175 # compete for the same generated dependencies
176 add_dependencies(libmemcached libmemcachedinternal)
177
178 target_sources(libmemcachedinternal PRIVATE
179 ${libmemcached_sources}
180 ${libmemcached_includes})