Skip to content

Commit

Permalink
Remove vcpkg.cmake and add expat.cmake for OCIO (Windows Only) (Acade…
Browse files Browse the repository at this point in the history
…mySoftwareFoundation#577)

### Remove vcpkg.cmake and add expat.cmake for OCIO

### Linked issues
n/a

### Summarize your change.
Remove `vcpkg.cmake` and add an `expat.cmake` to build Expat for OCIO

### Describe the reason for the change.
By adding `expat.cmake,` it respect the same build structure as the
other dependencies.

### Describe what you have tested and on which operating system.
Windows

---------

Signed-off-by: Cédrik Fuoco <[email protected]>
  • Loading branch information
cedrik-fuoco-adsk authored Sep 19, 2024
1 parent e78feb8 commit f9e45c7
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 36 deletions.
2 changes: 1 addition & 1 deletion cmake/dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ IF(NOT EXISTS "${PROJECT_SOURCE_DIR}/src/pub/CMakeLists.txt")
ENDIF()

IF(RV_TARGET_WINDOWS)
INCLUDE(vcpkg)
INCLUDE(expat)
ENDIF()
INCLUDE(qt5)
INCLUDE(openssl) # Python3 requirement
Expand Down
88 changes: 88 additions & 0 deletions cmake/dependencies/expat.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#
# Copyright (C) 2024 Autodesk, Inc. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

#
# Official source repository https://github.com/libexpat/libexpat
#

INCLUDE(ProcessorCount) # require CMake 3.15+
PROCESSORCOUNT(_cpu_count)

RV_CREATE_STANDARD_DEPS_VARIABLES("RV_DEPS_EXPAT" "2.6.3" "" "")
RV_SHOW_STANDARD_DEPS_VARIABLES()


string(REPLACE "." "_" _version_underscored ${_version})
SET(_download_url
"https://github.com/libexpat/libexpat/archive/refs/tags/R_${_version_underscored}.tar.gz"
)

SET(_download_hash
"985086e206a01e652ca460eb069e4780"
)

SET(_libexpat_lib_version
"2.6.3"
)

RV_MAKE_STANDARD_LIB_NAME("libexpat" "" "SHARED" "d")

# Remove the -S argument from _configure_options, and adjust the path for Expat.
list(REMOVE_ITEM _configure_options "-S ${_source_dir}")
# Expat source is under expat folder and not directly under repository root.
LIST(APPEND _configure_options "-S ${_source_dir}/expat")

LIST(APPEND _configure_options "-DEXPAT_BUILD_DOCS=OFF")
LIST(APPEND _configure_options "-DEXPAT_BUILD_EXAMPLES=OFF")
LIST(APPEND _configure_options "-DEXPAT_BUILD_TESTS=OFF")
LIST(APPEND _configure_options "-DEXPAT_BUILD_TOOLS=OFF")

EXTERNALPROJECT_ADD(
${_target}
URL ${_download_url}
URL_MD5 ${_download_hash}
DOWNLOAD_NAME ${_target}_${_version}.tar.gz
DOWNLOAD_DIR ${RV_DEPS_DOWNLOAD_DIR}
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
SOURCE_DIR ${_source_dir}
BINARY_DIR ${_build_dir}
INSTALL_DIR ${_install_dir}
CONFIGURE_COMMAND ${CMAKE_COMMAND} ${_configure_options}
BUILD_COMMAND ${_cmake_build_command}
INSTALL_COMMAND ${_cmake_install_command}
BUILD_IN_SOURCE FALSE
BUILD_ALWAYS FALSE
BUILD_BYPRODUCTS ${_byproducts}
USES_TERMINAL_BUILD TRUE
)

RV_COPY_LIB_BIN_FOLDERS()

ADD_DEPENDENCIES(dependencies ${_target}-stage-target)

ADD_LIBRARY(EXPAT::EXPAT SHARED IMPORTED GLOBAL)
ADD_DEPENDENCIES(EXPAT::EXPAT ${_target})

# An import library (.lib) file is often used to resolve references to
# functions and variables in a DLL, enabling the linker to generate code
# for loading the DLL and calling its functions at runtime.
SET_PROPERTY(
TARGET EXPAT::EXPAT
PROPERTY IMPORTED_LOCATION "${_libpath}"
)
SET_PROPERTY(
TARGET EXPAT::EXPAT
PROPERTY IMPORTED_IMPLIB "${_implibpath}"
)

# It is required to force directory creation at configure time otherwise CMake complains about importing a non-existing path
FILE(MAKE_DIRECTORY "${_include_dir}")
TARGET_INCLUDE_DIRECTORIES(
EXPAT::EXPAT
INTERFACE ${_include_dir}
)

LIST(APPEND RV_DEPS_LIST EXPAT::EXPAT)
37 changes: 2 additions & 35 deletions cmake/dependencies/ocio.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@ ELSE() # Windows
FILE(REMOVE ${_backup_pyopencolorio_cmakelists_path})
ENDIF()

GET_TARGET_PROPERTY(_vcpkg_location VCPKG::VCPKG IMPORTED_LOCATION)
GET_FILENAME_COMPONENT(_vcpkg_path ${_vcpkg_location} DIRECTORY)

# Some options are not multi-platform so we start clean.
SET(_configure_options
""
Expand All @@ -215,8 +212,7 @@ ELSE() # Windows
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-DZLIB_LIBRARY=${_zlib_library}"
"-DZLIB_INCLUDE_DIR=${_zlib_include_dir}"
# Using the expat build with /MD to match the CRT.
"-Dexpat_DIR=${_vcpkg_path}/packages/expat_x64-windows-static-md/share/expat"
"-Dexpat_ROOT=${RV_DEPS_EXPAT_ROOT_DIR}"
"-DImath_DIR=${RV_DEPS_IMATH_ROOT_DIR}/lib/cmake/Imath"
"-DPython_ROOT=${RV_DEPS_BASE_DIR}/RV_DEPS_PYTHON3/install"
# Mandatory param: OCIO CMake code finds Python.
Expand Down Expand Up @@ -264,7 +260,7 @@ ELSE() # Windows
SOURCE_DIR ${_source_dir}
BINARY_DIR ${_build_dir}
INSTALL_DIR ${_install_dir}
DEPENDS Boost::headers RV_DEPS_PYTHON3 Imath::Imath VCPKG::VCPKG ZLIB::ZLIB
DEPENDS Boost::headers RV_DEPS_PYTHON3 Imath::Imath ZLIB::ZLIB EXPAT::EXPAT
PATCH_COMMAND
python3 ${_pyopencolorio_patch_script_path} ${_pyopencolorio_cmakelists_path}
CONFIGURE_COMMAND ${CMAKE_COMMAND} ${_configure_options}
Expand All @@ -275,35 +271,6 @@ ELSE() # Windows
BUILD_BYPRODUCTS ${_byproducts}
USES_TERMINAL_BUILD TRUE
)

# To update the baseline property in the OCIO VCPKG JSON:
# See https://learn.microsoft.com/en-us/vcpkg/users/versioning#baselines
# vcpkg x-update-baseline
# Caveat: the file must be called vcpkg.json to work.
# Workaround: change ocio_vcpkg.json to vcpkg.json, update the baseline, and rename it back.
SET(_vcpkg_manifest
"${RV_PKGMANCONFIG_DIR}/ocio_vcpkg.json"
)
EXTERNALPROJECT_ADD_STEP(
${_target} add_vcpkg_manifest
COMMENT "Copying the VCPKG manifest"
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_vcpkg_manifest} "${_source_dir}/vcpkg.json"
DEPENDERS configure
)

EXTERNALPROJECT_ADD_STEP(
${_target} install_vcpkg_manifest
COMMENT "Installing OCIO dependencies via VCPKG"
# IMPORTANT: VCPKG Manifest mode (using a .json) does not support differents triplets per dependencies.
# This is not a problem right now because only expat is installed with vcpkg.
# Expat is installed with vcpkg because there's an expat library that comes with MSYS2 on Windows,
# and it is causing compiler error.
# OCIO installs the remaining dependencies (yaml-cpp, pystring, pybind11 and minizip-ng).
COMMAND ${_vcpkg_location} install --triplet x64-windows-static-md
DEPENDEES add_vcpkg_manifest
DEPENDERS configure
WORKING_DIRECTORY "${_source_dir}"
)
ENDIF()

SET(_ocio_stage_plugins_python_dir "${RV_STAGE_PLUGINS_PYTHON_DIR}")
Expand Down

0 comments on commit f9e45c7

Please sign in to comment.