Visibility issue with static libs on macOS
When building Wt with
-DSHARED_LIBS=OFF on macOS, it outputs linking warnings like:
ld: warning: direct access in function 'Wt::Chart::WAxis::getValue(std::__1::any const&) const' from file 'src/libwt.a(WAxis.C.o)' to global weak symbol 'std::__1::__any_imp::__unique_typeinfo<Wt::WDateTime>::__id' from file 'test/CMakeFiles/test.wt.dir/chart/WChartTest.C.o' means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings.
This is because we build all of our libraries with
SET_PROPERTY(TARGET wt PROPERTY C_VISIBILITY_PRESET hidden) SET_PROPERTY(TARGET wt PROPERTY CXX_VISIBILITY_PRESET hidden) SET_PROPERTY(TARGET wt PROPERTY VISIBILITY_INLINES_HIDDEN YES)
Our tests are not built with the above properties. While this doesn't cause any issues on Windows or Linux, on macOS this property needs to match, otherwise, this may lead to issues.
For example, the following Sqlite3 tests are failing:
With errors like:
ASSERTION FAILURE: - file : DboTest.C - line : 1582 - message: critical check Wt::asString(model->headerData(0)) == "id" has failed
I propose we won't set these visibility properties when building on macOS. The user may set
-DCMAKE_C_VISIBILITY_PRESET=hidden -DCMAKE_CXX_VISIBILITY_PRESET=hidden -DCMAKE_VISIBILITY_INLINES_HIDDEN=YES if they want to. It is then up to the user to make sure they consistently use those properties.
Maybe the issue would also be resolved if we create prelinked static libraries on macOS: https://gitlab.kitware.com/cmake/cmake/-/issues/22177 (and then declare the visibility of our symbols the same way as we do for shared libraries). At the moment this is not supported by CMake, however.