Skip to content

Instantly share code, notes, and snippets.

@rcnagireddy
Forked from HE-Wenjian/meson.build
Created May 31, 2020 18:58
Show Gist options
  • Save rcnagireddy/4e298a8c370484809e49a94293dbb949 to your computer and use it in GitHub Desktop.
Save rcnagireddy/4e298a8c370484809e49a94293dbb949 to your computer and use it in GitHub Desktop.
meson dependency searching with Conan
#############################################
# -----------
# Import from conan only.
# -----------
conan_pkgs= {
'fmt':'fmt/5.3.0@', # <- Must contain @, otherwise Conan will think it is a path
# ... the dependency list goes on
}
# Adding new dependencies to this dict is error-free, but if you
# change an existing entry, e.g. the pakage version, you probably need
# `meson configure --clearcache` to let new setting takes effect.
deps=[]
conan = find_program('conan', required: true)
foreach pkg_name, conan_ref : conan_pkgs
module_path = meson.current_build_dir() / 'conan-cmake' / pkg_name
conan_buildtype=get_option('debug') ? 'Debug' : 'Release'
run_command(conan,'install',conan_ref, '-if',module_path,
'-g','cmake_find_package', '-s:b','build_type='+conan_buildtype, check: true)
deps += dependency(pkg_name,
method: 'cmake', cmake_module_path: module_path)
endforeach
executable('exe_need_deps', ['main.cpp'],
dependencies: deps
)
########################################
# -----------
# Search system then Conan
# -----------
search_sys_then_conan = {
'fmt' : {'conan_ref':'fmt/5.3.0@','kwargs':{'version':['>=5','<6']}},
'dyad' : {'conan_ref':'dyad/0.2.1@bincrafters/stable'},
# 'zlib' : {}, # <- only search in system
# ... the dependency list goes on
# NOTE: conan_ref must contain '@'
}
deps = []
conan = find_program('conan', required: false)
foreach pkg_name, config : search_sys_then_conan
pkg = dependency(pkg_name, kwargs: config.get('kwargs',{}),
required: not config.has_key('conan_ref'))
if not pkg.found() and config.has_key('conan_ref')
assert(conan.found(),'Trying to find dependency from Conan, but Conan is not installed.')
module_path = meson.current_build_dir() / 'conan-cmake' / pkg_name
conan_buildtype=get_option('debug') ? 'Debug' : 'Release'
run_command(conan,'install',config['conan_ref'], '-if',module_path,
'-g','cmake_find_package', '-s:b','build_type='+conan_buildtype, check: true)
pkg = dependency(pkg_name, kwargs: config.get('kwargs',{}),
method: 'cmake', cmake_module_path : module_path)
endif
deps += pkg
endforeach
########################################
# -----------
# Search system then subproject wrap or Conan, with more configurability
# -----------
search_sys_then_wrap_or_conan = {
# 'libA' : {'kwargs':{'version':['2.1.0']}, #<- Only search system.
# 'libB' : {'wrap':['libB','libB_dep']}, #<- Only search system and subprojects wrap
'dyad' : {'conan_ref':'dyad/0.2.1@bincrafters/stable'}, #<- Only search system and conan
'fmt' : {'conan_ref':'fmt/5.3.0@', # <- Must contain @, otherwise Conan thinks it is a path
'kwargs':{'version':['>=5','<6']}},
# ... the dependency list goes on
}
deps = []
conan = find_program('conan', required: false)
foreach pkg_name, config : search_sys_then_wrap_or_conan
pkg = dependency(pkg_name, fallback : config.get('wrap',['_','_']),
required: not config.has_key('conan_ref'), kwargs: config.get('kwargs',{}))
if not pkg.found() and config.has_key('conan_ref')
assert(conan.found(),'Trying to find dependency from Conan, but Conan is not installed.')
module_path = meson.current_build_dir() / 'conan-cmake' / pkg_name
conan_buildtype = get_option('debug') ? 'Debug' : 'Release'
run_command(conan, 'install',config['conan_ref'], '-if',module_path,
'-g','cmake_find_package', '-s:b','build_type='+conan_buildtype, check: true)
deps += dependency(pkg_name, kwargs: config.get('kwargs',{}),
method: 'cmake', cmake_module_path : module_path)
endif
deps += pkg
endforeach
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment