Blender Git Commit Log

Git Commits -> Revision 517870a

Revision 517870a by Sergey Sharybin (master)
January 23, 2020, 15:59 (GMT)
CMake: Refactor external dependencies handling

This is a more correct fix to the issue Brecht was fixing in D6600.

While the fix in that patch worked fine for linking it broke ASAN
runtime under some circumstances.
For example, `make full debug developer` would compile, but trying
to start blender will cause assert failure in ASAN (related on check
that ASAN is not running already).

Top-level idea: leave it to CMake to keep track of dependency graph.

The root of the issue comes to the fact that target like "blender" is
configured to use a lot of static libraries coming from Blender sources
and to use external static libraries. There is nothing which ensures
order between blender's and external libraries. Only order of blender
libraries is guaranteed.

It was possible that due to a cycle or other circumstances some of
blender libraries would have been passed to linker after libraries
it uses, causing linker errors.

For example, this order will likely fail:

libbf_blenfont.a libfreetype6.a libbf_blenfont.a

This change makes it so blender libraries are explicitly provided
their dependencies to an external libraries, which allows CMake to
ensure they are always linked against them.

General rule here: if bf_foo depends on an external library it is
to be provided to LIBS for bf_foo.
For example, if bf_blenkernel depends on opensubdiv then LIBS in
blenkernel's CMakeLists.txt is to include OPENSUBDIB_LIBRARIES.

The change is made based on searching for used include folders
such as OPENSUBDIV_INCLUDE_DIRS and adding corresponding libraries
to LIBS ion that CMakeLists.txt. Transitive dependencies are not
simplified by this approach, but I am not aware of any downside of
this: CMake should be smart enough to simplify them on its side.
And even if not, this shouldn't affect linking time.

Benefit of not relying on transitive dependencies is that build
system is more robust towards future changes. For example, if
bf_intern_opensubiv is no longer depends on OPENSUBDIV_LIBRARIES
and all such code is moved to bf_blenkernel this will not break
linking.

The not-so-trivial part is change to blender_add_lib (and its
version in Cycles). The complexity is caused by libraries being
provided as a single list argument which doesn't allow to use
different release and debug libraries on Windows. The idea is:

- Have every library prefixed as "optimized" or "debug" if
separation is needed (non-prefixed libraries will be considered
"generic").

- Loop through libraries passed to function and do simple parsing
which will look for "optimized" and "debug" words and specify
following library to corresponding category.

This isn't something particularly great. Alternative would be to
use target_link_libraries() directly, which sounds like more code
but which is more explicit and allows to have more flexibility
and control comparing to wrapper approach.

Tested the following configurations on Linux, macOS and Windows:

- make full debug developer
- make full release developer
- make lite debug developer
- make lite release developer

NOTE: Linux libraries needs to be compiled with D6641 applied,
otherwise, depending on configuration, it's possible to run into
duplicated zlib symbols error.

Differential Revision: https://developer.blender.org/D6642

Commit Details:

Full Hash: 517870a4a11f660c71d3901818fbb09798cb2d7d
Parent Commit: 544ee7a
Lines Changed: +437, -215

57 Modified Paths:

/build_files/cmake/macros.cmake (+57, -185) (Diff)
/build_files/cmake/platform/platform_apple.cmake (+3, -7) (Diff)
/build_files/cmake/platform/platform_unix.cmake (+5, -0) (Diff)
/build_files/cmake/platform/platform_win32.cmake (+23, -11) (Diff)
/CMakeLists.txt (+5, -3) (Diff)
/extern/ceres/bundle.sh (+2, -1) (Diff)
/extern/ceres/CMakeLists.txt (+2, -1) (Diff)
/extern/mantaflow/CMakeLists.txt (+17, -0) (Diff)
/extern/quadriflow/CMakeLists.txt (+1, -0) (Diff)
/intern/audaspace/CMakeLists.txt (+9, -0) (Diff)
/intern/cycles/blender/CMakeLists.txt (+5, -1) (Diff)
/intern/cycles/bvh/CMakeLists.txt (+7, -0) (Diff)
/intern/cycles/cmake/macros.cmake (+58, -2) (Diff)
/intern/cycles/device/CMakeLists.txt (+3, -1) (Diff)
/intern/cycles/graph/CMakeLists.txt (+1, -1) (Diff)
/intern/cycles/kernel/osl/CMakeLists.txt (+4, -0) (Diff)
/intern/cycles/render/CMakeLists.txt (+3, -0) (Diff)
/intern/ghost/CMakeLists.txt (+8, -0) (Diff)
/intern/libmv/bundle.sh (+6, -1) (Diff)
/intern/libmv/CMakeLists.txt (+6, -1) (Diff)
/intern/locale/CMakeLists.txt (+3, -0) (Diff)
/intern/mantaflow/CMakeLists.txt (+4, -0) (Diff)
/intern/opencolorio/CMakeLists.txt (+7, -0) (Diff)
/intern/opensubdiv/CMakeLists.txt (+10, -0) (Diff)
/intern/openvdb/CMakeLists.txt (+15, -0) (Diff)
/intern/quadriflow/CMakeLists.txt (+1, -0) (Diff)
/intern/rigidbody/CMakeLists.txt (+1, -0) (Diff)
/source/blender/alembic/CMakeLists.txt (+10, -0) (Diff)
/source/blender/avi/CMakeLists.txt (+1, -0) (Diff)
/source/blender/blenfont/CMakeLists.txt (+2, -0) (Diff)
/source/blender/blenkernel/CMakeLists.txt (+21, -0) (Diff)
/source/blender/blenlib/CMakeLists.txt (+2, -0) (Diff)
/source/blender/blentranslation/msgfmt/CMakeLists.txt (+1, -0) (Diff)
/source/blender/bmesh/CMakeLists.txt (+2, -0) (Diff)
/source/blender/collada/CMakeLists.txt (+3, -0) (Diff)
/source/blender/compositor/CMakeLists.txt (+4, -0) (Diff)
/source/blender/editors/sound/CMakeLists.txt (+3, -0) (Diff)
/source/blender/editors/space_graph/CMakeLists.txt (+3, -0) (Diff)
/source/blender/editors/space_sequencer/CMakeLists.txt (+4, -0) (Diff)
/source/blender/freestyle/CMakeLists.txt (+3, -0) (Diff)
/source/blender/gpu/CMakeLists.txt (+1, -0) (Diff)
/source/blender/imbuf/CMakeLists.txt (+13, -0) (Diff)
/source/blender/imbuf/intern/oiio/CMakeLists.txt (+11, -0) (Diff)
/source/blender/imbuf/intern/openexr/CMakeLists.txt (+3, -0) (Diff)
/source/blender/makesrna/intern/CMakeLists.txt (+7, -0) (Diff)
/source/blender/nodes/CMakeLists.txt (+4, -0) (Diff)
/source/blender/physics/CMakeLists.txt (+6, -0) (Diff)
/source/blender/python/bmesh/CMakeLists.txt (+3, -0) (Diff)
/source/blender/python/generic/CMakeLists.txt (+2, -0) (Diff)
/source/blender/python/gpu/CMakeLists.txt (+2, -0) (Diff)
/source/blender/python/intern/CMakeLists.txt (+11, -0) (Diff)
/source/blender/python/mathutils/CMakeLists.txt (+3, -0) (Diff)
/source/blender/usd/CMakeLists.txt (+32, -0) (Diff)
/source/blender/windowmanager/CMakeLists.txt (+7, -0) (Diff)
/tests/gtests/alembic/CMakeLists.txt (+3, -0) (Diff)
/tests/gtests/blenlib/CMakeLists.txt (+1, -0) (Diff)
/tests/gtests/usd/CMakeLists.txt (+3, -0) (Diff)
By: Miika HämäläinenLast update: Nov-07-2014 14:18MiikaHweb | 2003-2021