Skip to content

build: collapse duplicated SHARED/STATIC add_library branches into VIZ_LIBRARY_TYPE - #147

Closed
chiliec wants to merge 1 commit into
masterfrom
chore/collapse-shared-static-cmake
Closed

build: collapse duplicated SHARED/STATIC add_library branches into VIZ_LIBRARY_TYPE#147
chiliec wants to merge 1 commit into
masterfrom
chore/collapse-shared-static-cmake

Conversation

@chiliec

@chiliec chiliec commented Aug 10, 2026

Copy link
Copy Markdown
Member

Addresses the BUILD_SHARED_LIBRARIES duplication (F035 in the tech-debt audit). No source code touched.

Problem

Every library and plugin CMakeLists.txt carried its full source + header list twice — once under add_library(<name> SHARED ...) and once under add_library(<name> STATIC ...), wrapped in if(BUILD_SHARED_LIBRARIES)/else()/endif(). 26 files, ~identical lists duplicated per file. Every source added to a library had to be added in two places, which is a standing drift hazard.

Why collapse rather than drop the option

The option is still live: build-mac.sh defaults SHARED_LIBS=ON, so macOS local dev builds actually exercise the SHARED path. Dropping shared support would break that. So this keeps the option and removes only the duplication.

Change

  • Add a single VIZ_LIBRARY_TYPE variable at root scope: SHARED when BUILD_SHARED_LIBRARIES is ON, STATIC otherwise.
  • Replace each dual-branch block with one add_library(<name> ${VIZ_LIBRARY_TYPE} ...).
  • Net −220 lines across 27 files.

Drift fix (bonus)

The duplication had already drifted in libraries/chain/CMakeLists.txt: the SHARED branch listed invite_evaluator.cpp twice and was missing include/graphene/chain/invite_objects.hpp, while the STATIC branch was correct. Collapsing onto the STATIC list fixes both — shared builds of the chain lib were previously missing a header from the target's file list.

Verification

  • Set-equivalence: for all 26 targets, the collapsed source/header set is byte-set-identical to the original STATIC branch. Since the default build, all Docker images, and CI all use -DBUILD_SHARED_LIBRARIES=FALSE, static-build behavior is provably unchanged.
  • Real cmake configure: built a minimal reproduction covering both the explicit-source pattern (chain/time) and the ${CURRENT_TARGET_SOURCES} plugin pattern. BUILD_SHARED_LIBRARIES=OFFSTATIC_LIBRARY targets; =ONSHARED_LIBRARY targets — matching the previous if/else semantics. graphene::<name> ALIAS targets still resolve.

(Full end-to-end compile not run in my environment — no Boost dev libs / submodules available — but the transformation is a mechanical branch-collapse with configure-level validation and set-level equivalence to the shipping static path.)

…Z_LIBRARY_TYPE

Every library and plugin CMakeLists carried the full source + header list twice:
once under add_library(<name> SHARED ...) and once under add_library(<name>
STATIC ...), inside an if(BUILD_SHARED_LIBRARIES)/else()/endif(). 26 files, with
the source list duplicated in each — a standing drift hazard.

Introduce a single VIZ_LIBRARY_TYPE variable at root scope (SHARED when
BUILD_SHARED_LIBRARIES is ON, STATIC otherwise) and replace each dual-branch
block with one add_library(<name> ${VIZ_LIBRARY_TYPE} ...). Net -220 lines.

The duplication had already drifted in libraries/chain: the SHARED branch listed
invite_evaluator.cpp twice and was missing include/graphene/chain/invite_objects.hpp,
while the STATIC branch was correct. Collapsing onto the STATIC list fixes both.

Verification:
- For all 26 targets the collapsed source/header set is byte-set-identical to the
  original STATIC branch (which is what the default build, Docker images, and CI
  all use via -DBUILD_SHARED_LIBRARIES=FALSE), so static-build behavior is
  unchanged.
- Configured a minimal reproduction with real cmake covering both the
  explicit-source pattern (chain/time) and the ${CURRENT_TARGET_SOURCES} plugin
  pattern: BUILD_SHARED_LIBRARIES=OFF yields STATIC_LIBRARY targets, ON yields
  SHARED_LIBRARY targets, matching the previous if/else semantics. graphene::
  ALIAS targets still resolve.

No source code touched; BUILD_SHARED_LIBRARIES option and its default (FALSE) are
unchanged. build-mac.sh (which defaults SHARED_LIBS=ON) keeps a working shared
path — now with the chain drift fixed.
On1x added a commit that referenced this pull request Aug 11, 2026
…RY_TYPE

# Conflicts:
#	libraries/chain/CMakeLists.txt
@On1x

On1x commented Aug 11, 2026

Copy link
Copy Markdown
Member

Folded into the pm branch (PR #124). Resolved a conflict in libraries/chain/CMakeLists.txt by keeping the VIZ_LIBRARY_TYPE collapse from this PR while preserving pm's full source list (the PM sources — pm/lmsr_q96, parimutuel, leverage, pm_evaluator — stay in the build). Full CI build on pm is green. Closing since it now lives in pm. Thanks!

@On1x On1x closed this Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants