Issues found when trying to get OIIO working as a static library on Windows #3611
DominikGrabiec
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I wanted a public place to write down and discuss the list of issues that I've found while trying to get OIIO building as a static library on Windows and linking it into another executable / dynamic library. I've got fixes for some of these issues but I'm not sure if any single change is the right way to go about it given the history of the project and other platforms and configurations it's used in.
Some advice, guidance, and hints would be appreciated.
I've used the guide that @aras-p has made but I've installed the dependencies with
vcpkg
to the global location, and reduced the initial CMake command to:cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static-md -DCMAKE_TOOLCHAIN_FILE=E:\vcpkg\scripts\buildsystems\vcpkg.cmake -DBUILD_SHARED_LIBS=OFF -DLINKSTATIC=ON -DVERBOSE=ON -DBUILD_DOCS=OFF -DINSTALL_DOCS=OFF -DBUILD_TESTING=OFF -DOIIO_BUILD_TOOLS=OFF -DOIIO_BUILD_TESTS=OFF -DUSE_PYTHON=OFF -DUSE_QT=OFF -DBoost_USE_STATIC_LIBS=ON ..
Which I end up running in thebuild
directory.This creates for me a Visual Studio solution for which I can build the static OpenImageIO libraries and install them to the
dist
directory, then point my test exexutable project at it by using-DOpenImageIO_DIR=<OIIO_ROOT>\dist\lib\cmake\OpenImageIO
. The test executable just prints out the supported extensions for image loading in OIIO.These are the issues I've encountered while generating the VS solution and building both the OpenImageIO libraries and the text executables.
OIIO_BUILD_TESTS=ON
with thex64-windows-static
triplet is broken due to a VC runtime mismatch between the OIIO static library (uses static runtime) and the test executables (uses dynamic runtime). The CMake fix for this would be to put in some generator expressions to change the runtime type, but much easier fixes are to either use thex64-windows-static-md
community triplet forvcpkg
, or to turn building tests off instead withOIIO_BUILD_TESTS=OFF
.find_package(OpenEXR)
into the project beforefind_package(OpenImageIO)
otherwise CMake exits with errors. I have a change (DominikGrabiec@a4382d4) which fixes this for me but I'm not sure if it's good as I don't know OpenEXR and how it's used at all.USE_STD_FILESYSTEM
on Windows is broken with MSVC because it requires at least C++17 where as OIIO specifies a minimum of C++14. To make this option work we would need to require C++17 ifUSE_STD_FILESYSTEM
is switched on, and I don't know how that will play out with other dependencies and projects.USE_QT=OFF
is used there is a warning that theQt5
library was not found, This is not a fatal error but just looks odd and can be worked around by also specifyingUSE_QT5=OFF
to prevent the call tochecked_find_package(Qt5)
from emitting the warning. I've got a fix for that in DominikGrabiec@f1603fdALWAYS_PREFER_CONFIG
option inchecked_find_package
is broken for a number of reasons but one of them is that when using theFindOpenEXR
module it definesOPENEXR_VERSION
but when using the config version it only hasOpenEXR_VERSION
and therefore it ends up usingIMath
version 2. This fix can be as simple as usingOpenEXR_VERSION
when deciding which version of IMath to use but I'm not sure if the old styleOPENEXR_VERSION
is used anywhere else.libheif
library has a dependency onlibde265
which it does seem to set up correctly for transitive linking but OIIO doesn't use it correctly. I tried to fix it by adding aif(LINKSTATIC)
section to theFindLibheif.cmake
module and do different forms offind_package
there forlibde265
but I couldn't get it to work. The actual fix to make it work came from the vcpkg patches (https://github.com/microsoft/vcpkg/tree/master/ports/openimageio) and I've made a more targetted change in DominikGrabiec@cd6e13dGIF
(presumably fromgiflib
),webp
, andbz2
dependencies end up generating full absolute paths in theOpenImageIOTargets.cmake
file that gets generated on install. This may be minor but it does prevent the library from being relocatable ala [BUG] Generated CMake config files contain absolute paths #2559GIF
andwebp
dependencies end up only finding the debug version of the library so that gets linked into all configurations. I think this was also happening withlibheif
before the change that I made to make it link. My guess is that this is because the CMakefind_XXX
call ends up searching the vcpkg debug install directory first and just uses that. While thebz2
library also includes full paths for its libraries it does have them split up into optimised and debug versions.$<TARGET_NAME_IF_EXISTS:Boost::****>
evaluating to empty for some reason. My simple fix is to go back to linkinglibOpenImageIO
andlibutil
with${Boost_LIBRARIES}
as it used to be but that does generate absolute paths inOpenImageIOTargets.cmake
(See DominikGrabiec@ef3483f)Beta Was this translation helpful? Give feedback.
All reactions