conda-forge / libtiff-feedstock

A conda-smithy repository for libtiff.
BSD 3-Clause "New" or "Revised" License
1 stars 25 forks source link

Imported target "TIFF::TIFF" includes non-existent path C:/bld/qt6-main_1696944674905/_h_env/Library/lib/cmake/tiff/include #102

Closed jschueller closed 12 months ago

jschueller commented 12 months ago

Solution to issue cannot be found in the documentation.

Issue

when building qt6 on windows with 4.6.0 I get this error:

CMake Error in qtimageformats/src/plugins/imageformats/tiff/CMakeLists.txt:
2023-10-10T13:54:39.7768892Z   Imported target "TIFF::TIFF" includes non-existent path
2023-10-10T13:54:39.7905566Z 
2023-10-10T13:54:39.9591525Z     "C:/bld/qt6-main_1696944674905/_h_env/Library/lib/cmake/tiff/include"

I looked at the Library/lib/cmake/tiff/TiffTargets.cmake but it looks correct:

# Compute the installation prefix relative to this file.
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
if(_IMPORT_PREFIX STREQUAL "/")
  set(_IMPORT_PREFIX "")
endif()

# Create imported target TIFF::tiff
add_library(TIFF::tiff SHARED IMPORTED)

set_target_properties(TIFF::tiff PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
)

any idea ?

Installed packages

libtiff 4.6

Environment info

https://dev.azure.com/conda-forge/feedstock-builds/_build/results?buildId=800840&view=logs&jobId=a70f640f-cc53-5cd3-6cdc-236a1aa90802&j=a70f640f-cc53-5cd3-6cdc-236a1aa90802&t=6119ccbe-9301-594f-7c27-f792b80a7fcc
hmaarrfk commented 12 months ago

it seems to be including the build time path on windows. how does that typically get addressed there?

hmaarrfk commented 12 months ago
set_target_properties(TIFF::tiff PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
)

^^^ Is the above line from qt or from libtiff? if it is from qt, it seems to be wrong and likely assuming vendoring of some kind

hmaarrfk commented 12 months ago

I'm not an expert with cmake, but is _IMPORT_PREFIX equivalent to ${PREFIX}, or ${PREFIX}/lib/cmake/tiff?

jschueller commented 12 months ago

this script is automatically generated by cmake export command _IMPORT_PREFIX should have a value of ${PREFIX} at the end of the cmake script (%LIBRARY_PREFIX% on windows)

the first part of the path C:/bld/qt6-main_1696944674905/_h_env/Library/ should be ok because that's where libtiff should be installed (the host env for qt6 build), the script starts from the location of itself (Library\lib\cmake\tiff\libtifftargets.cmake), then goes up 3 parents (Library), and adds /include (Library/include)

hmaarrfk commented 12 months ago

The diff from the two packages

diff -u libtiff-4.5.1-h6c8260b_1/pkg-libtiff-4.5.1-h6c8260b_1/Library/lib/cmake/tiff/TiffConfig.cmake libtiff-4.6.0-h6e2ebb7_2/pkg-libtiff-4.6.0-h6e2ebb7_2/Library/lib/cmake/tiff/TiffConfig.cmake
--- libtiff-4.5.1-h6c8260b_1/pkg-libtiff-4.5.1-h6c8260b_1/Library/lib/cmake/tiff/TiffConfig.cmake   2023-08-24 13:15:43.000000000 -0400
+++ libtiff-4.6.0-h6e2ebb7_2/pkg-libtiff-4.6.0-h6e2ebb7_2/Library/lib/cmake/tiff/TiffConfig.cmake   2023-09-25 13:10:12.000000000 -0400
@@ -1,6 +1,28 @@
 if(NOT "ON")
     # TODO: import dependencies
 endif()
+
+function(set_variable_from_rel_or_absolute_path var root rel_or_abs_path)
+    if(IS_ABSOLUTE "${rel_or_abs_path}")
+        set(${var} "${rel_or_abs_path}" PARENT_SCOPE)
+    else()
+        set(${var} "${root}/${rel_or_abs_path}" PARENT_SCOPE)
+    endif()
+endfunction()
+
+# Tell the user project where to find our headers and libraries
+get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" ABSOLUTE)
+get_filename_component(_DIR "${_DIR}" DIRECTORY)
+get_filename_component(_ROOT "${_DIR}/" ABSOLUTE)
+# Use _ROOT as prefix here for the possibility of relocation after installation.
+set_variable_from_rel_or_absolute_path("TIFF_INCLUDE_DIR" "${_ROOT}" "include")
+set(TIFF_INCLUDE_DIRS ${TIFF_INCLUDE_DIR})
+
+set(TIFF_LIBRARIES TIFF::tiff)
+
 if(NOT TARGET TIFF::tiff)
-    include("${CMAKE_CURRENT_LIST_DIR}/TiffTargets.cmake")
+    include("${_DIR}/TiffTargets.cmake")
 endif()
+
+unset (_ROOT)
+unset (_DIR)
diff -u libtiff-4.5.1-h6c8260b_1/pkg-libtiff-4.5.1-h6c8260b_1/Library/lib/cmake/tiff/TiffConfigVersion.cmake libtiff-4.6.0-h6e2ebb7_2/pkg-libtiff-4.6.0-h6e2ebb7_2/Library/lib/cmake/tiff/TiffConfigVersion.cmake
--- libtiff-4.5.1-h6c8260b_1/pkg-libtiff-4.5.1-h6c8260b_1/Library/lib/cmake/tiff/TiffConfigVersion.cmake    2023-08-24 13:15:43.000000000 -0400
+++ libtiff-4.6.0-h6e2ebb7_2/pkg-libtiff-4.6.0-h6e2ebb7_2/Library/lib/cmake/tiff/TiffConfigVersion.cmake    2023-09-25 13:10:12.000000000 -0400
@@ -9,19 +9,19 @@
 # The variable CVF_VERSION must be set before calling configure_file().

-set(PACKAGE_VERSION "4.5.1")
+set(PACKAGE_VERSION "4.6.0")

 if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
   set(PACKAGE_VERSION_COMPATIBLE FALSE)
 else()

-  if("4.5.1" MATCHES "^([0-9]+)\\.")
+  if("4.6.0" MATCHES "^([0-9]+)\\.")
     set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}")
     if(NOT CVF_VERSION_MAJOR VERSION_EQUAL 0)
       string(REGEX REPLACE "^0+" "" CVF_VERSION_MAJOR "${CVF_VERSION_MAJOR}")
     endif()
   else()
-    set(CVF_VERSION_MAJOR "4.5.1")
+    set(CVF_VERSION_MAJOR "4.6.0")
   endif()

   if(PACKAGE_FIND_VERSION_RANGE)
diff -u libtiff-4.5.1-h6c8260b_1/pkg-libtiff-4.5.1-h6c8260b_1/Library/lib/cmake/tiff/TiffTargets.cmake libtiff-4.6.0-h6e2ebb7_2/pkg-libtiff-4.6.0-h6e2ebb7_2/Library/lib/cmake/tiff/TiffTargets.cmake
--- libtiff-4.5.1-h6c8260b_1/pkg-libtiff-4.5.1-h6c8260b_1/Library/lib/cmake/tiff/TiffTargets.cmake  2023-08-24 13:15:57.000000000 -0400
+++ libtiff-4.6.0-h6e2ebb7_2/pkg-libtiff-4.6.0-h6e2ebb7_2/Library/lib/cmake/tiff/TiffTargets.cmake  2023-09-25 13:10:17.000000000 -0400
@@ -7,7 +7,7 @@
    message(FATAL_ERROR "CMake >= 2.8.3 required")
 endif()
 cmake_policy(PUSH)
-cmake_policy(VERSION 2.8.3...3.24)
+cmake_policy(VERSION 2.8.3...3.25)
 #----------------------------------------------------------------
 # Generated CMake target import file.
 #----------------------------------------------------------------

Chat GPT suggests:

From the provided diff, we can see several changes between the versions of `libtiff`. Let's break it down: 1. In `TiffConfig.cmake`: - A new function `set_variable_from_rel_or_absolute_path` is introduced. This function seems to take a variable name, a root path, and another path. If the third path is absolute, it sets the variable to this path; otherwise, it makes the path relative to the root path. - Variables `_DIR` and `_ROOT` are used to compute the absolute paths relative to the current CMake file. These are then used to set the `TIFF_INCLUDE_DIR` variable. The critical change here is the introduction of the `TIFF_INCLUDE_DIR` variable, which uses the new function to generate its path. Given the error you're seeing, it looks like the computed path does not exist. The issue seems to be that the new configuration expects the headers to be in a directory relative to the CMake file's location, but this directory does not actually exist in the new `libtiff` version. 2. In `TiffConfigVersion.cmake`, the version number is updated, which is expected. 3. In `TiffTargets.cmake`, there is an update to the `cmake_policy` version range. This doesn't appear directly relevant to the error you're seeing. To resolve the error: 1. **Manual Approach**: You could manually check if the `include` directory actually exists relative to the CMake file's location. If it doesn't, find out where the headers are and modify the `TiffConfig.cmake` file to reflect the correct path. 2. **CMake Configuration**: Sometimes, certain library paths can be provided to CMake through cache variables or command-line arguments. If you have control over the CMake configuration step, you might be able to override the problematic path. For instance, you might try adding `-DTIFF_INCLUDE_DIR=/path/to/correct/include/dir` when invoking `cmake`. 3. **Raise an Issue**: If you believe this is an issue with how the `libtiff` package was built or packaged, you could consider raising an issue with the maintainers of the library or the package repository you're using. For a quick solution, the first approach might be your best bet. Adjust the paths manually in the CMake configuration file for `libtiff` and see if that resolves the issue. If you're consistently building with this library, consider the other approaches for a more permanent solution.
jschueller commented 12 months ago

looks that TiffConfig.cmake is bogus

jschueller commented 12 months ago

https://gitlab.com/libtiff/libtiff/-/merge_requests/541

hmaarrfk commented 12 months ago

xid you want to make a PR here to fix it in the feedstocks?

I'm very ok fixing build related stuff when an upstream issue or merge request is created

jschueller commented 12 months ago

lets see what libtiff says first, I already have a simple workaround in the qt feedstock