Skip to content

Commit 0912068

Browse files
committed
feat conan: reuse config files from CMake
Fixes: #813 Tests: протестировано локально и в CI commit_hash:049cca416769bba2254b11c19f5d41a957cce6cc
1 parent 3dfd60d commit 0912068

File tree

1 file changed

+3
-368
lines changed

1 file changed

+3
-368
lines changed

conanfile.py

Lines changed: 3 additions & 368 deletions
Original file line numberDiff line numberDiff line change
@@ -238,372 +238,7 @@ def package(self):
238238
cmake = CMake(self)
239239
cmake.install()
240240

241-
@property
242-
def _userver_components(self):
243-
def abseil():
244-
return ['abseil::abseil']
245-
246-
def ares():
247-
return ['c-ares::c-ares']
248-
249-
def fmt():
250-
return ['fmt::fmt']
251-
252-
def curl():
253-
return ['libcurl::libcurl']
254-
255-
def cryptopp():
256-
return ['cryptopp::cryptopp']
257-
258-
def cctz():
259-
return ['cctz::cctz']
260-
261-
def boost():
262-
return ['boost::boost']
263-
264-
def concurrentqueue():
265-
return ['concurrentqueue::concurrentqueue']
266-
267-
def yaml():
268-
return ['yaml-cpp::yaml-cpp']
269-
270-
def iconv():
271-
return ['libiconv::libiconv']
272-
273-
def libev():
274-
return ['libev::libev']
275-
276-
def libnghttp2():
277-
return ['libnghttp2::libnghttp2']
278-
279-
def openssl():
280-
return ['openssl::openssl']
281-
282-
def rapidjson():
283-
return ['rapidjson::rapidjson']
284-
285-
def zlib():
286-
return ['zlib::zlib']
287-
288-
def zstd():
289-
# According to https://conan.io/center/recipes/zstd should be
290-
# zstd::libzstd_static, but it does not work that way
291-
return ['zstd::zstd']
292-
293-
def jemalloc():
294-
return ['jemalloc::jemalloc'] if self.options.with_jemalloc else []
295-
296-
def grpc():
297-
return ['grpc::grpc'] if self.options.with_grpc else []
298-
299-
def protobuf():
300-
return ['protobuf::protobuf'] if self.options.with_grpc else []
301-
302-
def postgresql():
303-
return ['libpq::pq'] if self.options.with_postgresql else []
304-
305-
def gtest():
306-
return ['gtest::gtest'] if self.options.with_utest else []
307-
308-
def benchmark():
309-
return ['benchmark::benchmark'] if self.options.with_utest else []
310-
311-
def mongo():
312-
return (
313-
['mongo-c-driver::mongo-c-driver']
314-
if self.options.with_mongodb
315-
else []
316-
)
317-
318-
def cyrussasl():
319-
return (
320-
['cyrus-sasl::cyrus-sasl']
321-
if self.options.with_mongodb or self.options.with_kafka
322-
else []
323-
)
324-
325-
def hiredis():
326-
return ['hiredis::hiredis'] if self.options.with_redis else []
327-
328-
def amqpcpp():
329-
return ['amqp-cpp::amqp-cpp'] if self.options.with_rabbitmq else []
330-
331-
def pugixml():
332-
return ['pugixml::pugixml'] if self.options.with_s3api else []
333-
334-
def clickhouse():
335-
return (
336-
['clickhouse-cpp::clickhouse-cpp']
337-
if self.options.with_clickhouse
338-
else []
339-
)
340-
341-
def librdkafka():
342-
return (
343-
['librdkafka::librdkafka'] if self.options.with_kafka else []
344-
)
345-
346-
userver_components = [
347-
{
348-
'target': 'core',
349-
'lib': 'core',
350-
'requires': (
351-
['universal']
352-
+ fmt()
353-
+ cctz()
354-
+ boost()
355-
+ concurrentqueue()
356-
+ yaml()
357-
+ iconv()
358-
+ libev()
359-
+ libnghttp2()
360-
+ curl()
361-
+ cryptopp()
362-
+ jemalloc()
363-
+ ares()
364-
+ rapidjson()
365-
+ zlib()
366-
),
367-
},
368-
]
369-
userver_components.extend([
370-
{
371-
'target': 'universal',
372-
'lib': 'universal',
373-
'requires': (
374-
fmt()
375-
+ cctz()
376-
+ boost()
377-
+ concurrentqueue()
378-
+ yaml()
379-
+ cryptopp()
380-
+ jemalloc()
381-
+ openssl()
382-
+ zstd()
383-
),
384-
},
385-
])
386-
387-
if self.options.with_grpc:
388-
userver_components.extend([
389-
{
390-
'target': 'grpc',
391-
'lib': 'grpc',
392-
'requires': (['core'] + abseil() + grpc() + protobuf()),
393-
},
394-
{
395-
'target': 'grpc-handlers',
396-
'lib': 'grpc-handlers',
397-
'requires': ['core'] + grpc(),
398-
},
399-
{
400-
'target': 'grpc-handlers-proto',
401-
'lib': 'grpc-handlers-proto',
402-
'requires': ['core'] + grpc(),
403-
},
404-
{
405-
'target': 'api-common-protos',
406-
'lib': 'api-common-protos',
407-
'requires': ['grpc'],
408-
},
409-
])
410-
if self.options.with_utest:
411-
userver_components.extend([
412-
{
413-
'target': 'utest',
414-
'lib': 'utest',
415-
'requires': ['core'] + gtest(),
416-
},
417-
{
418-
'target': 'ubench',
419-
'lib': 'ubench',
420-
'requires': ['core'] + benchmark(),
421-
},
422-
])
423-
if self.options.with_postgresql:
424-
userver_components.extend([
425-
{
426-
'target': 'postgresql',
427-
'lib': 'postgresql',
428-
'requires': ['core'] + postgresql(),
429-
},
430-
])
431-
if self.options.with_mongodb:
432-
userver_components.extend([
433-
{
434-
'target': 'mongo',
435-
'lib': 'mongo',
436-
'requires': ['core'] + mongo() + cyrussasl(),
437-
},
438-
])
439-
if self.options.with_redis:
440-
userver_components.extend([
441-
{
442-
'target': 'redis',
443-
'lib': 'redis',
444-
'requires': ['core'] + hiredis(),
445-
},
446-
])
447-
if self.options.with_rabbitmq:
448-
userver_components.extend([
449-
{
450-
'target': 'rabbitmq',
451-
'lib': 'rabbitmq',
452-
'requires': ['core'] + amqpcpp(),
453-
},
454-
])
455-
if self.options.with_clickhouse:
456-
userver_components.extend([
457-
{
458-
'target': 'clickhouse',
459-
'lib': 'clickhouse',
460-
'requires': ['core'] + abseil() + clickhouse(),
461-
},
462-
])
463-
if self.options.with_kafka:
464-
userver_components.extend([
465-
{
466-
'target': 'kafka',
467-
'lib': 'kafka',
468-
'requires': (
469-
['core']
470-
+ cyrussasl()
471-
+ curl()
472-
+ zlib()
473-
+ openssl()
474-
+ librdkafka()
475-
),
476-
},
477-
])
478-
479-
if self.options.with_otlp:
480-
userver_components.extend([
481-
{'target': 'otlp', 'lib': 'otlp', 'requires': ['core']},
482-
])
483-
484-
if self.options.with_easy:
485-
userver_components.extend([
486-
{
487-
'target': 'easy',
488-
'lib': 'easy',
489-
'requires': ['core', 'postgresql'],
490-
},
491-
])
492-
493-
if self.options.with_s3api:
494-
userver_components.extend([
495-
{
496-
'target': 's3api',
497-
'lib': 's3api',
498-
'requires': ['core'] + pugixml(),
499-
},
500-
])
501-
502-
if self.options.with_grpc_reflection:
503-
userver_components.extend([
504-
{
505-
'target': 'grpc-reflection',
506-
'lib': 'grpc-reflection',
507-
'requires': ['grpc'],
508-
},
509-
])
510-
return userver_components
511-
512241
def package_info(self):
513-
debug = 'd' if self.settings.build_type == 'Debug' else ''
514-
515-
def get_lib_name(module):
516-
return f'userver-{module}{debug}'
517-
518-
def add_components(components):
519-
for component in components:
520-
conan_component = component['target']
521-
cmake_target = component['target']
522-
cmake_component = component['lib']
523-
lib_name = get_lib_name(component['lib'])
524-
requires = component['requires']
525-
# TODO: we should also define COMPONENTS names of each target
526-
# for find_package() but not possible yet in CMakeDeps
527-
# see https://github.com/conan-io/conan/issues/10258
528-
self.cpp_info.components[conan_component].set_property(
529-
'cmake_target_name', 'userver::' + cmake_target,
530-
)
531-
if cmake_component == 'grpc':
532-
self.cpp_info.components[conan_component].libs.append(
533-
get_lib_name('grpc-internal'),
534-
)
535-
self.cpp_info.components[conan_component].libs.append(
536-
get_lib_name('grpc-proto'),
537-
)
538-
self.cpp_info.components[conan_component].libs.append(
539-
get_lib_name('api-common-protos'),
540-
)
541-
else:
542-
self.cpp_info.components[conan_component].libs = [lib_name]
543-
if cmake_component == 'otlp':
544-
self.cpp_info.components[conan_component].libs.append(
545-
get_lib_name('otlp-proto'),
546-
)
547-
if cmake_component == 'universal':
548-
self.cpp_info.components[
549-
cmake_component
550-
].includedirs.append(
551-
os.path.join('include', 'userver', 'third_party'),
552-
)
553-
554-
self.cpp_info.components[conan_component].requires = requires
555-
556-
self.cpp_info.components['universal'].defines.append(
557-
f'USERVER_NAMESPACE={self.options.namespace}',
558-
)
559-
self.cpp_info.components['universal'].defines.append(
560-
f'USERVER_NAMESPACE_BEGIN={self.options.namespace_begin}',
561-
)
562-
self.cpp_info.components['universal'].defines.append(
563-
f'USERVER_NAMESPACE_END={self.options.namespace_end}',
564-
)
565-
566-
self.cpp_info.set_property('cmake_file_name', 'userver')
567-
568-
add_components(self._userver_components)
569-
570-
def _cmake_path_to(name):
571-
return os.path.join(
572-
self.package_folder, 'lib', 'cmake', 'userver', name,
573-
)
574-
575-
with open(
576-
_cmake_path_to('UserverSetupPathsInConan.cmake'), 'w',
577-
) as cmake_file:
578-
cmake_file.write(
579-
'set(USERVER_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR}")\n',
580-
)
581-
cmake_file.write(
582-
'set_property(GLOBAL PROPERTY userver_cmake_dir "${USERVER_CMAKE_DIR}")\n',
583-
)
584-
cmake_file.write('set(USERVER_CONAN TRUE)\n')
585-
cmake_file.write(
586-
'set(USERVER_GRPC_SCRIPTS_PATH "${USERVER_CMAKE_DIR}/grpc")\n',
587-
)
588-
cmake_file.write(
589-
'set(USERVER_TESTSUITE_DIR "${USERVER_CMAKE_DIR}/testsuite")\n',
590-
)
591-
592-
with open(_cmake_path_to('CallSetupEnv.cmake'), 'w') as cmake_file:
593-
cmake_file.write('userver_setup_environment()\n')
594-
595-
build_modules = [
596-
_cmake_path_to('UserverSetupPathsInConan.cmake'),
597-
_cmake_path_to('UserverSetupEnvironment.cmake'),
598-
_cmake_path_to('CallSetupEnv.cmake'),
599-
_cmake_path_to('UserverVenv.cmake'),
600-
_cmake_path_to('UserverTestsuite.cmake'),
601-
]
602-
if self.options.with_utest:
603-
build_modules.append(_cmake_path_to('AddGoogleTests.cmake'))
604-
605-
if self.options.with_grpc:
606-
build_modules.append(_cmake_path_to('SetupProtobuf.cmake'))
607-
build_modules.append(_cmake_path_to('UserverGrpcTargets.cmake'))
608-
609-
self.cpp_info.set_property('cmake_build_modules', build_modules)
242+
# https://docs.conan.io/2/examples/tools/cmake/cmake_toolchain/use_package_config_cmake.html
243+
self.cpp_info.set_property('cmake_find_mode', 'none')
244+
self.cpp_info.builddirs.append(os.path.join('lib', 'cmake', 'userver'))

0 commit comments

Comments
 (0)