Viewing is open to everyone. Downloading and starring need a GitHub sign-in.
Sign in with GitHub
CMakeLists.txt
v0.1.0-build.85
Latest
Commit ede38f5
Sign in with GitHub to download. Each download is recorded with your GitHub username.
| 1 | # Native library for the CKey .NET SDK: one shared library named `ckey` |
| 2 | # (ckeynative.dll / libckeynative.so / libckeynative.dylib) built from the repository's core |
| 3 | # sources (codec, scan, render, certify, telemetry). The NuGet package ships it as runtimes/<rid>/native/ assets. |
| 4 | # |
| 5 | # cmake -S sdk/dotnet/native -B build-dotnet -DCMAKE_BUILD_TYPE=Release -DCKEY_DOTNET_RID=linux-x64 |
| 6 | # cmake --build build-dotnet --config Release |
| 7 | # |
| 8 | # With CKEY_DOTNET_RID set, the library is written to |
| 9 | # sdk/dotnet/artifacts/native/<rid>/, where CKey.csproj picks it up. |
| 10 | cmake_minimum_required(VERSION 3.20) |
| 11 | project(ckey_dotnet_native LANGUAGES C CXX) |
| 12 | |
| 13 | get_filename_component(CKEY_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../.." ABSOLUTE) |
| 14 | |
| 15 | option(CKEY_DOTNET_TELEMETRY "Include the optional telemetry module (src/telemetry.cpp)" ON) |
| 16 | option(CKEY_DOTNET_LAYOUT_PROBE "Build the struct layout probe (tools/layout_probe.c)" ON) |
| 17 | set(CKEY_DOTNET_RID "" CACHE STRING "NuGet runtime identifier (win-x64, linux-x64, osx-arm64, osx-x64); selects the output folder") |
| 18 | |
| 19 | set(CKEY_DOTNET_SOURCES |
| 20 | ${CKEY_ROOT}/src/ckey_codec.cpp |
| 21 | ${CKEY_ROOT}/src/ckey_scan.cpp |
| 22 | ${CKEY_ROOT}/src/ckey_render.cpp) |
| 23 | # Optical certification (renders and decodes; needs scan + render). |
| 24 | if(EXISTS ${CKEY_ROOT}/src/ckey_certify.cpp) |
| 25 | list(APPEND CKEY_DOTNET_SOURCES ${CKEY_ROOT}/src/ckey_certify.cpp) |
| 26 | endif() |
| 27 | if(CKEY_DOTNET_TELEMETRY) |
| 28 | list(APPEND CKEY_DOTNET_SOURCES ${CKEY_ROOT}/src/telemetry.cpp) |
| 29 | endif() |
| 30 | |
| 31 | add_library(ckey SHARED ${CKEY_DOTNET_SOURCES}) |
| 32 | target_compile_features(ckey PRIVATE cxx_std_20) |
| 33 | target_include_directories(ckey PRIVATE ${CKEY_ROOT}/include ${CKEY_ROOT}/src) |
| 34 | # CKEY_SHARED + CKEY_BUILDING: CKEY_API becomes __declspec(dllexport) on |
| 35 | # Windows and visibility("default") with GCC/Clang. Everything else is hidden. |
| 36 | target_compile_definitions(ckey PRIVATE CKEY_SHARED CKEY_BUILDING) |
| 37 | set_target_properties(ckey PROPERTIES |
| 38 | OUTPUT_NAME ckeynative |
| 39 | CXX_VISIBILITY_PRESET hidden |
| 40 | VISIBILITY_INLINES_HIDDEN YES |
| 41 | POSITION_INDEPENDENT_CODE YES) |
| 42 | if(WIN32) |
| 43 | # ckeynative.dll, also under MinGW (which would otherwise name it libckeynative.dll). |
| 44 | set_target_properties(ckey PROPERTIES PREFIX "") |
| 45 | endif() |
| 46 | if(MSVC) |
| 47 | # Static CRT: consumers need no Visual C++ redistributable. |
| 48 | set_target_properties(ckey PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") |
| 49 | target_compile_options(ckey PRIVATE /utf-8 /EHsc) |
| 50 | endif() |
| 51 | if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") |
| 52 | # Each core translation unit compiles shared internals it may not call. |
| 53 | target_compile_options(ckey PRIVATE -Wno-unused-function) |
| 54 | endif() |
| 55 | if(CMAKE_SYSTEM_NAME STREQUAL "Linux") |
| 56 | # Portable across distributions: no libstdc++/libgcc runtime dependency, |
| 57 | # and their symbols stay hidden; refuse unresolved symbols at link time. |
| 58 | target_link_options(ckey PRIVATE -static-libstdc++ -static-libgcc -Wl,--exclude-libs,ALL -Wl,--no-undefined) |
| 59 | # Export the C API and nothing else (see exports.map). |
| 60 | target_link_options(ckey PRIVATE "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports.map") |
| 61 | set_property(TARGET ckey APPEND PROPERTY LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/exports.map") |
| 62 | endif() |
| 63 | if(CKEY_DOTNET_TELEMETRY) |
| 64 | find_package(Threads REQUIRED) |
| 65 | target_link_libraries(ckey PRIVATE Threads::Threads) |
| 66 | endif() |
| 67 | |
| 68 | if(NOT CKEY_DOTNET_RID STREQUAL "") |
| 69 | set(CKEY_DOTNET_OUT "${CMAKE_CURRENT_SOURCE_DIR}/../artifacts/native/${CKEY_DOTNET_RID}") |
| 70 | # $<1:...> stops multi-config generators from appending a Release/ folder. |
| 71 | set_target_properties(ckey PROPERTIES |
| 72 | RUNTIME_OUTPUT_DIRECTORY "$<1:${CKEY_DOTNET_OUT}>" |
| 73 | LIBRARY_OUTPUT_DIRECTORY "$<1:${CKEY_DOTNET_OUT}>") |
| 74 | endif() |
| 75 | |
| 76 | if(CKEY_DOTNET_LAYOUT_PROBE) |
| 77 | # Prints sizeof/offsetof of every struct the C# interop declares; CI diffs |
| 78 | # it against tools/layout_expected.txt (64-bit ABIs). |
| 79 | add_executable(ckey_layout_probe tools/layout_probe.c) |
| 80 | target_include_directories(ckey_layout_probe PRIVATE ${CKEY_ROOT}/include) |
| 81 | set_target_properties(ckey_layout_probe PROPERTIES C_STANDARD 99 |
| 82 | RUNTIME_OUTPUT_DIRECTORY "$<1:${CMAKE_BINARY_DIR}>") |
| 83 | endif() |