diff --git a/CMakeLists.txt b/CMakeLists.txt index f6818ae7..24095caa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,16 @@ project(libmoq ) # -- Build options -------------------------------------------------- -option(MOQ_BUILD_PACKAGE_EXPORTS "Generate and install the LibMoQ CMake package" ON) +# An embedding project owns its install and the export sets of the source +# dependencies it supplies, so the package defaults to OFF there. Derived here +# because PROJECT_IS_TOP_LEVEL needs CMake 3.21. +if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) + set(_MOQ_IS_TOP_LEVEL ON) +else() + set(_MOQ_IS_TOP_LEVEL OFF) +endif() +option(MOQ_BUILD_PACKAGE_EXPORTS "Generate and install the LibMoQ CMake package" + ${_MOQ_IS_TOP_LEVEL}) option(MOQ_BUILD_TESTS "Build test suite" ON) option(MOQ_BUILD_SIM "Build moq-sim" ${MOQ_BUILD_TESTS}) option(MOQ_BUILD_ADAPTER_PICOQUIC "Build picoquic adapter" OFF) diff --git a/README.md b/README.md index ef65d2a4..4f933459 100644 --- a/README.md +++ b/README.md @@ -210,10 +210,12 @@ facade the service still builds, but that transport returns ### CMake component imports -`MOQ_BUILD_PACKAGE_EXPORTS` defaults to ON. An embedding project may explicitly -set `-DMOQ_BUILD_PACKAGE_EXPORTS=OFF` to use source dependencies without native -exports. In-tree targets and ordinary artifact/header installation remain usable; -LibMoQ CMake package config/version/target modules are omitted. Existing pkg-config +`MOQ_BUILD_PACKAGE_EXPORTS` defaults to ON when LibMoQ is the top-level project +and to OFF when it is added as a subdirectory, so an embedding project can supply +source dependencies without native exports. An embedding project that wants the +package sets `-DMOQ_BUILD_PACKAGE_EXPORTS=ON`. In-tree targets and ordinary +artifact/header installation remain usable; LibMoQ CMake package +config/version/target modules are omitted. Existing pkg-config availability follows its existing dependency rules. With exports ON, injected source providers own their unique native exports and ordinary consumer setup. diff --git a/docs/cmake-component-exports.md b/docs/cmake-component-exports.md index 6455bf13..108019b7 100644 --- a/docs/cmake-component-exports.md +++ b/docs/cmake-component-exports.md @@ -8,9 +8,10 @@ export set; foreign dependencies stay in their provider's namespace and sets. `export(EXPORT ...)` and `install(EXPORT ...)`. It does not reconstruct imported artifact properties or library identity. CMake 3.20 remains the minimum version. -`MOQ_BUILD_PACKAGE_EXPORTS` is a BOOL option, **ON by default**, including when -LibMoQ is added as a subdirectory. Set it to OFF explicitly for an embedded -project that supplies source dependencies without package exports. OFF retains +`MOQ_BUILD_PACKAGE_EXPORTS` is a BOOL option, **ON by default** when LibMoQ is +the top-level project and OFF when it is added as a subdirectory, where the +embedding project owns the install and the exports of the source dependencies it +supplies. An embedding project that wants the package sets it to ON. OFF retains the actual in-tree targets, artifact/header installation and existing pkg-config rules. It generates or installs no LibMoQ CMake config/version/target modules and registers no private foreign build export. Reusing an ON build tree with OFF also diff --git a/tests/cmake/manual_component_exports/embedding/CMakeLists.txt b/tests/cmake/manual_component_exports/embedding/CMakeLists.txt index ed169117..a0ce5ecd 100644 --- a/tests/cmake/manual_component_exports/embedding/CMakeLists.txt +++ b/tests/cmake/manual_component_exports/embedding/CMakeLists.txt @@ -10,7 +10,8 @@ project(moq_package_embedding LANGUAGES C CXX) include(GNUInstallDirs) # A real source library owned by the embedding project. This is an export-graph # fixture, not a stand-in for a transport SDK or a backend runtime qualification. -option(MOQ_BUILD_PACKAGE_EXPORTS "Generate LibMoQ package exports" ON) +# MOQ_BUILD_PACKAGE_EXPORTS stays unset unless the driver passes it, so the +# LibMoQ subdirectory default is exercised too. option(FIXTURE_PROVIDER_EXPORTS "Register the fixture provider's own exports" ON) option(FIXTURE_SERVICE "Build the embedding service component" ON) add_library(fixture_provider_runtime runtime.c) diff --git a/tests/cmake/manual_component_exports/embedding/check.cmake b/tests/cmake/manual_component_exports/embedding/check.cmake index f3027daf..a0308b6c 100644 --- a/tests/cmake/manual_component_exports/embedding/check.cmake +++ b/tests/cmake/manual_component_exports/embedding/check.cmake @@ -105,6 +105,14 @@ command(packaging-off-again-build PASS "${CMAKE_COMMAND}" --build "${build}" --p embedding_run("${build}" embedding.cmake packaging-off-again) embedding_install("${build}" packaging-off-again OFF) +# Left unset, an embedded LibMoQ defaults to no package exports, so a parent +# with an unexported source provider still configures. +command(unexported-provider-default PASS "${CMAKE_COMMAND}" ${context} + -S "${fixture}/embedding" -B "${WORK}/unexported-provider-default" -G Ninja + -DCMAKE_BUILD_TYPE=Debug "-DMOQ_SOURCE=${MOQ_SOURCE}" "-DBUILD_SHARED_LIBS=${MOQ_SHARED}" + -DFIXTURE_PROVIDER_EXPORTS=OFF) +embedding_no_package("${WORK}/unexported-provider-default") + # The explicit ON contract must not silently hide an unexported source edge. command(unexported-provider "not in any export set" "${CMAKE_COMMAND}" ${context} -S "${fixture}/embedding" -B "${WORK}/unexported-provider" -G Ninja -DCMAKE_BUILD_TYPE=Debug diff --git a/tests/cmake/manual_component_exports/producer/CMakeLists.txt b/tests/cmake/manual_component_exports/producer/CMakeLists.txt index c123fbff..9c12fe28 100644 --- a/tests/cmake/manual_component_exports/producer/CMakeLists.txt +++ b/tests/cmake/manual_component_exports/producer/CMakeLists.txt @@ -42,6 +42,11 @@ if(MOQ_MODE STREQUAL "pico-wt") set(MOQ_BUILD_ADAPTER_PICO_WT ON CACHE BOOL "Real WT adapter" FORCE) set(MOQ_BUILD_PICO_WT_MANAGED ON CACHE BOOL "Real WT managed facade" FORCE) endif() +# These rows qualify the package, which an embedded LibMoQ leaves OFF by +# default; the embedding row passes its own choice through instead. +if(NOT MOQ_MODE STREQUAL "embedding") + set(MOQ_BUILD_PACKAGE_EXPORTS ON CACHE BOOL "Qualify native packages" FORCE) +endif() add_subdirectory("${MOQ_SOURCE}" libmoq) set(components "") set(targets moq::core moq::msf)