cmake_minimum_required(VERSION 3.22.1)
project(ujnb_guard LANGUAGES CXX)
if(NOT DEFINED UJNB_EXPECTED_PACKAGE OR
   NOT UJNB_EXPECTED_PACKAGE MATCHES "^com\\.czenb\\.ujnb(\\.transfer[ab])?(\\.debug)?$")
    message(FATAL_ERROR "UJNB_EXPECTED_PACKAGE must be the application's configured package name")
endif()
add_library(ujnb_guard SHARED guard.cpp)
target_link_libraries(ujnb_guard PRIVATE dl)
# 构建时绑定唯一安装包名，运行时不接受其他测试变体或任意前缀。
target_compile_definitions(ujnb_guard PRIVATE UJNB_EXPECTED_PACKAGE="${UJNB_EXPECTED_PACKAGE}")
target_compile_features(ujnb_guard PRIVATE cxx_std_17)
target_compile_options(ujnb_guard PRIVATE -O2 -fvisibility=hidden -fvisibility-inlines-hidden
    -fstack-protector-strong -D_FORTIFY_SOURCE=2 -flto -Wall -Wextra -Werror)
target_link_options(ujnb_guard PRIVATE -flto -Wl,-z,relro,-z,now -Wl,--exclude-libs,ALL
    -Wl,-z,max-page-size=16384 -Wl,-z,common-page-size=16384)
