Skip to content

fix FindOpenEXR to respect OPENEXR_ROOT#15159

Merged
opencv-pushbot merged 1 commit intoopencv:3.4from
SSE4:fix_find_openexr
Nov 6, 2019
Merged

fix FindOpenEXR to respect OPENEXR_ROOT#15159
opencv-pushbot merged 1 commit intoopencv:3.4from
SSE4:fix_find_openexr

Conversation

@SSE4
Copy link
Copy Markdown
Contributor

@SSE4 SSE4 commented Jul 26, 2019

resolves #13403

This pullrequest changes

  • if CMake variable OPENEXR_ROOT is set, it has the top priority, so user-supplied OpenEXR version always wins against system-provided or one provided by OpenCV itself
  • do not try to override user-specified OPENEXR_ROOT to hard-coded paths (like C:\deploy)
  • OpenEXR libraries may use various versioning schemes, depending on compiler or configuration (debug vs release, static vs shared, etc.) for instance, Half library may have the following names in OpenEXR 2.3: Half-2_3 Half-2_3_s Half-2_3_d Half-2_3_s_d Half Half_s Half_d Half_s_d
  • parse OpenEXRConfig.h to find OpenEXR version number in order to know versioned library names

changes above basically allow to find OpenEXR supplied by various package managers (e.g. conan, vcpkg, hunter, cget, cppan, brew, etc.)

@SSE4 SSE4 force-pushed the fix_find_openexr branch from 2ae13cd to 166b8a3 Compare July 26, 2019 11:53
Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra validation checks are required:

  • base directory for includes/libraries/etc should be "the same". Case with libraries from /usr/lib and includes from /opt/local/include is wrong (due missing system's "-dev" package).
  • the same note is about suffixes like _s_d. All libraries should have the same build configuration.

Perhaps it make sense to wrap searching code into macro and call it multiple times with different paths / suffixes.

@SSE4 SSE4 force-pushed the fix_find_openexr branch from 166b8a3 to e686e39 Compare August 1, 2019 21:57
@SSE4
Copy link
Copy Markdown
Contributor Author

SSE4 commented Aug 1, 2019

@alalek I've changed the logic according to your suggestions

@SSE4 SSE4 force-pushed the fix_find_openexr branch 4 times, most recently from bfdaccd to 0338e80 Compare August 1, 2019 22:05
@asmorkalov
Copy link
Copy Markdown
Contributor

@SSE4 I tried the solution for Ubuntu 16.04 and it does not work for me. Please correct me, if I do something wrong:

$  git clone https://github.com/openexr/openexr.git
$ mkdir openexr_build
$ cd mkdir openexr_build
$ cmake -DCMAKE_INSTALL_PREFIX=/home/alexander/tmp
$ make
$ make install
$ cd ..
$ mkdir opencv_build
$ cmake -DOPENEXR_ROOT=/home/alexander/tmp ../opencv

Console log for OpenCV:

--   Media I/O: 
--     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.8)
--     JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80)
--     WEBP:                        build (ver encoder: 0x020e)
--     PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.2.54)
--     TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 / 4.0.6)
--     JPEG 2000:                   /usr/lib/x86_64-linux-gnu/libjasper.so (ver 1.900.1)
--     OpenEXR:                     build (ver 2.3.0)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES

CMakeCache.txt content:

alexander@asmorkal-desktop:~/Projects/opencv-build-pr$ cat ./CMakeCache.txt | grep -in openexr
125://Build openexr from source
126:BUILD_OPENEXR:BOOL=OFF
780:OPENEXR_HALF_LIBRARY:FILEPATH=OPENEXR_HALF_LIBRARY-NOTFOUND
783:OPENEXR_IEX_LIBRARY:FILEPATH=OPENEXR_IEX_LIBRARY-NOTFOUND
786:OPENEXR_ILMTHREAD_LIBRARY:FILEPATH=OPENEXR_ILMTHREAD_LIBRARY-NOTFOUND
789:OPENEXR_IMATH_LIBRARY:FILEPATH=OPENEXR_IMATH_LIBRARY-NOTFOUND
792:OPENEXR_INCLUDE_PATH:PATH=/usr/include/OpenEXR
795:OPENEXR_ROOT:UNINITIALIZED=/home/alexander/tmp
986://Include ILM support via OpenEXR
987:WITH_OPENEXR:BOOL=ON
1320:openexr_BINARY_DIR:STATIC=/home/alexander/Projects/opencv-build-pr/3rdparty/openexr
1323:openexr_SOURCE_DIR:STATIC=/home/alexander/Projects/opencv/3rdparty/openexr
3047://ADVANCED property for variable: OPENEXR_HALF_LIBRARY
3048:OPENEXR_HALF_LIBRARY-ADVANCED:INTERNAL=1
3049://ADVANCED property for variable: OPENEXR_IEX_LIBRARY
3050:OPENEXR_IEX_LIBRARY-ADVANCED:INTERNAL=1
3051://ADVANCED property for variable: OPENEXR_ILMTHREAD_LIBRARY
3052:OPENEXR_ILMTHREAD_LIBRARY-ADVANCED:INTERNAL=1
3053://ADVANCED property for variable: OPENEXR_IMATH_LIBRARY
3054:OPENEXR_IMATH_LIBRARY-ADVANCED:INTERNAL=1

@asmorkalov asmorkalov self-assigned this Oct 18, 2019
@SSE4
Copy link
Copy Markdown
Contributor Author

SSE4 commented Oct 18, 2019

@asmorkalov steps appear to be correct. I'll take a look and let you know.

@SSE4
Copy link
Copy Markdown
Contributor Author

SSE4 commented Oct 20, 2019

@asmorkalov worked for me (Ubuntu 18.04.2 LTS):

  666  git clone https://github.com/openexr/openexr.git
  667  cd openexr/
  668  mkdir openexr_build
  669  cd openexr_build/
  670  cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/tmp
  671  make
  672  make install
  673  cd ..
  676  git clone git@github.com:opencv/opencv.git
  677  cd opencv/
  679  git remote add sse4 git@github.com:SSE4/opencv.git
  680  git fetch --all
  681  git checkout -b fix_find_openexr sse4/fix_find_openexr
  682  mkdir opencv_build
  683  cd opencv_build/
  684  cmake .. -DOPENEXR_ROOT=$HOME/tmp
-- Found OpenEXR: /home/sse4/tmp/lib/libIlmImf-2_4.so
...
--   Media I/O:
--     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11)
--     JPEG:                        libjpeg-turbo (ver 2.0.2-62)
--     WEBP:                        build (ver encoder: 0x020e)
--     PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.34)
--     TIFF:                        build (ver 42 - 4.0.10)
--     JPEG 2000:                   build (ver 1.900.1)
--     OpenEXR:                     /home/sse4/tmp/lib/libImath-2_4.so /home/sse4/tmp/lib/libIlmImf-2_4.so /home/sse4/tmp/lib/libIex-2_4.so /home/sse4/tmp/lib/libHalf-2_4.so /home/sse4/tmp/lib/libIlmThread-2_4.so (ver 2_4)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
//Build openexr from source
BUILD_OPENEXR:BOOL=OFF
OPENEXR_HALF_LIBRARY:FILEPATH=/home/sse4/tmp/lib/libHalf-2_4.so
OPENEXR_IEX_LIBRARY:FILEPATH=/home/sse4/tmp/lib/libIex-2_4.so
OPENEXR_ILMIMF_LIBRARY:FILEPATH=/home/sse4/tmp/lib/libIlmImf-2_4.so
OPENEXR_ILMTHREAD_LIBRARY:FILEPATH=/home/sse4/tmp/lib/libIlmThread-2_4.so
OPENEXR_IMATH_LIBRARY:FILEPATH=/home/sse4/tmp/lib/libImath-2_4.so
OPENEXR_INCLUDE_PATH:PATH=/home/sse4/tmp/include/OpenEXR
//The include paths needed to use OpenEXR
OPENEXR_INCLUDE_PATHS:PATH=/home/sse4/tmp/include/OpenEXR
//The libraries needed to use OpenEXR
OPENEXR_LIBRARIES:STRING=/home/sse4/tmp/lib/libImath-2_4.so;/home/sse4/tmp/lib/libIlmImf-2_4.so;/home/sse4/tmp/lib/libIex-2_4.so;/home/sse4/tmp/lib/libHalf-2_4.so;/home/sse4/tmp/lib/libIlmThread-2_4.so
OPENEXR_ROOT:UNINITIALIZED=/home/sse4/tmp
//Include ILM support via OpenEXR
WITH_OPENEXR:BOOL=ON
//ADVANCED property for variable: OPENEXR_HALF_LIBRARY
OPENEXR_HALF_LIBRARY-ADVANCED:INTERNAL=1
//ADVANCED property for variable: OPENEXR_IEX_LIBRARY
OPENEXR_IEX_LIBRARY-ADVANCED:INTERNAL=1
//ADVANCED property for variable: OPENEXR_ILMIMF_LIBRARY
OPENEXR_ILMIMF_LIBRARY-ADVANCED:INTERNAL=1
//ADVANCED property for variable: OPENEXR_ILMTHREAD_LIBRARY
OPENEXR_ILMTHREAD_LIBRARY-ADVANCED:INTERNAL=1
//ADVANCED property for variable: OPENEXR_IMATH_LIBRARY
OPENEXR_IMATH_LIBRARY-ADVANCED:INTERNAL=1
//ADVANCED property for variable: OPENEXR_INCLUDE_PATHS
OPENEXR_INCLUDE_PATHS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: OPENEXR_LIBRARIES
OPENEXR_LIBRARIES-ADVANCED:INTERNAL=1

@asmorkalov
Copy link
Copy Markdown
Contributor

@SSE4 I apologize for the delay. I tried the patch with Ubuntu 16.04 and 18.04. It works properly on 18.04, but not on 16.04. Most probably it's issue of CMake 3.5.1. I'll dig a little bit in this today and let you know.

@SSE4
Copy link
Copy Markdown
Contributor Author

SSE4 commented Oct 25, 2019

@asmorkalov no problem. I'll try on 16.04 as well (and older CMake) and let you know about my findings, if it's related to Ubuntu version or CMake version.

@asmorkalov
Copy link
Copy Markdown
Contributor

@SSE4, do you have any progress on this?

@SSE4
Copy link
Copy Markdown
Contributor Author

SSE4 commented Nov 1, 2019

@asmorkalov on Ubuntu 16.04 I get:

CMake Error at CMakeLists.txt:12 (cmake_minimum_required):
  CMake 3.10 or higher is required.  You are running version 3.5.1


-- Configuring incomplete, errors occurred!

while building OpenEXR
checking with newer CMake

@SSE4
Copy link
Copy Markdown
Contributor Author

SSE4 commented Nov 1, 2019

@asmorkalov results:
works on both Ubuntu 16.04 and Ubuntu 18.04
works with both CMake 3.15.5 and CMake 3.10.2
OpenEXR may only be built with CMake 3.10+ AcademySoftwareFoundation/openexr@032304a

@asmorkalov
Copy link
Copy Markdown
Contributor

@SSE4 I apologize that I misdirect you with CMake versions. I have several versions on my host and I used 3.10+ for both OpenEXR and OpenCV as the first one cannot be built with old CMake. Let me describe what happened on my host and how to fix it.

FIND_PATH like other FIND_ functions set cache variable with path and does not search again, if something was found for the first time. I have some incomplete OpenEXR installation on my host or something that was not detected by your script in system directories. FIND_PATH finds headers in system path before hand and always returns the same value ignoring PATH option.

I see two things to fix:

  • Add NO_DEFAULT_PATH option for FIND_PATH to search for headers in locations that are defined in function parameters only.
  • UNSET OPENEXR_INCLUDE_PATH and all _LIBRARY variables from cache in loop body. Otherwise header files or some library found once earlier is mixed with things found on the next iteration. It's the issue @alalek mentioned before.

@SSE4
Copy link
Copy Markdown
Contributor Author

SSE4 commented Nov 5, 2019

@asmorkalov okay, I'll do that adjustments. meanwhile, do you have a command line to reproduce and test the explained case (to get some incomplete OpenEXR installation)?

@asmorkalov
Copy link
Copy Markdown
Contributor

@SSE4 I just tried to install everything related to OpenEXR on my Ubuntu 16.04. I'm not sure if it's complete installation or not, but it was not properly recognized by your code -- only headers were found.

@SSE4 SSE4 force-pushed the fix_find_openexr branch from 0338e80 to 210da18 Compare November 5, 2019 09:14
@SSE4
Copy link
Copy Markdown
Contributor Author

SSE4 commented Nov 5, 2019

@asmorkalov I've made suggested adjustments

Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch should go into 3.4 branch first. We will merge changes from 3.4 into master regularly (weekly/bi-weekly).

So, please:

  • change "base" branch of this PR: master => 3.4 (use "Edit" button near PR title)
  • rebase your commits from master onto 3.4 branch. For example:
    git rebase -i --onto upstream/3.4 upstream/master
    (check list of your commits, save and quit (Esc + "wq" + Enter)
    where upstream is configured by following this GitHub guide and fetched (git fetch upstream).
  • push rebased commits into source branch of your fork (with --force option)

Note: no needs to re-open PR, apply changes "inplace".

@SSE4 SSE4 changed the base branch from master to 3.4 November 6, 2019 10:26
Signed-off-by: SSE4 <tomskside@gmail.com>
@SSE4 SSE4 force-pushed the fix_find_openexr branch from 210da18 to 2e20f06 Compare November 6, 2019 10:27
@SSE4
Copy link
Copy Markdown
Contributor Author

SSE4 commented Nov 6, 2019

@alalek rebased onto 3.4

@opencv-pushbot opencv-pushbot merged commit 2e20f06 into opencv:3.4 Nov 6, 2019
@alalek alalek mentioned this pull request Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants