#!/bin/sh
set -e

tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT

cat > "$tmpdir/CMakeLists.txt" <<'EOF'
cmake_minimum_required(VERSION 3.10)
project(smoke CXX)

find_package(libhandlegraph REQUIRED)

add_executable(smoke smoke.cpp)
target_link_libraries(smoke PRIVATE libhandlegraph::handlegraph_shared)
EOF

cat > "$tmpdir/smoke.cpp" <<'EOF'
#include <handlegraph/types.hpp>
#include <handlegraph/util.hpp>

int main() {
    handlegraph::net_handle_t handle;
    handlegraph::as_integer(handle) = 42;
    return (handle == handle && handlegraph::as_integer(handle) == 42) ? 0 : 1;
}
EOF

cmake "$tmpdir" -B "$tmpdir/build"
cmake --build "$tmpdir/build"
"$tmpdir/build/smoke"
ldd "$tmpdir/build/smoke" | grep -q 'libhandlegraph\.so'
