Skip to content

Commit

Permalink
[mdl] Add port MDL-SDK 2021.1.2 (#24633)
Browse files Browse the repository at this point in the history
* [mdl] Add port MDL-SDK 2020.0.1

* [mdl] Expose `dds` and `freeimage` features

* [mdl] Upgrade MDL-SDK 2020.1.2

* Update ports/mdl/portfile.cmake

Co-authored-by: Jack·Boos·Yu <47264268+JackBoosY@users.noreply.github.com>

* [mdl] simplify patch 001-freeimage-from-vcpkg.patch

* [mdl] improve and simplify patch 003-install-rules.patch

* [mdl] enable dependency log for better debugging in case of failure

* [mdl] expose interface include directions for mdl core & mdl sdk

* [mdl] build clang as part of vendored LLVM

* [mdl] remove unnecessary export

* [mdl] Use `unofficial::` namespace prefix

* [mdl] remove unnecessary checks about clang CMake target

* [mdl] `vcpkg_extract_source_archive` -> `vcpkg_extract_source_archive_ex`

* [mdl] Use `vcpkg_find_acquire_program(CLANG7)`

* [mdl] disable osx arm64

* [mdl] add license

cf. https://developer.nvidia.com/nvidia-mdl-sdk-get-started

* [mdl] Use `vcpkg-tool-clang7`

* [mdl] restrict arm build

* [vcpkg-tool-clang7] Fix broken symlink on UNIX platform

* [mdl] Revert changes in `vckpg_find_acquire_program`

* [mdl] Rely on `vcpkg-tool-clang7` `vcpkg-port-config.cmake`

* [mdl] No support for x86 nor static CRT (because of dynamic linkage only)

* Mark Windows static linkage ports as fail due to freeimage requirement

* [mdl] Restrict static on Windows

* [mdl] remove leftover patch

* [vcpkg-tool-clang7] patch cleanup

* Commit suggestion.

* Versions

* [mdl] include priority to vendored LLVM

* [mdl] path in quotes

* [mdl] update 001-freeimage-from-vcpkg.patch with comments

* [mdl] Download clang 7 prior to build MDL-SDK

* Fix incorrect clang path for UNIX

* [mdl] portfile cleanup

* Apply code review suggestions

* Update ports/mdl/portfile.cmake

Co-authored-by: Victor Romero <romerosanchezv@gmail.com>

* bump version

* Address review comments

* mdl -> mdl-sdk

* minimize 006-guard-nonexisting-targets.patch

* minimize 002-install-rules.patch

* Notes in portfile about clang 7 usage

* Add CMAKE_DISABLE_FIND_PACKAGE-<PACKAGE_NAME> to disable optional packages

* Address comments

Co-authored-by: Jack·Boos·Yu <47264268+JackBoosY@users.noreply.github.com>
Co-authored-by: Victor Romero <romerosanchezv@gmail.com>
  • Loading branch information
3 people committed Oct 13, 2022
1 parent d8e60ef commit e2aa9d1
Show file tree
Hide file tree
Showing 14 changed files with 627 additions and 0 deletions.
68 changes: 68 additions & 0 deletions ports/mdl-sdk/001-freeimage-from-vcpkg.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
diff --git a/cmake/dependencies/add_freeimage.cmake b/cmake/dependencies/add_freeimage.cmake
index 944d452..3916352 100644
--- a/cmake/dependencies/add_freeimage.cmake
+++ b/cmake/dependencies/add_freeimage.cmake
@@ -67,13 +67,4 @@ else()
)
endif()
endif()
-
- # copy runtime dependencies
- # copy system libraries only on windows, we assume the libraries are installed in a unix environment
- if(NOT __TARGET_ADD_DEPENDENCY_NO_RUNTIME_COPY AND WINDOWS)
- target_copy_to_output_dir(TARGET ${__TARGET_ADD_DEPENDENCY_TARGET}
- FILES
- ${MDL_DEPENDENCY_FREEIMAGE_SHARED}
- )
- endif()
endif()
diff --git a/cmake/find/find_freeimage_ext.cmake b/cmake/find/find_freeimage_ext.cmake
index b11573a..703458e 100644
--- a/cmake/find/find_freeimage_ext.cmake
+++ b/cmake/find/find_freeimage_ext.cmake
@@ -28,6 +28,9 @@

function(FIND_FREEIMAGE_EXT)

+ find_package(freeimage CONFIG REQUIRED)
+ if(0)
+
set(FREEIMAGE_DIR "NOT-SPECIFIED" CACHE PATH "Directory that contains the freeimage library and the corresponding headers.")
#-----------------------------------------------------------------------------------------------

@@ -90,6 +93,35 @@ function(FIND_FREEIMAGE_EXT)
endif()
endif()

+ else()
+ get_target_property(_FREEIMAGE_INCLUDE freeimage::FreeImage INTERFACE_INCLUDE_DIRECTORIES)
+ get_target_property(_FREEIMAGE_DEPENDENCIES freeimage::FreeImage INTERFACE_LINK_LIBRARIES )
+
+ get_target_property(_FREEIMAGE_SHARED freeimage::FreeImage IMPORTED_LOCATION)
+ if(NOT _FREEIMAGE_SHARED)
+ get_target_property(_FREEIMAGE_SHARED freeimage::FreeImage IMPORTED_LOCATION_RELEASE)
+ endif()
+ if(NOT _FREEIMAGE_SHARED)
+ get_target_property(_FREEIMAGE_SHARED freeimage::FreeImage IMPORTED_LOCATION_DEBUG)
+ endif()
+
+ get_target_property(_FREEIMAGE_TYPE freeimage::FreeImage TYPE)
+ if(${_FREEIMAGE_TYPE} STREQUAL "SHARED_LIBRARY")
+ get_target_property(_FREEIMAGE_LIB freeimage::FreeImage IMPORTED_IMPLIB)
+ if(NOT _FREEIMAGE_LIB)
+ get_target_property(_FREEIMAGE_LIB freeimage::FreeImage IMPORTED_IMPLIB_RELEASE)
+ endif()
+ if(NOT _FREEIMAGE_LIB)
+ get_target_property(_FREEIMAGE_LIB freeimage::FreeImage IMPORTED_IMPLIB_DEBUG)
+ endif()
+ endif()
+
+ find_file(_FREEIMAGE_HEADER_FILE "FreeImage.h"
+ HINTS
+ ${_FREEIMAGE_INCLUDE}
+ )
+ endif()
+
# error if dependencies can not be resolved
if(NOT EXISTS ${_FREEIMAGE_INCLUDE} OR (WINDOWS AND NOT EXISTS ${_FREEIMAGE_LIB}) OR NOT EXISTS ${_FREEIMAGE_SHARED})
message(STATUS "FREEIMAGE_DIR: ${FREEIMAGE_DIR}")
171 changes: 171 additions & 0 deletions ports/mdl-sdk/002-install-rules.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1f1902c..623bec8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -53,6 +53,9 @@ option(MDL_LOG_FILE_DEPENDENCIES "Prints the list of files that is copied after
set(MDL_ADDITIONAL_COMPILER_DEFINES "MDL_SOURCE_RELEASE" CACHE STRING "Additional compile defines that are passed to each of the projects")
set(MDL_ADDITIONAL_COMPILER_OPTIONS "" CACHE STRING "Additional compile options that are passed to each of the projects")

+include(GNUInstallDirs)
+include(CMakePackageConfigHelpers)
+
# set the default installation path
if(NOT DEFINED CMAKE_INSTALL_PREFIX OR CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "..." FORCE)
@@ -235,3 +238,35 @@ foreach(_TEST_POST ${MDL_TEST_LIST_POST})
add_subdirectory(${_TEST_POST})
endforeach()

+# Config
+#--------------------------------------------------------------------------------------------------
+
+set(PATH_EXPORT_TARGETS "${CMAKE_INSTALL_DATADIR}/unofficial-mdl/unofficial-mdl-targets.cmake")
+configure_package_config_file(
+ "${CMAKE_CURRENT_SOURCE_DIR}/unofficial-mdl-config.cmake.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/unofficial-mdl-config.cmake"
+ PATH_VARS
+ PATH_EXPORT_TARGETS
+ INSTALL_DESTINATION ${CMAKE_INSTALL_DATADIR}/unofficial-mdl
+)
+
+write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/unofficial-mdl-config-version.cmake"
+ VERSION 2021.0.1
+ COMPATIBILITY SameMajorVersion
+)
+
+# Install
+#--------------------------------------------------------------------------------------------------
+
+install(
+ EXPORT unofficial-mdl-targets
+ NAMESPACE "unofficial::mdl::"
+ DESTINATION "${CMAKE_INSTALL_DATADIR}/unofficial-mdl"
+)
+
+install(
+ FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/unofficial-mdl-config.cmake
+ ${CMAKE_CURRENT_BINARY_DIR}/unofficial-mdl-config-version.cmake
+ DESTINATION "${CMAKE_INSTALL_DATADIR}/unofficial-mdl"
+)
diff --git a/cmake/utilities.cmake b/cmake/utilities.cmake
index 5e9774f..51dc65c 100644
--- a/cmake/utilities.cmake
+++ b/cmake/utilities.cmake
@@ -705,6 +705,7 @@ function(CREATE_FROM_BASE_PRESET)
# adjust output file name if requested
if(CREATE_FROM_BASE_PRESET_OUTPUT_NAME)
set_target_properties(${CREATE_FROM_BASE_PRESET_TARGET} PROPERTIES OUTPUT_NAME ${CREATE_FROM_BASE_PRESET_OUTPUT_NAME})
+ set_target_properties(${CREATE_FROM_BASE_PRESET_TARGET} PROPERTIES EXPORT_NAME ${CREATE_FROM_BASE_PRESET_OUTPUT_NAME})
endif()

# log message
@@ -1143,6 +1144,15 @@ endfunction()
# -------------------------------------------------------------------------------------------------
# basic install logic to copy the entire output folder

+set(_MDL_PROD_TARGETS
+ prod-lib-mdl_core
+ prod-lib-mdl_sdk
+ prod-bin-i18n
+ prod-bin-mdlc
+ prod-bin-mdlm
+ shaders-plugin-dds
+ shaders-plugin-freeimage
+)
function(ADD_TARGET_INSTALL)
set(options)
set(oneValueArgs TARGET DESTINATION)
@@ -1152,6 +1162,14 @@ function(ADD_TARGET_INSTALL)
# - ADD_TARGET_INSTALL_TARGET
# - ADD_TARGET_INSTALL_DESTINATION

+ if(${ADD_TARGET_INSTALL_TARGET} IN_LIST _MDL_PROD_TARGETS)
+ install(
+ TARGETS ${ADD_TARGET_INSTALL_TARGET}
+ EXPORT unofficial-mdl-targets
+ )
+ return()
+ endif()
+
install(DIRECTORY $<TARGET_FILE_DIR:${ADD_TARGET_INSTALL_TARGET}>/
DESTINATION ${ADD_TARGET_INSTALL_DESTINATION}
USE_SOURCE_PERMISSIONS

diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index 246303d..28934b4 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -229,3 +229,8 @@ source_group("base" FILES ${PROJECT_HEADERS_BASE})
source_group("math" FILES ${PROJECT_HEADERS_MATH})
source_group("mdl" FILES ${PROJECT_HEADERS_MDL})
source_group("neuraylib" FILES ${PROJECT_HEADERS_NEURAYLIB})
+
+install(
+ DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/mi"
+ TYPE INCLUDE
+)
diff --git a/src/prod/lib/mdl_core/CMakeLists.txt b/src/prod/lib/mdl_core/CMakeLists.txt
index b60a1fc..3c3d2f4 100644
--- a/src/prod/lib/mdl_core/CMakeLists.txt
+++ b/src/prod/lib/mdl_core/CMakeLists.txt
@@ -42,9 +42,15 @@ create_from_base_preset(
EMBED_RC "mdl_core.rc"
)

+target_include_directories(${PROJECT_NAME}
+ PUBLIC
+ $<INSTALL_INTERFACE:include>
+)
+
# customize name
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "lib")
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "mdl_core")
+set_target_properties(${PROJECT_NAME} PROPERTIES EXPORT_NAME "mdl_core")

if(MACOSX)
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".so") # corresponding to the binary release
diff --git a/src/prod/lib/mdl_sdk/CMakeLists.txt b/src/prod/lib/mdl_sdk/CMakeLists.txt
index 6ddfc24..51c84e7 100644
--- a/src/prod/lib/mdl_sdk/CMakeLists.txt
+++ b/src/prod/lib/mdl_sdk/CMakeLists.txt
@@ -44,9 +44,15 @@ create_from_base_preset(
EMBED_RC "mdl_sdk.rc"
)

+target_include_directories(${PROJECT_NAME}
+ PUBLIC
+ $<INSTALL_INTERFACE:include>
+)
+
# customize name
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "lib")
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "mdl_sdk")
+set_target_properties(${PROJECT_NAME} PROPERTIES EXPORT_NAME "mdl_sdk")

if(MACOSX)
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".so") # corresponding to the binary release
diff --git a/src/shaders/plugin/dds/CMakeLists.txt b/src/shaders/plugin/dds/CMakeLists.txt
index 81558b0..179e1df 100644
--- a/src/shaders/plugin/dds/CMakeLists.txt
+++ b/src/shaders/plugin/dds/CMakeLists.txt
@@ -65,6 +65,7 @@ create_from_base_preset(
# customize name
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "dds")
+set_target_properties(${PROJECT_NAME} PROPERTIES EXPORT_NAME "dds")

if(MACOSX)
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".so") # corresponding to the binary release
diff --git a/src/shaders/plugin/freeimage/CMakeLists.txt b/src/shaders/plugin/freeimage/CMakeLists.txt
index b3ae039..a28b50e 100644
--- a/src/shaders/plugin/freeimage/CMakeLists.txt
+++ b/src/shaders/plugin/freeimage/CMakeLists.txt
@@ -56,6 +56,7 @@ create_from_base_preset(
# customize name
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "nv_freeimage")
+set_target_properties(${PROJECT_NAME} PROPERTIES EXPORT_NAME "nv_freeimage")

if(MACOSX)
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".so") # corresponding to the binary release
13 changes: 13 additions & 0 deletions ports/mdl-sdk/003-freeimage-disable-faxg3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/shaders/plugin/freeimage/freeimage_image_plugin_impl.cpp b/src/shaders/plugin/freeimage/freeimage_image_plugin_impl.cpp
index ff79628..f22d05b 100644
--- a/src/shaders/plugin/freeimage/freeimage_image_plugin_impl.cpp
+++ b/src/shaders/plugin/freeimage/freeimage_image_plugin_impl.cpp
@@ -270,7 +270,7 @@ Plugin_description g_plugin_list[] = {
Plugin_description( "fi_cut" , FIF_CUT ),
Plugin_description( "fi_dds" , FIF_DDS ),
Plugin_description( "fi_exr" , FIF_EXR ),
- Plugin_description( "fi_faxg3" , FIF_FAXG3 ),
+ // Plugin_description( "fi_faxg3" , FIF_FAXG3 ), # not shipped with vcpkg
Plugin_description( "fi_gif" , FIF_GIF ),
Plugin_description( "fi_hdr" , FIF_HDR ),
Plugin_description( "fi_ico" , FIF_ICO ),
36 changes: 36 additions & 0 deletions ports/mdl-sdk/004-missing-std-includes.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
diff --git a/src/api/api/neuray/neuray_class_factory.h b/src/api/api/neuray/neuray_class_factory.h
index b8b5b55..c226458 100644
--- a/src/api/api/neuray/neuray_class_factory.h
+++ b/src/api/api/neuray/neuray_class_factory.h
@@ -40,6 +40,7 @@

#include <map>
#include <string>
+#include <vector>

#include <boost/core/noncopyable.hpp>
#include <base/data/serial/i_serial_classid.h>
diff --git a/src/api/api/neuray/neuray_mdl_resource_callback.h b/src/api/api/neuray/neuray_mdl_resource_callback.h
index 5439cfb..cd803fa 100644
--- a/src/api/api/neuray/neuray_mdl_resource_callback.h
+++ b/src/api/api/neuray/neuray_mdl_resource_callback.h
@@ -35,6 +35,7 @@

#include <string>
#include <map>
+#include <vector>

#include <mi/base/handle.h>
#include <mi/mdl/mdl_printers.h>
diff --git a/src/base/util/registry/config_registry_impl.cpp b/src/base/util/registry/config_registry_impl.cpp
index 01ad0c1..dd089ec 100644
--- a/src/base/util/registry/config_registry_impl.cpp
+++ b/src/base/util/registry/config_registry_impl.cpp
@@ -37,6 +37,7 @@
#include <cctype>
#include <ostream>
#include <vector>
+#include <algorithm>

namespace MI {
namespace CONFIG {
15 changes: 15 additions & 0 deletions ports/mdl-sdk/005-missing-link-windows-crypt-libraries.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/src/io/scene/CMakeLists.txt b/src/io/scene/CMakeLists.txt
index 5a0a1c6..37a0a19 100644
--- a/src/io/scene/CMakeLists.txt
+++ b/src/io/scene/CMakeLists.txt
@@ -104,5 +104,10 @@ target_add_dependencies(TARGET ${PROJECT_NAME}
boost
)

+target_compile_definitions(${PROJECT_NAME}
+ PRIVATE
+ BOOST_UUID_FORCE_AUTO_LINK # for some reason this is not working while using vcpkg boost-uuid
+)
+
# add tests if available
add_tests(POST)
38 changes: 38 additions & 0 deletions ports/mdl-sdk/006-guard-nonexisting-targets.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
diff --git a/src/mdl/jit/llvm/CMakeLists.txt b/src/mdl/jit/llvm/CMakeLists.txt
index 70f7f50..13857be 100644
--- a/src/mdl/jit/llvm/CMakeLists.txt
+++ b/src/mdl/jit/llvm/CMakeLists.txt
@@ -289,11 +289,16 @@ endforeach()

# -------------------------------------------------------------------------------------------------
# set options for all other projects that are build in addition to the libs we need
-set(ADDITIONAL_LLVM_TARGETS
- obj.llvm-tblgen
- llvm-tblgen
+set(ADDITIONAL_LLVM_TARGETS
+ llvm-tblgen
)

+
+# LLVM_ENABLE_OBJLIB cf. dist\cmake\modules\TableGen.cmake:125
+if(NOT (CMAKE_GENERATOR STREQUAL "Ninja" AND NOT CMAKE_VERSION VERSION_LESS 3.9) AND NOT XCODE)
+ list(APPEND ADDITIONAL_LLVM_TARGETS obj.llvm-tblgen)
+endif()
+
foreach(_ADD_LLVM ${ADDITIONAL_LLVM_TARGETS})
message(STATUS "setting flags for ${_ADD_LLVM}")
llvm_target_setup(TARGET ${_ADD_LLVM})
@@ -360,9 +365,10 @@ if(WINDOWS)
)
endif()

- set(_LLVM_EXCLUDE ${_LLVM_EXCLUDE}
- LLVMVisualizers
- )
+ # LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION cf. dist\CMakeLists.txt:559
+ if (MSVC_IDE AND NOT (MSVC_VERSION LESS 1900))
+ list(APPEND _LLVM_EXCLUDE LLVMVisualizers)
+ endif()
endif()


48 changes: 48 additions & 0 deletions ports/mdl-sdk/007-plugin-options.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index def8fce..33dc3de 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -47,6 +47,8 @@ set(MDL_EXAMPLES_FOLDER ${CMAKE_SOURCE_DIR}/examples CACHE PATH "The folder that
option(MDL_BUILD_SDK_EXAMPLES "Adds MDL SDK examples to the build." ON)
option(MDL_BUILD_CORE_EXAMPLES "Adds MDL Core examples to the build." ON)
option(MDL_BUILD_ARNOLD_PLUGIN "Enable the build of the MDL Arnold plugin." OFF)
+option(MDL_BUILD_DDS_PLUGIN "Enable the build of the MDL DDS image plugin." ON)
+option(MDL_BUILD_FREEIMAGE_PLUGIN "Enable the build of the MDL Freeimage image plugin." ON)
option(MDL_LOG_PLATFORM_INFOS "Prints some infos about the current build system (relevant for error reports)." ON)
option(MDL_LOG_DEPENDENCIES "Prints the list of dependencies during the generation step." OFF)
option(MDL_LOG_FILE_DEPENDENCIES "Prints the list of files that is copied after a successful build." OFF)
@@ -148,8 +150,12 @@ add_subdirectory(${MDL_SRC_FOLDER}/prod/bin/mdlm)

# PLUGINS
#--------------------------------------------------------------------------------------------------
-add_subdirectory(${MDL_SRC_FOLDER}/shaders/plugin/dds)
-add_subdirectory(${MDL_SRC_FOLDER}/shaders/plugin/freeimage)
+if(MDL_BUILD_DDS_PLUGIN)
+ add_subdirectory(${MDL_SRC_FOLDER}/shaders/plugin/dds)
+endif()
+if(MDL_BUILD_FREEIMAGE_PLUGIN)
+ add_subdirectory(${MDL_SRC_FOLDER}/shaders/plugin/freeimage)
+endif()

# EXAMPLES
#--------------------------------------------------------------------------------------------------
diff --git a/cmake/utilities.cmake b/cmake/utilities.cmake
index ecdb672..74f54e0 100644
--- a/cmake/utilities.cmake
+++ b/cmake/utilities.cmake
@@ -1148,9 +1148,13 @@ set(_MDL_PROD_TARGETS
prod-bin-i18n
prod-bin-mdlc
prod-bin-mdlm
- shaders-plugin-dds
- shaders-plugin-freeimage
)
+if(MDL_BUILD_DDS_PLUGIN)
+ list(APPEND _MDL_PROD_TARGETS shaders-plugin-dds)
+endif()
+if(MDL_BUILD_FREEIMAGE_PLUGIN)
+ list(APPEND _MDL_PROD_TARGETS shaders-plugin-freeimage)
+endif()
function(ADD_TARGET_INSTALL)
set(options)
set(oneValueArgs TARGET DESTINATION)
Loading

0 comments on commit e2aa9d1

Please sign in to comment.