diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2020-01-20 20:36:19 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2020-01-23 18:59:18 +0300 |
commit | 517870a4a11f660c71d3901818fbb09798cb2d7d (patch) | |
tree | 11773a96b156339b5168e94ae0968929fdce2025 /source/blender | |
parent | 544ee7a4f2f81094967559dfd1dd21ae9f4b9809 (diff) |
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
Diffstat (limited to 'source/blender')
27 files changed, 164 insertions, 0 deletions
diff --git a/source/blender/alembic/CMakeLists.txt b/source/blender/alembic/CMakeLists.txt index 82812fb81cf..4618246013a 100644 --- a/source/blender/alembic/CMakeLists.txt +++ b/source/blender/alembic/CMakeLists.txt @@ -75,10 +75,20 @@ set(SRC set(LIB bf_blenkernel bf_blenlib + + ${ALEMBIC_LIBRARIES} + ${OPENEXR_LIBRARIES} ) if(WITH_ALEMBIC_HDF5) add_definitions(-DWITH_ALEMBIC_HDF5) + list(APPEND LIB + ${HDF5_LIBRARIES} + ) endif() +list(APPEND LIB + ${BOOST_LIBRARIES} +) + blender_add_lib(bf_alembic "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/avi/CMakeLists.txt b/source/blender/avi/CMakeLists.txt index 721905ec9d4..eafb299944d 100644 --- a/source/blender/avi/CMakeLists.txt +++ b/source/blender/avi/CMakeLists.txt @@ -47,6 +47,7 @@ set(SRC ) set(LIB + ${JPEG_LIBRARIES} ) blender_add_lib(bf_avi "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/blenfont/CMakeLists.txt b/source/blender/blenfont/CMakeLists.txt index ba8697a44b6..fa02d6d21c9 100644 --- a/source/blender/blenfont/CMakeLists.txt +++ b/source/blender/blenfont/CMakeLists.txt @@ -54,6 +54,8 @@ set(SRC set(LIB bf_gpu bf_intern_guardedalloc + + ${FREETYPE_LIBRARY} ) if(WIN32) diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 3db878ab95f..61aeb51a197 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -423,6 +423,10 @@ if(WITH_AUDASPACE) list(APPEND INC_SYS ${AUDASPACE_C_INCLUDE_DIRS} ) + list(APPEND LIB + ${AUDASPACE_C_LIBRARIES} + ${AUDASPACE_PY_LIBRARIES} + ) endif() if(WITH_BULLET) @@ -435,6 +439,8 @@ if(WITH_BULLET) list(APPEND LIB bf_intern_rigidbody extern_bullet + + ${BULLET_LIBRARIES} ) add_definitions(-DWITH_BULLET) endif() @@ -489,6 +495,9 @@ if(WITH_CODEC_FFMPEG) list(APPEND INC_SYS ${FFMPEG_INCLUDE_DIRS} ) + list(APPEND LIB + ${FFMPEG_LIBRARIES} + ) add_definitions(-DWITH_FFMPEG) remove_strict_c_flags_file( @@ -542,6 +551,9 @@ if(WITH_LZO) list(APPEND INC_SYS ${LZO_INCLUDE_DIR} ) + list(APPEND LIB + ${LZO_LIBRARIES} + ) add_definitions(-DWITH_SYSTEM_LZO) else() list(APPEND INC_SYS @@ -572,6 +584,9 @@ if(WITH_FFTW3) list(APPEND INC_SYS ${FFTW3_INCLUDE_DIRS} ) + list(APPEND LIB + ${FFTW3_LIBRARIES} + ) add_definitions(-DFFTW3=1) endif() @@ -594,6 +609,9 @@ if(WITH_OPENSUBDIV) list(APPEND INC_SYS ${OPENSUBDIV_INCLUDE_DIRS} ) + list(APPEND LIB + ${OPENSUBDIV_LIBRARIES} + ) add_definitions(-DWITH_OPENSUBDIV) endif() @@ -629,6 +647,9 @@ if(WITH_TBB) list(APPEND INC_SYS ${TBB_INCLUDE_DIRS} ) + list(APPEND LIB + ${TBB_LIBRARIES} + ) endif() # # Warnings as errors, this is too strict! diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index f3740b5d39f..d22b1cd0ddb 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -261,6 +261,8 @@ set(LIB bf_intern_guardedalloc bf_intern_numaapi extern_wcwidth + + ${FREETYPE_LIBRARY} ) if(WITH_MEM_VALGRIND) diff --git a/source/blender/blentranslation/msgfmt/CMakeLists.txt b/source/blender/blentranslation/msgfmt/CMakeLists.txt index 0361137f5b1..147c375aa6e 100644 --- a/source/blender/blentranslation/msgfmt/CMakeLists.txt +++ b/source/blender/blentranslation/msgfmt/CMakeLists.txt @@ -30,6 +30,7 @@ set(SRC msgfmt.c ) +setup_libdirs() add_cc_flags_custom_test(msgfmt) if(APPLE) diff --git a/source/blender/bmesh/CMakeLists.txt b/source/blender/bmesh/CMakeLists.txt index 00954eb400c..35c33837d64 100644 --- a/source/blender/bmesh/CMakeLists.txt +++ b/source/blender/bmesh/CMakeLists.txt @@ -183,6 +183,8 @@ if(WITH_BULLET) ) list(APPEND LIB extern_bullet + + ${BULLET_LIBRARIES} ) add_definitions(-DWITH_BULLET) endif() diff --git a/source/blender/collada/CMakeLists.txt b/source/blender/collada/CMakeLists.txt index 40762db759e..a88fd05a18f 100644 --- a/source/blender/collada/CMakeLists.txt +++ b/source/blender/collada/CMakeLists.txt @@ -126,6 +126,9 @@ set(SRC ) set(LIB + ${OPENCOLLADA_LIBRARIES} + ${PCRE_LIBRARIES} + ${XML2_LIBRARIES} ) if(WITH_BUILDINFO) diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt index ed14397f73c..8d609d545f8 100644 --- a/source/blender/compositor/CMakeLists.txt +++ b/source/blender/compositor/CMakeLists.txt @@ -568,6 +568,10 @@ if(WITH_OPENIMAGEDENOISE) ${OPENIMAGEDENOISE_INCLUDE_DIRS} ${TBB_INCLUDE_DIRS} ) + list(APPEND LIB + ${OPENIMAGEDENOISE_LIBRARIES} + ${TBB_LIBRARIES} + ) endif() blender_add_lib(bf_compositor "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/sound/CMakeLists.txt b/source/blender/editors/sound/CMakeLists.txt index 7f4b5a45aa3..b4099edce68 100644 --- a/source/blender/editors/sound/CMakeLists.txt +++ b/source/blender/editors/sound/CMakeLists.txt @@ -47,6 +47,9 @@ if(WITH_AUDASPACE) ) list(APPEND LIB bf_intern_audaspace + + ${AUDASPACE_C_LIBRARIES} + ${AUDASPACE_PY_LIBRARIES} ) add_definitions(-DWITH_AUDASPACE) endif() diff --git a/source/blender/editors/space_graph/CMakeLists.txt b/source/blender/editors/space_graph/CMakeLists.txt index f4d31886e3f..8170c920990 100644 --- a/source/blender/editors/space_graph/CMakeLists.txt +++ b/source/blender/editors/space_graph/CMakeLists.txt @@ -56,6 +56,9 @@ if(WITH_AUDASPACE) ) list(APPEND LIB bf_intern_audaspace + + ${AUDASPACE_C_LIBRARIES} + ${AUDASPACE_PY_LIBRARIES} ) add_definitions(-DWITH_AUDASPACE) endif() diff --git a/source/blender/editors/space_sequencer/CMakeLists.txt b/source/blender/editors/space_sequencer/CMakeLists.txt index 84ded1dd2c7..da7d9e2a8f3 100644 --- a/source/blender/editors/space_sequencer/CMakeLists.txt +++ b/source/blender/editors/space_sequencer/CMakeLists.txt @@ -62,6 +62,10 @@ if(WITH_AUDASPACE) list(APPEND INC_SYS ${AUDASPACE_C_INCLUDE_DIRS} ) + list(APPEND LIB + ${AUDASPACE_C_LIBRARIES} + ${AUDASPACE_PY_LIBRARIES} + ) endif() if(WITH_INTERNATIONAL) diff --git a/source/blender/freestyle/CMakeLists.txt b/source/blender/freestyle/CMakeLists.txt index ba5172c7916..8270476e9dd 100644 --- a/source/blender/freestyle/CMakeLists.txt +++ b/source/blender/freestyle/CMakeLists.txt @@ -549,6 +549,9 @@ set(SRC set(LIB bf_python_mathutils + + ${PYTHON_LINKFLAGS} + ${PYTHON_LIBRARIES} ) set(INC diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 8daeda67c80..25f9ef886e9 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -129,6 +129,7 @@ set(SRC ) set(LIB + ${BLENDER_GL_LIBRARIES} ) if(NOT WITH_SYSTEM_GLEW) diff --git a/source/blender/imbuf/CMakeLists.txt b/source/blender/imbuf/CMakeLists.txt index b8d43b8e9c2..7aab644fc12 100644 --- a/source/blender/imbuf/CMakeLists.txt +++ b/source/blender/imbuf/CMakeLists.txt @@ -90,6 +90,9 @@ set(LIB bf_intern_guardedalloc bf_intern_memutil bf_intern_opencolorio + + ${PNG_LIBRARIES} + ${JPEG_LIBRARIES} ) if(WITH_IMAGE_OPENEXR) @@ -110,6 +113,9 @@ if(WITH_IMAGE_TIFF) list(APPEND SRC intern/tiff.c ) + list(APPEND LIB + ${TIFF_LIBRARY} + ) add_definitions(-DWITH_TIFF) endif() @@ -128,6 +134,9 @@ if(WITH_IMAGE_OPENJPEG) list(APPEND SRC intern/jp2.c ) + list(APPEND LIB + ${OPENJPEG_LIBRARIES} + ) add_definitions(-DWITH_OPENJPEG ${OPENJPEG_DEFINES}) endif() @@ -149,6 +158,10 @@ if(WITH_CODEC_FFMPEG) list(APPEND INC_SYS ${FFMPEG_INCLUDE_DIRS} ) + list(APPEND LIB + ${FFMPEG_LIBRARIES} + ${OPENJPEG_LIBRARIES} + ) add_definitions(-DWITH_FFMPEG) remove_strict_c_flags_file( diff --git a/source/blender/imbuf/intern/oiio/CMakeLists.txt b/source/blender/imbuf/intern/oiio/CMakeLists.txt index 984e62bc75a..211b6a0b40e 100644 --- a/source/blender/imbuf/intern/oiio/CMakeLists.txt +++ b/source/blender/imbuf/intern/oiio/CMakeLists.txt @@ -47,11 +47,22 @@ if(WITH_OPENIMAGEIO) ${OPENIMAGEIO_INCLUDE_DIRS} ${BOOST_INCLUDE_DIR} ) + list(APPEND LIB + ${OPENIMAGEIO_LIBRARIES} + ) if(WITH_IMAGE_OPENEXR) list(APPEND INC_SYS ${OPENEXR_INCLUDE_DIRS} ) + list(APPEND LIB + ${OPENEXR_LIBRARIES} + ) endif() + + list(APPEND LIB + ${BOOST_LIBRARIES} + ) + add_definitions(-DWITH_OPENIMAGEIO) endif() diff --git a/source/blender/imbuf/intern/openexr/CMakeLists.txt b/source/blender/imbuf/intern/openexr/CMakeLists.txt index fc584ace81e..a84f31c7025 100644 --- a/source/blender/imbuf/intern/openexr/CMakeLists.txt +++ b/source/blender/imbuf/intern/openexr/CMakeLists.txt @@ -47,6 +47,9 @@ if(WITH_IMAGE_OPENEXR) list(APPEND INC_SYS ${OPENEXR_INCLUDE_DIRS} ) + list(APPEND LIB + ${OPENEXR_LIBRARIES} + ) add_definitions(-DWITH_OPENEXR) endif() diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt index 3082daa83a4..b2f1f6c651d 100644 --- a/source/blender/makesrna/intern/CMakeLists.txt +++ b/source/blender/makesrna/intern/CMakeLists.txt @@ -228,6 +228,10 @@ if(WITH_AUDASPACE) list(APPEND INC_SYS ${AUDASPACE_C_INCLUDE_DIRS} ) + list(APPEND LIB + ${AUDASPACE_C_LIBRARIES} + ${AUDASPACE_PY_LIBRARIES} + ) endif() if(WITH_CODEC_FFMPEG) @@ -237,6 +241,9 @@ if(WITH_CODEC_FFMPEG) list(APPEND INC_SYS ${FFMPEG_INCLUDE_DIRS} ) + list(APPEND LIB + ${FFMPEG_LIBRARIES} + ) add_definitions(-DWITH_FFMPEG) endif() diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt index 2eb2a6b380a..e15eb5af2c4 100644 --- a/source/blender/nodes/CMakeLists.txt +++ b/source/blender/nodes/CMakeLists.txt @@ -275,6 +275,10 @@ if(WITH_PYTHON) list(APPEND INC_SYS ${PYTHON_INCLUDE_DIRS} ) + list(APPEND LIB + ${PYTHON_LINKFLAGS} + ${PYTHON_LIBRARIES} + ) add_definitions(-DWITH_PYTHON) endif() diff --git a/source/blender/physics/CMakeLists.txt b/source/blender/physics/CMakeLists.txt index edcfdceb697..10520a18513 100644 --- a/source/blender/physics/CMakeLists.txt +++ b/source/blender/physics/CMakeLists.txt @@ -48,4 +48,10 @@ set(SRC set(LIB ) +if(WITH_OPENMP_STATIC) + list(APPEND LIB + ${OpenMP_LIBRARIES} + ) +endif() + blender_add_lib(bf_physics "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/python/bmesh/CMakeLists.txt b/source/blender/python/bmesh/CMakeLists.txt index 3875057185a..818498fe7db 100644 --- a/source/blender/python/bmesh/CMakeLists.txt +++ b/source/blender/python/bmesh/CMakeLists.txt @@ -55,6 +55,9 @@ set(LIB bf_blenkernel bf_blenlib bf_python_mathutils + + ${PYTHON_LINKFLAGS} + ${PYTHON_LIBRARIES} ) if(WITH_FREESTYLE) diff --git a/source/blender/python/generic/CMakeLists.txt b/source/blender/python/generic/CMakeLists.txt index c878103e19d..822f05bad90 100644 --- a/source/blender/python/generic/CMakeLists.txt +++ b/source/blender/python/generic/CMakeLists.txt @@ -50,6 +50,8 @@ set(SRC set(LIB ${GLEW_LIBRARY} + ${PYTHON_LINKFLAGS} + ${PYTHON_LIBRARIES} ) add_definitions(${GL_DEFINITIONS}) diff --git a/source/blender/python/gpu/CMakeLists.txt b/source/blender/python/gpu/CMakeLists.txt index ca0e6ced42b..22a3d3a79de 100644 --- a/source/blender/python/gpu/CMakeLists.txt +++ b/source/blender/python/gpu/CMakeLists.txt @@ -55,6 +55,8 @@ set(SRC ) set(LIB + ${PYTHON_LINKFLAGS} + ${PYTHON_LIBRARIES} ) add_definitions(${GL_DEFINITIONS}) diff --git a/source/blender/python/intern/CMakeLists.txt b/source/blender/python/intern/CMakeLists.txt index 012492fe9a7..adcda710622 100644 --- a/source/blender/python/intern/CMakeLists.txt +++ b/source/blender/python/intern/CMakeLists.txt @@ -123,6 +123,9 @@ set(LIB bf_editor_interface bf_editor_space_api bf_python_gpu + + ${PYTHON_LINKFLAGS} + ${PYTHON_LIBRARIES} ) # only to check if buildinfo is available @@ -156,6 +159,9 @@ if(WITH_CODEC_FFMPEG) list(APPEND INC_SYS ${FFMPEG_INCLUDE_DIRS} ) + list(APPEND LIB + ${FFMPEG_LIBRARIES} + ) add_definitions(-DWITH_FFMPEG) endif() @@ -240,6 +246,11 @@ if(WITH_SDL) list(APPEND INC_SYS ${SDL_INCLUDE_DIR} ) + if(NOT WITH_SDL_DYNLOAD) + list(APPEND LIB + ${SDL_LIBRARY} + ) + endif() add_definitions(-DWITH_SDL) endif() diff --git a/source/blender/python/mathutils/CMakeLists.txt b/source/blender/python/mathutils/CMakeLists.txt index cdb562a3233..e34432f0c54 100644 --- a/source/blender/python/mathutils/CMakeLists.txt +++ b/source/blender/python/mathutils/CMakeLists.txt @@ -58,6 +58,9 @@ set(SRC set(LIB bf_blenlib bf_python_ext + + ${PYTHON_LINKFLAGS} + ${PYTHON_LIBRARIES} ) diff --git a/source/blender/usd/CMakeLists.txt b/source/blender/usd/CMakeLists.txt index 12d281f643d..1d72593f829 100644 --- a/source/blender/usd/CMakeLists.txt +++ b/source/blender/usd/CMakeLists.txt @@ -78,4 +78,36 @@ set(LIB bf_blenlib ) +# Source: https://github.com/PixarAnimationStudios/USD/blob/master/BUILDING.md#linking-whole-archives +if(WIN32) + list(APPEND LIB + ${USD_LIBRARIES} + ) +elseif(CMAKE_COMPILER_IS_GNUCXX) + list(APPEND LIB + -Wl,--whole-archive ${USD_LIBRARIES} -Wl,--no-whole-archive + ) +elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + list(APPEND LIB + -Wl,-force_load ${USD_LIBRARIES} + ) +else() + message(FATAL_ERROR "Unknown how to link USD with your compiler ${CMAKE_CXX_COMPILER_ID}") +endif() + +list(APPEND LIB + ${BOOST_LIBRARIES} +) + +list(APPEND LIB + ${TBB_LIBRARIES} +) + blender_add_lib(bf_usd "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") + +if(WIN32) + set_property(TARGET bf_usd APPEND_STRING PROPERTY LINK_FLAGS_DEBUG " /WHOLEARCHIVE:${USD_DEBUG_LIB}") + set_property(TARGET bf_usd APPEND_STRING PROPERTY LINK_FLAGS_RELEASE " /WHOLEARCHIVE:${USD_RELEASE_LIB}") + set_property(TARGET bf_usd APPEND_STRING PROPERTY LINK_FLAGS_RELWITHDEBINFO " /WHOLEARCHIVE:${USD_RELEASE_LIB}") + set_property(TARGET bf_usd APPEND_STRING PROPERTY LINK_FLAGS_MINSIZEREL " /WHOLEARCHIVE:${USD_RELEASE_LIB}") +endif() diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt index ab87f81dba5..73fbde4148e 100644 --- a/source/blender/windowmanager/CMakeLists.txt +++ b/source/blender/windowmanager/CMakeLists.txt @@ -122,6 +122,10 @@ if(WITH_AUDASPACE) list(APPEND INC_SYS ${AUDASPACE_C_INCLUDE_DIRS} ) + list(APPEND LIB + ${AUDASPACE_C_LIBRARIES} + ${AUDASPACE_PY_LIBRARIES} + ) endif() add_definitions(${GL_DEFINITIONS}) @@ -138,6 +142,9 @@ if(WITH_CODEC_FFMPEG) list(APPEND INC_SYS ${FFMPEG_INCLUDE_DIRS} ) + list(APPEND LIB + ${FFMPEG_LIBRARIES} + ) add_definitions(-DWITH_FFMPEG) endif() |