Files
ANSCORE/core/ANSModelPackage/CMakeLists.txt
T
nghianguyenandClaude Opus 5 ea877a61bc fix(keys): decide at configure time whether this build has the key
Whether the model-package key is present was an __has_include test
inside the header, and that test leaves no dependency for the build
system. A key emitted after a build had already compiled the file would
not take effect until someone cleaned, and the resulting engine looks
exactly like one built without a key — which on a release machine means
shipping an engine that silently cannot open a package.

CMake now decides it and says which case it is, so emitting the key and
re-configuring is what installs it, visibly.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-13 05:56:58 +10:00

43 lines
1.8 KiB
CMake

# ANSModelPackage — reading an ANS model package (.ansmodel).
#
# Header-only apart from the vendored curves, and deliberately free of the
# heavy dependencies around it: no CUDA, no OpenCV, no LabVIEW. That is what
# lets it build — and be tested — on every platform, including the ones where
# the engine layer does not build at all.
add_library(ANSModelPackage STATIC
${CMAKE_SOURCE_DIR}/3rdparty/monocypher/monocypher.c
${CMAKE_SOURCE_DIR}/3rdparty/monocypher/monocypher-ed25519.c
)
target_include_directories(ANSModelPackage PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/3rdparty/monocypher
)
# nlohmann/json comes from vcpkg on Windows and the system elsewhere, the same
# way ANSFR already takes it.
if(WIN32)
target_include_directories(ANSModelPackage PUBLIC ${VCPKG_INCLUDE_DIR})
else()
find_path(ANSCORE_NLOHMANN_INCLUDE nlohmann/json.hpp
HINTS /opt/homebrew/include /usr/local/include /usr/include)
if(ANSCORE_NLOHMANN_INCLUDE)
target_include_directories(ANSModelPackage PUBLIC ${ANSCORE_NLOHMANN_INCLUDE})
else()
message(WARNING "nlohmann/json.hpp not found — ANSModelPackage will not build")
endif()
endif()
# The model-package key, decided at configure time: see ANSModelKeys.h for why
# this is not an __has_include test. PUBLIC so every engine that opens a
# package is compiled with the same answer.
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/ANSModelKeysGenerated.h")
target_compile_definitions(ANSModelPackage PUBLIC ANSCORE_HAVE_BUILTIN_MODEL_KEYS=1)
message(STATUS "ANSModelPackage: key present — packages can be opened")
else()
message(STATUS "ANSModelPackage: no key — packages cannot be opened "
"(run ansmodel-keys emit --product anscore, then re-run cmake)")
endif()
set_target_properties(ANSModelPackage PROPERTIES POSITION_INDEPENDENT_CODE ON)