CMake: Refactor external dependencies handling
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 20 Jan 2020 17:36:19 +0000 (18:36 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 23 Jan 2020 15:59:18 +0000 (16:59 +0100)
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

57 files changed:
CMakeLists.txt
build_files/cmake/macros.cmake
build_files/cmake/platform/platform_apple.cmake
build_files/cmake/platform/platform_unix.cmake
build_files/cmake/platform/platform_win32.cmake
extern/ceres/CMakeLists.txt
extern/ceres/bundle.sh
extern/mantaflow/CMakeLists.txt
extern/quadriflow/CMakeLists.txt
intern/audaspace/CMakeLists.txt
intern/cycles/blender/CMakeLists.txt
intern/cycles/bvh/CMakeLists.txt
intern/cycles/cmake/macros.cmake
intern/cycles/device/CMakeLists.txt
intern/cycles/graph/CMakeLists.txt
intern/cycles/kernel/osl/CMakeLists.txt
intern/cycles/render/CMakeLists.txt
intern/ghost/CMakeLists.txt
intern/libmv/CMakeLists.txt
intern/libmv/bundle.sh
intern/locale/CMakeLists.txt
intern/mantaflow/CMakeLists.txt
intern/opencolorio/CMakeLists.txt
intern/opensubdiv/CMakeLists.txt
intern/openvdb/CMakeLists.txt
intern/quadriflow/CMakeLists.txt
intern/rigidbody/CMakeLists.txt
source/blender/alembic/CMakeLists.txt
source/blender/avi/CMakeLists.txt
source/blender/blenfont/CMakeLists.txt
source/blender/blenkernel/CMakeLists.txt
source/blender/blenlib/CMakeLists.txt
source/blender/blentranslation/msgfmt/CMakeLists.txt
source/blender/bmesh/CMakeLists.txt
source/blender/collada/CMakeLists.txt
source/blender/compositor/CMakeLists.txt
source/blender/editors/sound/CMakeLists.txt
source/blender/editors/space_graph/CMakeLists.txt
source/blender/editors/space_sequencer/CMakeLists.txt
source/blender/freestyle/CMakeLists.txt
source/blender/gpu/CMakeLists.txt
source/blender/imbuf/CMakeLists.txt
source/blender/imbuf/intern/oiio/CMakeLists.txt
source/blender/imbuf/intern/openexr/CMakeLists.txt
source/blender/makesrna/intern/CMakeLists.txt
source/blender/nodes/CMakeLists.txt
source/blender/physics/CMakeLists.txt
source/blender/python/bmesh/CMakeLists.txt
source/blender/python/generic/CMakeLists.txt
source/blender/python/gpu/CMakeLists.txt
source/blender/python/intern/CMakeLists.txt
source/blender/python/mathutils/CMakeLists.txt
source/blender/usd/CMakeLists.txt
source/blender/windowmanager/CMakeLists.txt
tests/gtests/alembic/CMakeLists.txt
tests/gtests/blenlib/CMakeLists.txt
tests/gtests/usd/CMakeLists.txt

index 6f8b512b69b077f546615784550cff9c1f170add..70196d00df6c5c9ee23a2603fc0dce6df4c801a1 100644 (file)
@@ -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()
 
index 23ed5b6cbfbcb94318fee6766d7d916c9ddc386c..2d13476f09ab09e8ff27b772597c3001ffbb262e 100644 (file)
@@ -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
index e60760e6cfd2feb5965b47cf38a02d5a63389208..a4de3876243cae012bcbb61c6b7f0bfd4afe8ac8 100644 (file)
@@ -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)
index d4a75e5e5c0aac90a1ce2c76ae06bb2d7ffeaa4a..5d46ee751af178a1e14537754e5600b22a69cd37 100644 (file)
@@ -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)
index f485490f300cb16fce882bf84c3bd21512f1367d..b228930bfb128b64e15b6b758fc94b7566a3a80d 100644 (file)
@@ -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()
 
index 4ab3bffb70525977f64aaf45b83bd40d4ccc3f52..009445ea690ebfb544bb3704eddcc180ace14f13 100644 (file)
@@ -257,7 +257,8 @@ set(SRC
 )
 
 set(LIB
-  extern_glog
+  ${GLOG_LIBRARIES}
+  ${GFLAGS_LIBRARIES}
 )
 
 if(WITH_LIBMV_SCHUR_SPECIALIZATIONS)
index bf5a43852b578a5ce5a8d42a92c01ad0a96cfd0f..02af59faf28dc288fe8f5c283caa99cc993f5928 100755 (executable)
@@ -136,7 +136,8 @@ ${headers}
 )
 
 set(LIB
-  extern_glog
+  \${GLOG_LIBRARIES}
+  \${GFLAGS_LIBRARIES}
 )
 
 if(WITH_LIBMV_SCHUR_SPECIALIZATIONS)
index aab1fdd0219f197e316f7edeb2fbd68ba2feaccb..d2f78f7ab6c1d8ebab329b88a35f95e27086af58 100644 (file)
@@ -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}")
index 0f10b8fe707ac092f6bde3cf1b11fe60d5b74b43..bf64e5edb67c0f27c63e752036e1608a079aca9d 100644 (file)
@@ -105,6 +105,7 @@ set(SRC
 )
 
 set(LIB
+ ${BOOST_LIBRARIES}
 )
 
 blender_add_lib(extern_quadriflow "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
index 1972a5fc94c652c1c3a339966bfb6d2d62f1df07..254fb5ecf192cd0e2516878e047d6fa6d5cf3a84 100644 (file)
@@ -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
index 09379bf2017a8f740bcec8113f3adba6e2da94b3..b6ecab28555cd4ca152a0e6e05810933ec146e96 100644 (file)
@@ -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()
 
index 27a7f604e1c2b5dddc0cbdf570cffba8d0655874..fb724704a84acdce6c9816cbd2022c83fad2f0cd 100644 (file)
@@ -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})
index 0efd8bb7ea8158ca110506b5635b0db0bfbc69ff..13328a8b6bf0a4ddcc569959643fcbf304a71053 100644 (file)
@@ -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()
index a8c4949ad075dc2b765a4e7c9ab3b7352ac22ee2..35a79356957820b7d24577128e5ef270090f881a 100644 (file)
@@ -60,7 +60,9 @@ set(SRC_HEADERS
 )
 
 set(LIB
-
+  cycles_render
+  cycles_kernel
+  cycles_util
 )
 
 if(WITH_CUDA_DYNLOAD)
index c6c4694159819d4e81041fcefaca1213cce94b37..9ff1c5b98c68942aa207967c5a12eb34aa1b7e6f 100644 (file)
@@ -17,7 +17,7 @@ set(SRC_HEADERS
 )
 
 set(LIB
-
+  cycles_util
 )
 
 include_directories(${INC})
index 35cca2da8ada3b954318e0e31d59b82cef00dfe4..5be5bd181ec48cb7cd404ab9df5046aedcac6570 100644 (file)
@@ -27,6 +27,10 @@ set(HEADER_SRC
 
 set(LIB
   cycles_render
+
+  ${OSL_LIBRARIES}
+  ${OPENIMAGEIO_LIBRARIES}
+  ${LLVM_LIBRARY}
 )
 
 include_directories(${INC})
index 53196b013f618a9b7453c00b6ce8401a2fb5695c..92578b888a6ca8fbd2d15804aaecb34a69e4f29d 100644 (file)
@@ -77,6 +77,9 @@ set(SRC_HEADERS
 
 set(LIB
   cycles_bvh
+  cycles_device
+  cycles_subd
+  cycles_util
 )
 
 if(WITH_CYCLES_OSL)
index ec2e84268bee6018f827ebf8c5d57598de7e256b..cc671e31f92d8f5e582d30a2e9a254d346f6352d 100644 (file)
@@ -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)
index e16e27368d06a3daadc9d2d5bdffba413ceaa0db..f587aee615b9831d15d295991093a0916d335628 100644 (file)
@@ -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(
index 08bdf491d3b53d014c67b863f1cbb2fde5e70c06..2601a2d6754d5515cf93b4ff4ad8a8489f345b02 100755 (executable)
@@ -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(
index 5c5da31482de24b7b26777355fc355183376e9de..732fa1e4d11987047caa8c3c6ac1c10ef035d618 100644 (file)
@@ -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()
index 9fdd8b59aca9bf985edaffd137fa64f2c2babea8..c7b3c56c3c23126621d406c4ae349491a6cd590a 100644 (file)
@@ -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}")
index 4d95c1b701b6ab19b371f2d8b6a8fc1a61bc8b02..d2336692d22b46052de0586c26a8d5ba91f6d6aa 100644 (file)
@@ -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)
index 69f4bad62b243ff85a5d081a1545f0fd965dd8a8..268b4e31d7dcf2307bb057105300dff42612f7f3 100644 (file)
@@ -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)
index fdc57d1a282bd03fe448c914c6f8f11ae2cc7b41..a681d723b9c4f8c60f313d7e043f64b33f9d4e0c 100644 (file)
@@ -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}")
index 35cfe22a018b6a4a30230e1afbf61878500c6dc5..5fe60f3eda208e62a78cd054f60f63beb0dbfb60 100644 (file)
@@ -36,6 +36,7 @@ set(SRC
 
 set(LIB
   extern_quadriflow
+  ${BOOST_LIBRARIES}
 )
 
 if(WIN32)
index cf9b70448e03f292b008c7f9c4a0e036be9da155..77d88548e1b7bc5a6157eebbd58c75011cc64d27 100644 (file)
@@ -33,6 +33,7 @@ set(SRC
 )
 
 set(LIB
+  ${BULLET_LIBRARIES}
 )
 
 blender_add_lib(bf_intern_rigidbody "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
index 82812fb81cfb05dbb8c6b3031f47e7ae32f4ad2f..4618246013a16dd7d3c1f041337ac81aaae67d93 100644 (file)
@@ -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}")
index 721905ec9d4d2ba8cbf42ccae2eaa488bd331bd0..eafb299944da02e1b42ecb1e7b08b975aa59f855 100644 (file)
@@ -47,6 +47,7 @@ set(SRC
 )
 
 set(LIB
+  ${JPEG_LIBRARIES}
 )
 
 blender_add_lib(bf_avi "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
index ba8697a44b6e121d91f685e26642c813c7638c0c..fa02d6d21c9026d29a2ae5d9bf46cc775593693d 100644 (file)
@@ -54,6 +54,8 @@ set(SRC
 set(LIB
   bf_gpu
   bf_intern_guardedalloc
+
+  ${FREETYPE_LIBRARY}
 )
 
 if(WIN32)
index 3db878ab95fb49f73b66c9800ad8bb04c5fad573..61aeb51a1971c9ec4f06ac5b850f906f467a038b 100644 (file)
@@ -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!
index f3740b5d39f0d1c314915bdb31ca46fa5ea16cbd..d22b1cd0ddb3e7b372c7c6604420fd7d0764cc1f 100644 (file)
@@ -261,6 +261,8 @@ set(LIB
   bf_intern_guardedalloc
   bf_intern_numaapi
   extern_wcwidth
+
+  ${FREETYPE_LIBRARY}
 )
 
 if(WITH_MEM_VALGRIND)
index 0361137f5b19a7f53d318a43ab2e523b6b9292d6..147c375aa6e60a08a321cd6338507dbe571deb91 100644 (file)
@@ -30,6 +30,7 @@ set(SRC
   msgfmt.c
 )
 
+setup_libdirs()
 add_cc_flags_custom_test(msgfmt)
 
 if(APPLE)
index 00954eb400c93c8cb2dba6542d6cbed0c92ca51e..35c33837d645e53f7c0845a27baebbc19b433c4b 100644 (file)
@@ -183,6 +183,8 @@ if(WITH_BULLET)
   )
   list(APPEND LIB
     extern_bullet
+
+    ${BULLET_LIBRARIES}
   )
   add_definitions(-DWITH_BULLET)
 endif()
index 40762db759eb7748f864167209e75dee77ca283e..a88fd05a18fce1f95d4df8d7b4b0d8fe793c1b91 100644 (file)
@@ -126,6 +126,9 @@ set(SRC
 )
 
 set(LIB
+  ${OPENCOLLADA_LIBRARIES}
+  ${PCRE_LIBRARIES}
+  ${XML2_LIBRARIES}
 )
 
 if(WITH_BUILDINFO)
index ed14397f73cca50e342f3e8763f9a397e9b6a704..8d609d545f87c5871ef44543a8a5dbc0da841804 100644 (file)
@@ -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}")
index 7f4b5a45aa369a007cd9fc7ed3e4757a97a8ca61..b4099edce68cd895441d120da6ea05da7655162b 100644 (file)
@@ -47,6 +47,9 @@ if(WITH_AUDASPACE)
   )
   list(APPEND LIB
     bf_intern_audaspace
+
+    ${AUDASPACE_C_LIBRARIES}
+    ${AUDASPACE_PY_LIBRARIES}
   )
   add_definitions(-DWITH_AUDASPACE)
 endif()
index f4d31886e3f8558e33ca29af6f0a956b524c1b79..8170c9209907664a4fd841465c47883d28478280 100644 (file)
@@ -56,6 +56,9 @@ if(WITH_AUDASPACE)
   )
   list(APPEND LIB
     bf_intern_audaspace
+
+    ${AUDASPACE_C_LIBRARIES}
+    ${AUDASPACE_PY_LIBRARIES}
   )
   add_definitions(-DWITH_AUDASPACE)
 endif()
index 84ded1dd2c777f0644066249cffd4f33b18f1d8f..da7d9e2a8f37bfd2021d42df28f8a0bc16ea1779 100644 (file)
@@ -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)
index ba5172c7916481cf0b810c66e73f993c16418ef5..8270476e9dd35ee8d0a3be1b793942cf06d051d4 100644 (file)
@@ -549,6 +549,9 @@ set(SRC
 
 set(LIB
   bf_python_mathutils
+
+  ${PYTHON_LINKFLAGS}
+  ${PYTHON_LIBRARIES}
 )
 
 set(INC
index 8daeda67c80a5d7519fdffaffafb51aacc837cd2..25f9ef886e9610055659bc01e16551cac147ec07 100644 (file)
@@ -129,6 +129,7 @@ set(SRC
 )
 
 set(LIB
+  ${BLENDER_GL_LIBRARIES}
 )
 
 if(NOT WITH_SYSTEM_GLEW)
index b8d43b8e9c2cc4d4639de99e2ba5d925a10c6003..7aab644fc12d5f33443f4c6c5bceb1f404796799 100644 (file)
@@ -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(
index 984e62bc75af1f7430804ee9667492e0f2825015..211b6a0b40e3697e963bad95ea3b68be7b8406dd 100644 (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()
 
index fc584ace81e0b6dc7e50e7345756fc2655d00a84..a84f31c7025dca32e7d4458d8a4ec5fad2a02d53 100644 (file)
@@ -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()
 
index 3082daa83a4f61b58e207f45cf2418a73f62938e..b2f1f6c651d5d481779c086c2d566848c58e2d3e 100644 (file)
@@ -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()
 
index 2eb2a6b380ac901df2ef066646cbfd0dbff2a116..e15eb5af2c43bd5a8026a0362ef173bf2938c4b0 100644 (file)
@@ -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()
 
index edcfdceb697b0b30b9c3d5955d0b54b64abae0c8..10520a185131899fd287145fc44ec547ea25dd4e 100644 (file)
@@ -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}")
index 3875057185a7ec37381df2a8fa1ee82645f13a12..818498fe7db82c549bea77414bc48b822f45f460 100644 (file)
@@ -55,6 +55,9 @@ set(LIB
   bf_blenkernel
   bf_blenlib
   bf_python_mathutils
+
+  ${PYTHON_LINKFLAGS}
+  ${PYTHON_LIBRARIES}
 )
 
 if(WITH_FREESTYLE)
index c878103e19dc2b82e8956975276182da280aea79..822f05bad90f07d62d1ce3835e6cee3c790dc8ed 100644 (file)
@@ -50,6 +50,8 @@ set(SRC
 
 set(LIB
   ${GLEW_LIBRARY}
+  ${PYTHON_LINKFLAGS}
+  ${PYTHON_LIBRARIES}
 )
 
 add_definitions(${GL_DEFINITIONS})
index ca0e6ced42bf9b7c08c188049453f5229b41daef..22a3d3a79de5165d5421fa6d3b768323cf44109a 100644 (file)
@@ -55,6 +55,8 @@ set(SRC
 )
 
 set(LIB
+  ${PYTHON_LINKFLAGS}
+  ${PYTHON_LIBRARIES}
 )
 
 add_definitions(${GL_DEFINITIONS})
index 012492fe9a7e40ea9d7303252067354931aa590b..adcda7106228058862e18c2a79c2c8cc46c5eaef 100644 (file)
@@ -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()
 
index cdb562a3233913832d34083078793889d7b877bb..e34432f0c5409bbec4ddb863a6627a0b5aabb5ed 100644 (file)
@@ -58,6 +58,9 @@ set(SRC
 set(LIB
   bf_blenlib
   bf_python_ext
+
+  ${PYTHON_LINKFLAGS}
+  ${PYTHON_LIBRARIES}
 )
 
 
index 12d281f643dfeaf0d2039c4fcef383392c8aa1bb..1d72593f8296374cb1d91dd20604818f4d3850b6 100644 (file)
@@ -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()
index ab87f81dba516438876f42807ed93877be12810b..73fbde4148ee02af64e7c00c1d1a1d250e550e78 100644 (file)
@@ -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()
 
index 57b1fb52022edc0388438d73822a23b651a50d52..f8b2c3730296601f0d2bb974e7347b2ecd11f40c 100644 (file)
@@ -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})
index 1f52886132f6a51ef4f5e09edd6dd49a86dba32a..c6b23615a5ae75f35a0ae93fe9eaa07fede7f466 100644 (file)
@@ -27,6 +27,7 @@ set(INC
   ../../../intern/atomic
 )
 
+setup_libdirs()
 include_directories(${INC})
 
 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}")
index 21bd2aba07fc74ac02fba3e924c24a1d06a5c54e..3850d279b3cf74864e94a9232e20d2a5d9a30129 100644 (file)
@@ -52,6 +52,9 @@ set(LIB
   bf_gpu
 
   bf_usd
+
+  ${BOOST_LIBRARIES}
+  ${TBB_LIBRARIES}
 )
 
 include_directories(${INC})