Select CMake Components
Combine multiple Sharp Runtime targets and inspect dependency closure.
Scenario
An application needs JSON and non-cryptographic hashing. Request exactly those direct surfaces:
set(SHARP_RUNTIME_COMPONENTS
Text.Json
IO.Hashing
)
set(SHARP_RUNTIME_BUILD_TESTS OFF CACHE BOOL "" FORCE)
add_subdirectory(sharp-runtime)
target_link_libraries(app PRIVATE
SharpRuntime::Text.Json
SharpRuntime::IO.Hashing
)
Understand the closure
Text.Json enables Core.Base, Buffers and Text publicly plus Collections.Core privately. IO.Hashing enables Core.Base and IO; IO in turn brings Uri publicly and TimeZone privately. The application does not repeat any of those transitive targets.
Test one component
cmake -S sharp-runtime -B build-json-tests \
+ -DSHARP_RUNTIME_COMPONENTS=Text.Json \
+ -DSHARP_RUNTIME_BUILD_TESTS=ON
cmake --build build-json-tests --target SharpRuntimeTests --parallel 2
sharp-runtime/scripts/run_component_tests.sh build-json-tests
Common mistakes
- Setting the component list after
add_subdirectory - Linking
SHARP_RUNTIMEin a selective build—the legacy target only exists with All - Listing private/transitive dependencies in consumer CMake
- Assuming that a component’s test dependencies become production dependencies