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

Size
8.5 KB
Lines
143
Language
cmake
SHA-256
1c336c6fcc09…
View on GitHub

Sign in with GitHub to download. Each download is recorded with your GitHub username.

1cmake_minimum_required(VERSION 3.20)
2project(CKey VERSION 0.1.0 LANGUAGES CXX)
3
4option(CKEY_BUILD_TESTS "Build CKey tests" ON)
5option(CKEY_BUILD_TELEMETRY "Build the optional telemetry module" ON)
6
7# The core is split into independent libraries (specification §2.1, §6, §9.2):
8# ckey_codec encode and decode codewords (RS, CRC, framing)
9# ckey_scan image localization and decoding; needs only ckey_codec
10# ckey_render geometry, SVG, raster, PNG, PDF, print; needs nothing else
11# ckey_certify optical certification through a modelled scan; needs scan + render
12# ckey_telemetry optional aggregate counters; nothing depends on it
13# A scan-only app links ckey_scan alone. ckey_core is codec, scan, render and certify. The
14# Xcode projects compile src/ckey.cpp, the amalgamation of the same parts.
15function(ckey_library name source)
16 add_library(${name} ${source})
17 target_compile_features(${name} PUBLIC cxx_std_20)
18 target_include_directories(${name} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
19 target_include_directories(${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
20 set_target_properties(${name} PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN YES POSITION_INDEPENDENT_CODE YES)
21 if(BUILD_SHARED_LIBS)
22 target_compile_definitions(${name} PRIVATE CKEY_SHARED CKEY_BUILDING)
23 endif()
24 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
25 # Each library compiles only the shared internals it calls.
26 target_compile_options(${name} PRIVATE -Wno-unused-function)
27 endif()
28endfunction()
29ckey_library(ckey_codec src/ckey_codec.cpp)
30ckey_library(ckey_scan src/ckey_scan.cpp)
31target_link_libraries(ckey_scan PUBLIC ckey_codec)
32ckey_library(ckey_render src/ckey_render.cpp)
33ckey_library(ckey_certify src/ckey_certify.cpp)
34target_link_libraries(ckey_certify PUBLIC ckey_scan ckey_render)
35add_library(ckey_core INTERFACE)
36target_link_libraries(ckey_core INTERFACE ckey_codec ckey_scan ckey_render ckey_certify)
37if(CKEY_BUILD_TELEMETRY)
38 find_package(Threads REQUIRED)
39 ckey_library(ckey_telemetry src/telemetry.cpp)
40 target_link_libraries(ckey_telemetry PRIVATE Threads::Threads)
41endif()
42add_executable(ckey-conformance tools/conformance/ckey_conformance.cpp)
43target_link_libraries(ckey-conformance PRIVATE ckey_core)
44# Optical benchmark harness (spec §5). -DCKEY_BENCH_ZXING=ON adds QR Code and
45# Data Matrix through zxing-cpp for equal-area comparison.
46option(CKEY_BENCH_ZXING "Compare against QR/Data Matrix with zxing-cpp in ckey-bench" OFF)
47add_executable(ckey-bench tools/optical-benchmarks/ckey_bench.cpp)
48target_link_libraries(ckey-bench PRIVATE ckey_core)
49if(CKEY_BENCH_ZXING)
50 find_package(ZXing REQUIRED)
51 target_link_libraries(ckey-bench PRIVATE ZXing::ZXing)
52 target_compile_definitions(ckey-bench PRIVATE CKEY_BENCH_ZXING)
53endif()
54add_executable(ckey-gallery tools/gallery/ckey_gallery.cpp)
55target_link_libraries(ckey-gallery PRIVATE ckey_core)
56
57add_executable(ckey cli/main.cpp)
58target_link_libraries(ckey PRIVATE ckey_core)
59
60# ---- Install and CMake package (spec §7: C/C++ consumers use find_package(CKey)) ----
61include(GNUInstallDirs)
62include(CMakePackageConfigHelpers)
63file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/VERSION CKEY_VERSION_STRING LIMIT_COUNT 1)
64set(CKEY_INSTALL_TARGETS ckey_codec ckey_scan ckey_render ckey_certify ckey_core)
65if(CKEY_BUILD_TELEMETRY)
66 list(APPEND CKEY_INSTALL_TARGETS ckey_telemetry)
67endif()
68foreach(lib ${CKEY_INSTALL_TARGETS})
69 string(REPLACE "ckey_" "" short ${lib})
70 set_target_properties(${lib} PROPERTIES EXPORT_NAME ${short})
71endforeach()
72install(TARGETS ${CKEY_INSTALL_TARGETS} EXPORT CKeyTargets
73 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
74 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
75install(TARGETS ckey RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
76install(DIRECTORY include/ckey DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
77install(EXPORT CKeyTargets NAMESPACE CKey:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CKey)
78configure_package_config_file(cmake/CKeyConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/CKeyConfig.cmake
79 INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CKey)
80write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/CKeyConfigVersion.cmake VERSION ${PROJECT_VERSION} COMPATIBILITY SameMinorVersion)
81install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CKeyConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/CKeyConfigVersion.cmake
82 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CKey)
83if(CKEY_BUILD_TESTS)
84 enable_testing()
85 add_executable(ckey_tests tests/core_tests.cpp)
86 target_link_libraries(ckey_tests PRIVATE ckey_core)
87 add_test(NAME ckey_core_tests COMMAND ckey_tests)
88 add_executable(ckey_image_tests tests/image_decode_tests.cpp)
89 # Scan-only: proves a reader needs neither the renderer nor telemetry.
90 target_link_libraries(ckey_image_tests PRIVATE ckey_scan)
91 target_compile_definitions(ckey_image_tests PRIVATE CKEY_TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
92 add_test(NAME ckey_optical_image_decode COMMAND ckey_image_tests)
93 add_executable(ckey_roundtrip_tests tests/roundtrip_tests.cpp)
94 target_link_libraries(ckey_roundtrip_tests PRIVATE ckey_core)
95 add_test(NAME ckey_render_decode_roundtrip COMMAND ckey_roundtrip_tests)
96 add_executable(ckey_reader_pipeline_tests tests/reader_pipeline_tests.cpp)
97 target_link_libraries(ckey_reader_pipeline_tests PRIVATE ckey_core)
98 add_test(NAME ckey_simulated_reader COMMAND ckey_reader_pipeline_tests)
99 add_executable(ckey_render_tests tests/render_tests.cpp)
100 target_link_libraries(ckey_render_tests PRIVATE ckey_core)
101 add_test(NAME ckey_native_render COMMAND ckey_render_tests)
102 add_executable(ckey_interchange_tests tests/interchange_tests.cpp)
103 target_link_libraries(ckey_interchange_tests PRIVATE ckey_codec ckey_render)
104 add_test(NAME ckey_interchange COMMAND ckey_interchange_tests)
105 add_test(NAME ckey_conformance_vectors COMMAND ckey-conformance --check ${CMAKE_CURRENT_SOURCE_DIR}/tests/vectors/conformance-v1.json)
106 add_executable(ckey_safe_actions_tests tests/safe_actions_tests.cpp)
107 target_link_libraries(ckey_safe_actions_tests PRIVATE ckey_codec)
108 add_test(NAME ckey_safe_actions COMMAND ckey_safe_actions_tests ${CMAKE_CURRENT_SOURCE_DIR}/tests/vectors/safe-actions-v1.json)
109 add_executable(ckey_certify_tests tests/certify_tests.cpp)
110 target_link_libraries(ckey_certify_tests PRIVATE ckey_certify)
111 add_test(NAME ckey_style_certification COMMAND ckey_certify_tests)
112 if(CKEY_BUILD_TELEMETRY)
113 add_executable(ckey_telemetry_tests tests/telemetry_tests.cpp)
114 target_link_libraries(ckey_telemetry_tests PRIVATE ckey_telemetry Threads::Threads)
115 add_test(NAME ckey_telemetry COMMAND ckey_telemetry_tests)
116 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
117 target_compile_options(ckey_telemetry_tests PRIVATE -Wall -Wextra)
118 endif()
119 endif()
120 # White-box: Profile 0 layout invariants, capacities, ECC, and every version's image round trip.
121 add_executable(ckey_scalable_tests tests/scalable_tests.cpp)
122 target_include_directories(ckey_scalable_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
123 target_compile_features(ckey_scalable_tests PRIVATE cxx_std_20)
124 add_test(NAME ckey_scalable_profile0 COMMAND ckey_scalable_tests)
125 # White-box: compiles the core translation unit directly to inspect layout.
126 add_executable(ckey_layout_tests tests/layout_tests.cpp)
127 target_include_directories(ckey_layout_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
128 target_compile_features(ckey_layout_tests PRIVATE cxx_std_20)
129 add_test(NAME ckey_dense_layout COMMAND ckey_layout_tests)
130 foreach(test_target ckey_interchange_tests ckey_certify_tests ckey_render_tests ckey_tests ckey_image_tests ckey_roundtrip_tests ckey_layout_tests ckey_reader_pipeline_tests ckey_scalable_tests)
131 target_include_directories(${test_target} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
132 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
133 target_compile_options(${test_target} PRIVATE -Wall -Wextra)
134 endif()
135 endforeach()
136 find_package(Python3 COMPONENTS Interpreter QUIET)
137 if(Python3_Interpreter_FOUND)
138 add_test(NAME ckey_independent_rs_vector COMMAND ${Python3_EXECUTABLE} tools/rs_reference.py)
139 set_tests_properties(ckey_independent_rs_vector PROPERTIES WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
140 add_test(NAME ckey_version_consistency COMMAND ${Python3_EXECUTABLE} tools/check_version.py)
141 set_tests_properties(ckey_version_consistency PROPERTIES WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
142 endif()
143endif()