Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: static link hipo4 #74

Merged
merged 18 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defaults:
shell: bash

env:
hipo_version: 4.0.1
hipo_version: f40da676bbd1745398e9fdf233ff213ff98798f1
num_events: 10

jobs:
Expand Down
7 changes: 3 additions & 4 deletions examples/build_with_cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ if(NOT "${CMAKE_CXX_STANDARD}")
endif()

# find dependencies
# - iguana doesn't create a `iguanaConfig.cmake` file, but it does create a pkg-config `.pc` file;
# using `PkgConfig`, the iguana target will be imported as `PkgConfig::iguana`
find_package(hipo4 REQUIRED)
# - using `PkgConfig` module imports pkg-config dependencies as targets prefixed with `PkgConfig::`
find_package(PkgConfig REQUIRED)
pkg_check_modules(hipo4 REQUIRED IMPORTED_TARGET hipo4)
pkg_check_modules(iguana REQUIRED IMPORTED_TARGET iguana)

# set the rpath to use the link path
Expand All @@ -27,5 +26,5 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(EXAMPLE_BIN iguana-example-00-basic)
add_executable(${EXAMPLE_BIN})
target_sources(${EXAMPLE_BIN} PRIVATE ${EXAMPLE_BIN}.cc)
target_link_libraries(${EXAMPLE_BIN} PUBLIC PkgConfig::iguana hipo4)
target_link_libraries(${EXAMPLE_BIN} PUBLIC PkgConfig::iguana PkgConfig::hipo4)
install(TARGETS ${EXAMPLE_BIN})
15 changes: 3 additions & 12 deletions examples/build_with_meson/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,16 @@ project(

# find dependencies
# - it's good practice to specifiy minimum version requirements; here we just assume that `iguana` already did this
hipo_dep = dependency('hipo4')
hipo_dep = dependency('hipo4', static: true) # use static link, for performance
iguana_dep = dependency('iguana')

# set rpath
# - this is so that the executable knows where the dependency libraries are
# - alternatively, set $LD_LIBRARY_PATH before running your executables ($DYLD_LIBRARY_PATH on macOS)
# - not needed for libraries which are static-linked
bin_rpaths = [
hipo_dep.get_variable(pkgconfig: 'libdir'),
iguana_dep.get_variable(pkgconfig: 'libdir')
]
if host_machine.system() != 'darwin'
# FIXME(darwin): not sure how to set multiple rpaths on darwin executables, aside
# from running `install_name_tool -add_rpath` post-installation; luckily,
# darwin-built examples only need `hipo_dep` libraries in the rpath and they
# don't need the `iguana` library path explictly included in the rpath, so
# this `if` block just keeps `bin_rpaths` to only one element. If we need
# more rpath elements someday, either we need to use `install_name_tool` or,
# preferably, resolution of https://github.com/mesonbuild/meson/issues/5760
bin_rpaths += iguana_dep.get_variable(pkgconfig: 'libdir')
endif

# build and install the executable
example_bin = 'iguana-example-00-basic'
Expand Down
17 changes: 7 additions & 10 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ yamlcpp_dep = dependency(
)
hipo_dep = dependency(
'hipo4',
static: true,
method: 'pkg-config',
version: '>=4.0.1',
)
Expand Down Expand Up @@ -67,17 +68,13 @@ project_pkg_vars = [
]

# executables' rpath
project_exe_rpath = [
hipo_dep.get_variable(pkgconfig: 'libdir'),
]
project_exe_rpath = []
if host_machine.system() != 'darwin'
# FIXME(darwin): not sure how to set multiple rpaths on darwin executables, aside
# from running `install_name_tool -add_rpath` post-installation; luckily,
# darwin-built examples only need `hipo_dep` libraries in the rpath and they
# don't need the `iguana` library path explictly included in the rpath, so
# this `if` block just keeps `project_exe_rpath` to only one element. If we need
# more rpath elements someday, either we need to use `install_name_tool` or,
# preferably, resolution of https://github.com/mesonbuild/meson/issues/5760
# FIXME(darwin): not sure how to set multiple rpaths on darwin executables,
# aside from running `install_name_tool -add_rpath` post-installation;
# luckily, darwin-built executables don't need the `iguana` library path
# explictly included in the rpath, so this `if` block just keeps
# `project_exe_rpath` minimal. See https://github.com/mesonbuild/meson/issues/5760
project_exe_rpath += '$ORIGIN' / '..' / get_option('libdir')
endif

Expand Down