debug/AssertFatal.cpp Not Included in yogacore Build with file(GLOB), Causes Linker Error When Building Yoga 3.2.1 as Shared Library (yoga/CMakeLists.txt Fix) #1806
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
Summary
When building the
yogacore
library with the defaultCMakeLists.txt
in theyoga/
directory, thedebug/AssertFatal.cpp
file (which definesfacebook::yoga::fatalWithMessage
) is not included in the source list when usingfile(GLOB ...)
. This doesn’t affect the static build (libyogacore.a
) in my current test suite, but it causes a linker error (undefined reference to facebook::yoga::fatalWithMessage
) when building as a shared library (libyogacore.so
).Steps to Reproduce
yoga/CMakeLists.txt
to support shared libraries:yogatests
build:Expected Behavior
yogacore
library (static or shared) should include all necessary source files, includingdebug/AssertFatal.cpp
, so thatfatalWithMessage
is defined and the build completes successfully.Actual Behavior
file(GLOB SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/**/*.cpp)
does not includedebug/AssertFatal.cpp
.fatalWithMessage
isn’t called), but shared builds fail with anundefined reference
error because the symbol is referenced inStyleTest.cpp
(viaStyle.h
).Root Cause
file(GLOB ...)
pattern inyoga/CMakeLists.txt
fails to recurse into thedebug/
subdirectory, omittingdebug/AssertFatal.cpp
. This is unexpected since/**/*.cpp
should include subdirectories, but it doesn’t work as intended in my environment (CMake 3.26, Fedora).My Fix
I modified
yoga/CMakeLists.txt
to usefile(GLOB_RECURSE ...)
instead:This correctly includes
debug/AssertFatal.cpp
, and both static and shared builds succeed:Suggested Action
yoga/CMakeLists.txt
to usefile(GLOB_RECURSE ...)
or explicitly includedebug/AssertFatal.cpp
to ensure all necessary sources are built intoyogacore
.debug/AssertFatal.cpp
is intentionally excluded and how users should handle shared library builds.Environment
Additional Notes
fatalWithMessage
in my test suite. If tests or consumers call it (e.g., viaStyle.h
), the static build could fail too.CMakeLists.txt
: