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
master
Sergey Sharybin 4 years ago
parent 544ee7a4f2
commit 517870a4a1

@ -780,9 +780,11 @@ if(NOT CMAKE_BUILD_TYPE MATCHES "Release")
if(MSVC)
set(COMPILER_ASAN_LINKER_FLAGS "/FUNCTIONPADMIN:6")
endif()
set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS};${COMPILER_ASAN_LIBRARY}")
set(PLATFORM_LINKFLAGS "${COMPILER_ASAN_LIBRARY} ${COMPILER_ASAN_LINKER_FLAGS}")
set(PLATFORM_LINKFLAGS_DEBUG "${COMPILER_ASAN_LIBRARY} ${COMPILER_ASAN_LINKER_FLAGS}")
if(COMPILER_ASAN_LIBRARY)
set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS};${COMPILER_ASAN_LIBRARY}")
set(PLATFORM_LINKFLAGS "${COMPILER_ASAN_LIBRARY} ${COMPILER_ASAN_LINKER_FLAGS}")
set(PLATFORM_LINKFLAGS_DEBUG "${COMPILER_ASAN_LIBRARY} ${COMPILER_ASAN_LINKER_FLAGS}")
endif()
endif()
endif()

@ -251,8 +251,59 @@ function(blender_add_lib__impl
add_library(${name} ${sources})
# On Windows certain libraries have two sets of binaries: one for debug builds and one for
# release builds. The root of this requirement goes into ABI, I believe, but that's outside
# of a scope of this comment.
#
# CMake have a native way of dealing with this, which is specifying what build type the
# libraries are provided for:
#
# target_link_libraries(tagret optimized|debug|general <libraries>)
#
# The build type is to be provided as a separate argument to the function.
#
# CMake's variables for libraries will contain build type in such cases. For example:
#
# set(FOO_LIBRARIES optimized libfoo.lib debug libfoo_d.lib)
#
# Complications starts with a single argument for library_deps: all the elements are being
# put to a list: "${FOO_LIBRARIES}" will become "optimized;libfoo.lib;debug;libfoo_d.lib".
# This makes it impossible to pass it as-is to target_link_libraries sine it will treat
# this argument as a list of libraries to be linked against, causing missing libraries
# for optimized.lib.
#
# What this code does it traverses library_deps and extracts information about whether
# library is to provided as general, debug or optimized. This is a little state machine which
# keeps track of whiuch build type library is to provided for:
#
# - If "debug" or "optimized" word is found, the next element in the list is expected to be
# a library which will be passed to target_link_libraries() under corresponding build type.
#
# - If there is no "debug" or "optimized" used library is specified for all build types.
#
# NOTE: If separated libraries for debug and release ar eneeded every library is the list are
# to be prefixed explicitly.
#
# Use: "optimized libfoo optimized libbar debug libfoo_d debug libbar_d"
# NOT: "optimized libfoo libbar debug libfoo_d libbar_d"
if(NOT "${library_deps}" STREQUAL "")
target_link_libraries(${name} INTERFACE "${library_deps}")
set(next_library_mode "")
foreach(library ${library_deps})
string(TOLOWER "${library}" library_lower)
if(("${library_lower}" STREQUAL "optimized") OR
("${library_lower}" STREQUAL "debug"))
set(next_library_mode "${library_lower}")
else()
if("${next_library_mode}" STREQUAL "optimized")
target_link_libraries(${name} optimized ${library})
elseif("${next_library_mode}" STREQUAL "debug")
target_link_libraries(${name} debug ${library})
else()
target_link_libraries(${name} ${library})
endif()
set(next_library_mode "")
endif()
endforeach()
endif()
# works fine without having the includes
@ -404,6 +455,11 @@ function(setup_liblinks
target
)
# NOTE: This might look like it affects global scope, accumulating linker flags on every call
# to setup_liblinks, but this isn't how CMake works. These flags will only affect current
# directory from where the function is called.
# This means that setup_liblinks() called for ffmpeg_test will not affect blender, and each
# of thsoe targets will have single set of linker flags.
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}" PARENT_SCOPE)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}" PARENT_SCOPE)
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${PLATFORM_LINKFLAGS_RELEASE}" PARENT_SCOPE)
@ -416,201 +472,17 @@ function(setup_liblinks
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}" PARENT_SCOPE)
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} ${PLATFORM_LINKFLAGS_RELEASE}" PARENT_SCOPE)
# Work around undefined reference errors when disabling certain libraries.
# Finding the right order for all combinations of options is too hard, so
# we use --start-group and --end-group so the linker does not discard symbols
# too early. This appears to have no significant performance impact.
if(UNIX AND NOT APPLE)
target_link_libraries(
${target}
-Wl,--start-group
)
endif()
# jemalloc must be early in the list, to be before pthread (see T57998)
if(WITH_MEM_JEMALLOC)
target_link_libraries(${target} ${JEMALLOC_LIBRARIES})
endif()
target_link_libraries(
${target}
${PNG_LIBRARIES}
${FREETYPE_LIBRARY}
)
if(WITH_PYTHON)
target_link_libraries(${target} ${PYTHON_LINKFLAGS})
target_link_libraries(${target} ${PYTHON_LIBRARIES})
endif()
if(WITH_LZO AND WITH_SYSTEM_LZO)
target_link_libraries(${target} ${LZO_LIBRARIES})
endif()
if(WITH_SYSTEM_GLEW)
target_link_libraries(${target} ${BLENDER_GLEW_LIBRARIES})
endif()
if(WITH_BULLET AND WITH_SYSTEM_BULLET)
target_link_libraries(${target} ${BULLET_LIBRARIES})
endif()
if(WITH_AUDASPACE AND WITH_SYSTEM_AUDASPACE)
target_link_libraries(${target} ${AUDASPACE_C_LIBRARIES} ${AUDASPACE_PY_LIBRARIES})
endif()
if(WITH_OPENAL)
target_link_libraries(${target} ${OPENAL_LIBRARY})
endif()
if(WITH_FFTW3)
target_link_libraries(${target} ${FFTW3_LIBRARIES})
endif()
if(WITH_JACK AND NOT WITH_JACK_DYNLOAD)
target_link_libraries(${target} ${JACK_LIBRARIES})
endif()
if(WITH_CODEC_SNDFILE)
target_link_libraries(${target} ${LIBSNDFILE_LIBRARIES})
endif()
if(WITH_SDL AND NOT WITH_SDL_DYNLOAD)
target_link_libraries(${target} ${SDL_LIBRARY})
endif()
if(WITH_CYCLES_OSL)
target_link_libraries(${target} ${OSL_LIBRARIES})
endif()
if(WITH_OPENVDB)
target_link_libraries(${target} ${OPENVDB_LIBRARIES} ${BLOSC_LIBRARIES})
endif()
if(WITH_USD)
# Source: https://github.com/PixarAnimationStudios/USD/blob/master/BUILDING.md#linking-whole-archives
if(WIN32)
target_link_libraries(${target} ${USD_LIBRARIES})
set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS_DEBUG " /WHOLEARCHIVE:${USD_DEBUG_LIB}")
set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS_RELEASE " /WHOLEARCHIVE:${USD_RELEASE_LIB}")
set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS_RELWITHDEBINFO " /WHOLEARCHIVE:${USD_RELEASE_LIB}")
set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS_MINSIZEREL " /WHOLEARCHIVE:${USD_RELEASE_LIB}")
elseif(CMAKE_COMPILER_IS_GNUCXX)
target_link_libraries(${target} -Wl,--whole-archive ${USD_LIBRARIES} -Wl,--no-whole-archive)
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
target_link_libraries(${target} -Wl,-force_load ${USD_LIBRARIES})
else()
message(FATAL_ERROR "Unknown how to link USD with your compiler ${CMAKE_CXX_COMPILER_ID}")
endif()
endif()
if(WITH_OPENIMAGEIO)
target_link_libraries(${target} ${OPENIMAGEIO_LIBRARIES})
endif()
if(WITH_OPENIMAGEDENOISE)
target_link_libraries(${target} ${OPENIMAGEDENOISE_LIBRARIES})
endif()
if(WITH_TBB)
target_link_libraries(${target} ${TBB_LIBRARIES})
endif()
if(WITH_OPENCOLORIO)
target_link_libraries(${target} ${OPENCOLORIO_LIBRARIES})
endif()
if(WITH_OPENSUBDIV)
target_link_libraries(${target} ${OPENSUBDIV_LIBRARIES})
endif()
if(WITH_CYCLES_EMBREE)
target_link_libraries(${target} ${EMBREE_LIBRARIES})
endif()
if(WITH_BOOST)
target_link_libraries(${target} ${BOOST_LIBRARIES})
if(Boost_USE_STATIC_LIBS AND Boost_USE_ICU)
target_link_libraries(${target} ${ICU_LIBRARIES})
endif()
endif()
target_link_libraries(${target} ${JPEG_LIBRARIES})
if(WITH_ALEMBIC)
target_link_libraries(${target} ${ALEMBIC_LIBRARIES} ${HDF5_LIBRARIES})
endif()
if(WITH_IMAGE_TIFF)
target_link_libraries(${target} ${TIFF_LIBRARY})
endif()
if(WITH_IMAGE_OPENEXR)
target_link_libraries(${target} ${OPENEXR_LIBRARIES})
endif()
if(WITH_IMAGE_OPENJPEG)
target_link_libraries(${target} ${OPENJPEG_LIBRARIES})
endif()
if(WITH_CODEC_FFMPEG)
target_link_libraries(${target} ${FFMPEG_LIBRARIES})
endif()
if(WITH_OPENCOLLADA)
if(WIN32 AND NOT UNIX)
file_list_suffix(OPENCOLLADA_LIBRARIES_DEBUG "${OPENCOLLADA_LIBRARIES}" "_d")
target_link_libraries_debug(${target} "${OPENCOLLADA_LIBRARIES_DEBUG}")
target_link_libraries_optimized(${target} "${OPENCOLLADA_LIBRARIES}")
unset(OPENCOLLADA_LIBRARIES_DEBUG)
file_list_suffix(PCRE_LIBRARIES_DEBUG "${PCRE_LIBRARIES}" "_d")
target_link_libraries_debug(${target} "${PCRE_LIBRARIES_DEBUG}")
target_link_libraries_optimized(${target} "${PCRE_LIBRARIES}")
unset(PCRE_LIBRARIES_DEBUG)
if(EXPAT_LIB)
file_list_suffix(EXPAT_LIB_DEBUG "${EXPAT_LIB}" "_d")
target_link_libraries_debug(${target} "${EXPAT_LIB_DEBUG}")
target_link_libraries_optimized(${target} "${EXPAT_LIB}")
unset(EXPAT_LIB_DEBUG)
endif()
else()
target_link_libraries(
${target}
${OPENCOLLADA_LIBRARIES}
${PCRE_LIBRARIES}
${XML2_LIBRARIES}
${EXPAT_LIB}
)
endif()
endif()
if(WITH_LLVM)
target_link_libraries(${target} ${LLVM_LIBRARY})
endif()
if(WIN32 AND NOT UNIX)
target_link_libraries(${target} ${PTHREADS_LIBRARIES})
endif()
if(UNIX AND NOT APPLE)
if(WITH_OPENMP_STATIC)
target_link_libraries(${target} ${OpenMP_LIBRARIES})
endif()
if(WITH_INPUT_NDOF)
target_link_libraries(${target} ${NDOF_LIBRARIES})
endif()
endif()
if(WITH_SYSTEM_GLOG)
target_link_libraries(${target} ${GLOG_LIBRARIES})
endif()
if(WITH_SYSTEM_GFLAGS)
target_link_libraries(${target} ${GFLAGS_LIBRARIES})
endif()
# We put CLEW and CUEW here because OPENSUBDIV_LIBRARIES depends on them..
if(WITH_CYCLES OR WITH_COMPOSITOR OR WITH_OPENSUBDIV)
target_link_libraries(${target} "extern_clew")
if(WITH_CUDA_DYNLOAD)
target_link_libraries(${target} "extern_cuew")
else()
target_link_libraries(${target} ${CUDA_CUDA_LIBRARY})
endif()
endif()
target_link_libraries(
${target}
${ZLIB_LIBRARIES}
)
# System libraries with no dependencies such as platform link libs or opengl should go last.
target_link_libraries(${target}
${BLENDER_GL_LIBRARIES})
# target_link_libraries(${target} ${PLATFORM_LINKLIBS} ${CMAKE_DL_LIBS})
target_link_libraries(${target} ${PLATFORM_LINKLIBS})
# See comments above regarding --start-group.
if(UNIX AND NOT APPLE)
target_link_libraries(
${target}
-Wl,--end-group
)
endif()
endfunction()
macro(TEST_SSE_SUPPORT

@ -132,13 +132,13 @@ if(WITH_FFTW3)
set(FFTW3_LIBPATH ${FFTW3}/lib)
endif()
set(PNG_LIBRARIES png)
set(JPEG_LIBRARIES jpeg)
set(ZLIB /usr)
set(ZLIB_INCLUDE_DIRS "${ZLIB}/include")
set(ZLIB_LIBRARIES z bz2)
set(PNG_LIBRARIES png ${ZLIB_LIBRARIES})
set(JPEG_LIBRARIES jpeg)
set(FREETYPE ${LIBDIR}/freetype)
set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
set(FREETYPE_LIBPATH ${FREETYPE}/lib)
@ -228,10 +228,6 @@ if(WITH_OPENCOLLADA)
# set(PCRE ${LIBDIR}/pcre)
# set(PCRE_LIBPATH ${PCRE}/lib)
set(PCRE_LIBRARIES pcre)
# libxml2 is used
# set(EXPAT ${LIBDIR}/expat)
# set(EXPAT_LIBPATH ${EXPAT}/lib)
set(EXPAT_LIB)
endif()
if(WITH_SDL)

@ -336,6 +336,11 @@ if(WITH_BOOST)
set(BOOST_LIBRARIES ${Boost_LIBRARIES})
set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
if(Boost_USE_STATIC_LIBS AND WITH_BOOST_ICU)
find_package(IcuLinux)
list(APPEND BOOST_LIBRARIES ${ICU_LIBRARIES})
endif()
endif()
if(WITH_OPENIMAGEIO)

@ -225,7 +225,7 @@ windows_find_package(png)
if(NOT PNG_FOUND)
warn_hardcoded_paths(libpng)
set(PNG_PNG_INCLUDE_DIR ${LIBDIR}/png/include)
set(PNG_LIBRARIES ${LIBDIR}/png/lib/libpng.lib)
set(PNG_LIBRARIES ${LIBDIR}/png/lib/libpng.lib ${ZLIB_LIBRARY})
set(PNG "${LIBDIR}/png")
set(PNG_INCLUDE_DIRS "${PNG}/include")
set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
@ -269,21 +269,33 @@ if(WITH_OPENCOLLADA)
)
set(OPENCOLLADA_LIBRARIES
${OPENCOLLADA}/lib/opencollada/OpenCOLLADASaxFrameworkLoader.lib
${OPENCOLLADA}/lib/opencollada/OpenCOLLADAFramework.lib
${OPENCOLLADA}/lib/opencollada/OpenCOLLADABaseUtils.lib
${OPENCOLLADA}/lib/opencollada/OpenCOLLADAStreamWriter.lib
${OPENCOLLADA}/lib/opencollada/MathMLSolver.lib
${OPENCOLLADA}/lib/opencollada/GeneratedSaxParser.lib
${OPENCOLLADA}/lib/opencollada/xml.lib
${OPENCOLLADA}/lib/opencollada/buffer.lib
${OPENCOLLADA}/lib/opencollada/ftoa.lib
optimized ${OPENCOLLADA}/lib/opencollada/OpenCOLLADASaxFrameworkLoader.lib
optimized ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAFramework.lib
optimized ${OPENCOLLADA}/lib/opencollada/OpenCOLLADABaseUtils.lib
optimized ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAStreamWriter.lib
optimized ${OPENCOLLADA}/lib/opencollada/MathMLSolver.lib
optimized ${OPENCOLLADA}/lib/opencollada/GeneratedSaxParser.lib
optimized ${OPENCOLLADA}/lib/opencollada/xml.lib
optimized ${OPENCOLLADA}/lib/opencollada/buffer.lib
optimized ${OPENCOLLADA}/lib/opencollada/ftoa.lib
debug ${OPENCOLLADA}/lib/opencollada/OpenCOLLADASaxFrameworkLoader_d.lib
debug ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAFramework_d.lib
debug ${OPENCOLLADA}/lib/opencollada/OpenCOLLADABaseUtils_d.lib
debug ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAStreamWriter_d.lib
debug ${OPENCOLLADA}/lib/opencollada/MathMLSolver_d.lib
debug ${OPENCOLLADA}/lib/opencollada/GeneratedSaxParser_d.lib
debug ${OPENCOLLADA}/lib/opencollada/xml_d.lib
debug ${OPENCOLLADA}/lib/opencollada/buffer_d.lib
debug ${OPENCOLLADA}/lib/opencollada/ftoa_d.lib
)
list(APPEND OPENCOLLADA_LIBRARIES ${OPENCOLLADA}/lib/opencollada/UTF.lib)
set(PCRE_LIBRARIES
${OPENCOLLADA}/lib/opencollada/pcre.lib
optimized ${OPENCOLLADA}/lib/opencollada/pcre.lib
debug ${OPENCOLLADA}/lib/opencollada/pcre_d.lib
)
endif()

@ -257,7 +257,8 @@ set(SRC
)
set(LIB
extern_glog
${GLOG_LIBRARIES}
${GFLAGS_LIBRARIES}
)
if(WITH_LIBMV_SCHUR_SPECIALIZATIONS)

@ -136,7 +136,8 @@ ${headers}
)
set(LIB
extern_glog
\${GLOG_LIBRARIES}
\${GFLAGS_LIBRARIES}
)
if(WITH_LIBMV_SCHUR_SPECIALIZATIONS)

@ -73,6 +73,9 @@ if(WITH_TBB)
list(APPEND INC_SYS
${TBB_INCLUDE_DIRS}
)
list(APPEND LIB
${TBB_LIBRARIES}
)
endif()
if(WITH_OPENVDB)
@ -81,6 +84,18 @@ if(WITH_OPENVDB)
${OPENEXR_INCLUDE_DIRS}
${OPENVDB_INCLUDE_DIRS}
)
list(APPEND LIB
${OPENVDB_LIBRARIES}
${OPENEXR_LIBRARIES}
${ZLIB_LIBRARIES}
${BOOST_LIBRARIES}
)
if(WITH_OPENVDB_BLOSC)
list(APPEND LIB
${BLOSC_LIBRARIES}
${ZLIB_LIBRARIES}
)
endif()
endif()
set(SRC
@ -207,6 +222,8 @@ set(SRC
)
set(LIB
${PYTHON_LINKFLAGS}
${PYTHON_LIBRARIES}
)
blender_add_lib(extern_mantaflow "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")

@ -105,6 +105,7 @@ set(SRC
)
set(LIB
${BOOST_LIBRARIES}
)
blender_add_lib(extern_quadriflow "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")

@ -50,6 +50,11 @@ if(NOT WITH_SYSTEM_AUDASPACE)
extern_sdlew
)
endif()
else()
list(APPEND LIB
${AUDASPACE_C_LIBRARIES}
${AUDASPACE_PY_LIBRARIES}
)
endif()
if(WITH_PYTHON)
@ -60,6 +65,10 @@ if(WITH_PYTHON)
intern/AUD_PyInit.cpp
intern/AUD_PyInit.h
)
list(APPEND LIB
${PYTHON_LINKFLAGS}
${PYTHON_LIBRARIES}
)
if(NOT WITH_SYSTEM_AUDASPACE)
list(APPEND LIB
audaspace-py

@ -49,11 +49,15 @@ set(LIB
cycles_render
cycles_subd
cycles_util
${PYTHON_LINKFLAGS}
${PYTHON_LIBRARIES}
)
if(WITH_CYCLES_LOGGING)
list(APPEND LIB
extern_glog
${GLOG_LIBRARIES}
${GFLAGS_LIBRARIES}
)
endif()

@ -39,9 +39,16 @@ set(SRC_HEADERS
set(LIB
cycles_render
cycles_util
)
include_directories(${INC})
include_directories(SYSTEM ${INC_SYS})
if(WITH_CYCLES_EMBREE)
list(APPEND LIB
${EMBREE_LIBRARIES}
)
endif()
cycles_add_library(cycles_bvh "${LIB}" ${SRC} ${SRC_HEADERS})

@ -8,8 +8,64 @@ endfunction()
macro(cycles_add_library target library_deps)
add_library(${target} ${ARGN})
if(NOT ("${library_deps}" STREQUAL ""))
target_link_libraries(${target} "${library_deps}")
# On Windows certain libraries have two sets of binaries: one for debug builds and one for
# release builds. The root of this requirement goes into ABI, I believe, but that's outside
# of a scope of this comment.
#
# CMake have a native way of dealing with this, which is specifying what build type the
# libraries are provided for:
#
# target_link_libraries(tagret optimized|debug|general <libraries>)
#
# The build type is to be provided as a separate argument to the function.
#
# CMake's variables for libraries will contain build type in such cases. For example:
#
# set(FOO_LIBRARIES optimized libfoo.lib debug libfoo_d.lib)
#
# Complications starts with a single argument for library_deps: all the elements are being
# put to a list: "${FOO_LIBRARIES}" will become "optimized;libfoo.lib;debug;libfoo_d.lib".
# This makes it impossible to pass it as-is to target_link_libraries sine it will treat
# this argument as a list of libraries to be linked against, causing missing libraries
# for optimized.lib.
#
# What this code does it traverses library_deps and extracts information about whether
# library is to provided as general, debug or optimized. This is a little state machine which
# keeps track of whiuch build type library is to provided for:
#
# - If "debug" or "optimized" word is found, the next element in the list is expected to be
# a library which will be passed to target_link_libraries() under corresponding build type.
#
# - If there is no "debug" or "optimized" used library is specified for all build types.
#
# NOTE: If separated libraries for debug and release ar eneeded every library is the list are
# to be prefixed explicitly.
#
# Use: "optimized libfoo optimized libbar debug libfoo_d debug libbar_d"
# NOT: "optimized libfoo libbar debug libfoo_d libbar_d"
#
# TODO(sergey): This is the same as Blender's side CMake. Find a way to avoid duplication
# somehow in a way which allows to have Cycles standalone.
if(NOT "${library_deps}" STREQUAL "")
set(next_library_mode "")
foreach(library ${library_deps})
string(TOLOWER "${library}" library_lower)
if(("${library_lower}" STREQUAL "optimized") OR
("${library_lower}" STREQUAL "debug"))
set(next_library_mode "${library_lower}")
else()
if("${next_library_mode}" STREQUAL "optimized")
target_link_libraries(${target} optimized ${library})
elseif("${next_library_mode}" STREQUAL "debug")
target_link_libraries(${target} debug ${library})
else()
target_link_libraries(${target} ${library})
endif()
set(next_library_mode "")
endif()
endforeach()
endif()
cycles_set_solution_folder(${target})
endmacro()

@ -60,7 +60,9 @@ set(SRC_HEADERS
)
set(LIB
cycles_render
cycles_kernel
cycles_util
)
if(WITH_CUDA_DYNLOAD)

@ -17,7 +17,7 @@ set(SRC_HEADERS
)
set(LIB
cycles_util
)
include_directories(${INC})

@ -27,6 +27,10 @@ set(HEADER_SRC
set(LIB
cycles_render
${OSL_LIBRARIES}
${OPENIMAGEIO_LIBRARIES}
${LLVM_LIBRARY}
)
include_directories(${INC})

@ -77,6 +77,9 @@ set(SRC_HEADERS
set(LIB
cycles_bvh
cycles_device
cycles_subd
cycles_util
)
if(WITH_CYCLES_OSL)

@ -112,6 +112,9 @@ if(WITH_INPUT_NDOF)
list(APPEND INC_SYS
${NDOF_INCLUDE_DIRS}
)
list(APPEND LIB
${NDOF_LIBRARIES}
)
endif()
if(WITH_HEADLESS OR WITH_GHOST_SDL)
@ -141,6 +144,11 @@ if(WITH_HEADLESS OR WITH_GHOST_SDL)
list(APPEND INC_SYS
${SDL_INCLUDE_DIR}
)
if(NOT WITH_SDL_DYNLOAD)
list(APPEND LIB
${SDL_LIBRARY}
)
endif()
endif()
elseif(APPLE AND NOT WITH_X11)

@ -38,6 +38,8 @@ set(LIB
)
if(WITH_LIBMV)
setup_libdirs()
if(WIN32)
add_definitions(-D_USE_MATH_DEFINES)
endif()
@ -62,7 +64,10 @@ if(WITH_LIBMV)
list(APPEND LIB
extern_ceres
extern_glog
${GLOG_LIBRARIES}
${GFLAGS_LIBRARIES}
${PNG_LIBRARIES}
)
add_definitions(

@ -117,6 +117,8 @@ set(LIB
)
if(WITH_LIBMV)
setup_libdirs()
add_definitions(\${GFLAGS_DEFINES})
add_definitions(\${GLOG_DEFINES})
add_definitions(\${CERES_DEFINES})
@ -138,7 +140,10 @@ if(WITH_LIBMV)
list(APPEND LIB
extern_ceres
extern_glog
\${GLOG_LIBRARIES}
\${GFLAGS_LIBRARIES}
\${PNG_LIBRARIES}
)
add_definitions(

@ -53,6 +53,9 @@ if(WITH_INTERNATIONAL)
list(APPEND INC_SYS
${BOOST_INCLUDE_DIR}
)
list(APPEND LIB
${BOOST_LIBRARIES}
)
add_definitions(-DWITH_INTERNATIONAL)
add_definitions(${BOOST_DEFINITIONS})
endif()

@ -62,6 +62,10 @@ set(SRC
set(LIB
extern_mantaflow
${PYTHON_LINKFLAGS}
${PYTHON_LIBRARIES}
${ZLIB_LIBRARIES}
)
blender_add_lib(bf_intern_mantaflow "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")

@ -59,6 +59,10 @@ if(WITH_OPENCOLORIO)
ocio_impl_glsl.cc
)
list(APPEND LIB
${OPENCOLORIO_LIBRARIES}
)
if(WIN32)
list(APPEND INC_SYS
${BOOST_INCLUDE_DIR}
@ -66,6 +70,9 @@ if(WITH_OPENCOLORIO)
add_definitions(
-DOpenColorIO_STATIC
)
list(APPEND LIB
${BOOST_LIBRARIES}
)
endif()
data_to_c_simple(gpu_shader_display_transform.glsl SRC)

@ -83,6 +83,16 @@ if(WITH_OPENSUBDIV)
internal/opensubdiv_util.h
)
list(APPEND LIB
${OPENSUBDIV_LIBRARIES}
)
if(WITH_OPENMP_STATIC)
list(APPEND LIB
${OpenMP_LIBRARIES}
)
endif()
OPENSUBDIV_DEFINE_COMPONENT(OPENSUBDIV_HAS_OPENMP)
# TODO(sergey): OpenCL is not tested and totally unstable atm.
# OPENSUBDIV_DEFINE_COMPONENT(OPENSUBDIV_HAS_OPENCL)

@ -77,11 +77,26 @@ if(WITH_OPENVDB)
openvdb_util.h
)
list(APPEND LIB
${OPENVDB_LIBRARIES}
${OPENEXR_LIBRARIES}
${ZLIB_LIBRARIES}
)
if(WITH_OPENVDB_BLOSC)
add_definitions(
-DWITH_OPENVDB_BLOSC
)
list(APPEND LIB
${BLOSC_LIBRARIES}
${ZLIB_LIBRARIES}
)
endif()
list(APPEND LIB
${BOOST_LIBRARIES}
${TBB_LIBRARIES}
)
endif()
blender_add_lib(bf_intern_openvdb "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")

@ -36,6 +36,7 @@ set(SRC
set(LIB
extern_quadriflow
${BOOST_LIBRARIES}
)
if(WIN32)

@ -33,6 +33,7 @@ set(SRC
)
set(LIB
${BULLET_LIBRARIES}
)
blender_add_lib(bf_intern_rigidbody "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")

@ -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}")

@ -47,6 +47,7 @@ set(SRC
)
set(LIB
${JPEG_LIBRARIES}
)
blender_add_lib(bf_avi "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")

@ -54,6 +54,8 @@ set(SRC
set(LIB
bf_gpu
bf_intern_guardedalloc
${FREETYPE_LIBRARY}
)
if(WIN32)

@ -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!

@ -261,6 +261,8 @@ set(LIB
bf_intern_guardedalloc
bf_intern_numaapi
extern_wcwidth
${FREETYPE_LIBRARY}
)
if(WITH_MEM_VALGRIND)

@ -30,6 +30,7 @@ set(SRC
msgfmt.c
)
setup_libdirs()
add_cc_flags_custom_test(msgfmt)
if(APPLE)

@ -183,6 +183,8 @@ if(WITH_BULLET)
)
list(APPEND LIB
extern_bullet
${BULLET_LIBRARIES}
)
add_definitions(-DWITH_BULLET)
endif()

@ -126,6 +126,9 @@ set(SRC
)
set(LIB
${OPENCOLLADA_LIBRARIES}
${PCRE_LIBRARIES}
${XML2_LIBRARIES}
)
if(WITH_BUILDINFO)

@ -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}")

@ -47,6 +47,9 @@ if(WITH_AUDASPACE)
)
list(APPEND LIB
bf_intern_audaspace
${AUDASPACE_C_LIBRARIES}
${AUDASPACE_PY_LIBRARIES}
)
add_definitions(-DWITH_AUDASPACE)
endif()

@ -56,6 +56,9 @@ if(WITH_AUDASPACE)
)
list(APPEND LIB
bf_intern_audaspace
${AUDASPACE_C_LIBRARIES}
${AUDASPACE_PY_LIBRARIES}
)
add_definitions(-DWITH_AUDASPACE)
endif()

@ -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)

@ -549,6 +549,9 @@ set(SRC
set(LIB
bf_python_mathutils
${PYTHON_LINKFLAGS}
${PYTHON_LIBRARIES}
)
set(INC

@ -129,6 +129,7 @@ set(SRC
)
set(LIB
${BLENDER_GL_LIBRARIES}
)
if(NOT WITH_SYSTEM_GLEW)

@ -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(

@ -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()

@ -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()

@ -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()

@ -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()

@ -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}")

@ -55,6 +55,9 @@ set(LIB
bf_blenkernel
bf_blenlib
bf_python_mathutils
${PYTHON_LINKFLAGS}
${PYTHON_LIBRARIES}
)
if(WITH_FREESTYLE)

@ -50,6 +50,8 @@ set(SRC
set(LIB
${GLEW_LIBRARY}
${PYTHON_LINKFLAGS}
${PYTHON_LIBRARIES}
)
add_definitions(${GL_DEFINITIONS})

@ -55,6 +55,8 @@ set(SRC
)
set(LIB
${PYTHON_LINKFLAGS}
${PYTHON_LIBRARIES}
)
add_definitions(${GL_DEFINITIONS})

@ -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()

@ -58,6 +58,9 @@ set(SRC
set(LIB
bf_blenlib
bf_python_ext
${PYTHON_LINKFLAGS}
${PYTHON_LIBRARIES}
)

@ -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()

@ -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()

@ -37,6 +37,9 @@ set(LIB
bf_intern_opencolorio # Should not be needed but gives windows linker errors if the ocio libs are linked before this
bf_gpu # Should not be needed but gives windows linker errors if the ocio libs are linked before this
bf_alembic
${OPENEXR_LIBRARIES}
${BOOST_LIBRARIES}
)
include_directories(${INC})

@ -27,6 +27,7 @@ set(INC
../../../intern/atomic
)
setup_libdirs()
include_directories(${INC})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}")

@ -52,6 +52,9 @@ set(LIB
bf_gpu
bf_usd
${BOOST_LIBRARIES}
${TBB_LIBRARIES}
)
include_directories(${INC})

Loading…
Cancel
Save