By default, Bugzilla does not search the list of RESOLVED bugs.
You can force it to do so by putting the upper-case word ALL in front of your search query, e.g.: ALL tdelibs
We recommend searching for bugs this way, as you may discover that your bug has already been resolved and fixed in a later release.
Bug 901 - Concatenation of tdegraphics libs string causing build fail due to CMake policy CMP0004
Summary: Concatenation of tdegraphics libs string causing build fail due to CMake poli...
Status: RESOLVED FIXED
Alias: None
Product: TDE
Classification: Unclassified
Component: tdegraphics (show other bugs)
Version: R14.0.0 [Trinity]
Hardware: All Linux
: P5 major
Assignee: Timothy Pearson
URL:
Depends on:
Blocks:
 
Reported: 2012-03-08 13:43 CST by David C. Rankin
Modified: 2012-04-15 21:16 CDT (History)
2 users (show)

See Also:
Compiler Version:
TDE Version String:
Application Version:
Application Name:


Attachments
patch for tdegraphics/libkscan/ConfigureChecks.cmake (875 bytes, patch)
2012-03-08 16:02 CST, David C. Rankin
Details | Diff
patch for tdegraphics/libkscan/ConfigureChecks.cmake (update) (875 bytes, patch)
2012-03-08 16:22 CST, David C. Rankin
Details | Diff
patch for tdegraphics/libkscan/ConfigureChecks.cmake (update) (876 bytes, patch)
2012-03-08 16:34 CST, David C. Rankin
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David C. Rankin 2012-03-08 13:43:08 CST
Tim, Serghei, all

  tdegraphics fails to build due to a run-together of something like ${LIBS}${LDFLAGS} including libsane resulting in a link string that contains "-lsane-Wl" instead of "-lsane -Wl". After investigation and bug reports filed with Archlinux against net-snmp-config, the crux of the issue was discovered. The problem is NOT sane, NOT net-snmp-config, and not tdegraphics, the problem is the way CMAKE concatenates the library stings to include libsane. (something like ${LIBS}${LDFLAGS}.) The problem appears to start in tdegraphics/libkscan/ConfigureChecks.cmake

  Example:

On Archlinux, sane-config --libs provides the following:

-lsane  -Wl,-O1,--sort-common,--as-needed,-z,relro,--hash-style=gnu -L/usr/lib -lnetsnmp -lcrypto -lm -ldl -lv4l1   -lm -ltiff -ljpeg  -lgphoto2 -lgphoto2_port -lm -lexif -lusb     -lavahi-common -lavahi-client    -lusb

After CMake processing with kdegraphics/libkscan/ConfigureChecks.cmake, the following linker string is provided:

-lsane-Wl,-O1,--sort-common,--as-needed,-z,relro,--hash-style=gnu-L/usr/lib -lnetsnmp -lcrypto -lm -ldl -lv4l1 -ltiff -ljpeg -lgphoto2 -lgphoto2_port -lexif -lusb -lavahi-common -lavahi-client <snip /opt/trinity/...>

The build then fails with:

/usr/bin/ld: cannot find -lsane-Wl,-O1,--sort-common,--as-needed,-z,relro,--hash-style=gnu-L/usr/lib
collect2: ld returned 1 exit status

  As Serghei pointed out, part of the concatenation occurs in tdegraphics/libkscan/ConfigureChecks.cmake:

  string( REGEX REPLACE "(^| )-l" ";" SANE_LIBRARIES "${SANE_LIBRARIES}" )
  string( REPLACE " " "" SANE_LIBRARIES "${SANE_LIBRARIES}" )

On Arch, the first part of the sane-config libs is:

-lsane  -Wl,-O1,--sort-common,--as-needed,-z,relro,--hash-style=gnu -L/usr/lib -lnetsnmp -lcrypto 

The build failure is cause by the concatenation to:

-lsane-Wl,-O1,--sort-common,--as-needed,-z,relro,--hash-style=gnu-L/usr/lib -lnetsnmp -lcrypto 

The string( REGEX REPLACE "(^| )-l" ";...  and ... string( REPLACE " " "" ... has resulted in the run-together of both:

-lsane-Wl  and  --hash-style=gnu-L/usr/lib

  I have looked, but I don't know where the actual concatenation is being done. It looks like a simple solution would be to change substitutions so that they prevent removing required spaces.  I'll work on a patch and submit. If someone sees the solution already, feel welcome to provide it.

  I have tried removing the " " "" substitution, but that results in the error:

CMake Error at cmake/modules/TDEMacros.cmake:662 (add_library):
  Target "kscan-shared" links to item "v4l1 " which has leading or trailing
  whitespace.  This is now an error according to policy CMP0004.
Call Stack (most recent call first):
  libkscan/CMakeLists.txt:38 (tde_add_library)

  So CMAKE policy CMP0004 seems to be the whole reason for the substitutions to begin with.
Comment 1 David C. Rankin 2012-03-08 16:01:07 CST
Here is a patch that I think is the way this should be done. This set of regexes leave only a semi-colon separated list of libraries returned by 'sane-config --libs':


--- tdegraphics/libkscan/ConfigureChecks.cmake
+++ tdegraphics/libkscan/ConfigureChecks.cmake  2012-03-08 15:51:30.452794166 -0600
@@ -39,8 +39,14 @@
   string( REGEX REPLACE "(^| )-I" ";" SANE_INCLUDE_DIRS "${SANE_INCLUDE_DIRS}" )
 endif( )
 if( SANE_LIBRARIES )
-  string( REGEX REPLACE "(^| )-l" ";" SANE_LIBRARIES "${SANE_LIBRARIES}" )
-  string( REPLACE " " "" SANE_LIBRARIES "${SANE_LIBRARIES}" )
+  ## remove all spaces and replace whitespace with ';'
+  string( REGEX REPLACE "[ ]+" ";" SANE_LIBRARIES "${SANE_LIBRARIES}" )
+  ## remove all non-library information
+  string( REGEX REPLACE "[-][^l]([^ ;])+" "" SANE_LIBRARIES "${SANE_LIBRARIES}" )
+  ## remove multiple ';'
+  string( REGEX REPLACE "[;]+" ";" SANE_LIBRARIES "${SANE_LIBRARIES}" )
+  ## remove '-l'
+  string( REGEX REPLACE "-l" "" SANE_LIBRARIES "${SANE_LIBRARIES}" )
 endif( )

 if( NOT HAVE_SANE )
Comment 2 David C. Rankin 2012-03-08 16:02:28 CST
Created attachment 469 [details]
patch for tdegraphics/libkscan/ConfigureChecks.cmake
Comment 3 David C. Rankin 2012-03-08 16:22:31 CST
Created attachment 470 [details]
patch for tdegraphics/libkscan/ConfigureChecks.cmake (update)

Oops, had to fix this one:

  string( REGEX REPLACE ";[-][^l]([^ ;])+" "" SANE_LIBRARIES "${SANE_LIBRARIES}" )
Comment 4 David C. Rankin 2012-03-08 16:34:43 CST
Created attachment 471 [details]
patch for tdegraphics/libkscan/ConfigureChecks.cmake (update)

Uploaded wrong patch last time :)
Comment 5 David C. Rankin 2012-03-08 20:53:17 CST
I have confirmed this patch and it work flawlessly. tdegraphics built without issue using:

  # patch ConfigureChecks.cmake
  msg "Patching..."
  patch -Np0 -i libkscan.patch

  # fix libXext inclusion in linker string (gcc >=4.6.2)
  msg "fixing libXext inclusion in linker string (gcc >=4.6.2)"
  sed -i "/LINK/s|$| Xext|" tdegraphics/ksnapshot/CMakeLists.txt
  
  msg "Creating out-of-source build directory: ${srcdir}/build"
  mkdir -p build
  cd build

  msg "Starting cmake..."
  cmake ${srcdir}/${pkgname#*-} \
    -DCMAKE_VERBOSE_MAKEFILE=ON \
    -DCMAKE_INSTALL_PREFIX=${TDEDIR} \
    -DWITH_T1LIB=ON \
    -DWITH_LIBPAPER=ON \
    -DWITH_TIFF=ON \
    -DWITH_OPENEXR=ON \
    -DWITH_PDF=ON \
    -DBUILD_ALL=ON
Comment 6 David C. Rankin 2012-03-08 20:55:55 CST
(In reply to comment #1)

> +  ## remove all non-library information
> +  string( REGEX REPLACE "[-][^l]([^ ;])+" "" SANE_LIBRARIES
> "${SANE_LIBRARIES}" )

See comment 3 for proper patch, should be:

+  string( REGEX REPLACE ";[-][^l]([^ ;])+" "" SANE_LIBRARIES "${SANE_LIBRARIES}" )
Comment 7 Darrell 2012-04-15 21:16:20 CDT
I ran across this same bug when building tdegraphics on Slackware 13.37 (gcc 4.5.2, cmake 2.8.4).

I never saw this bug with Slackware 13.1 (gcc 4.4.4, cmake 2.8.4).

The patch was needed to build in 13.37.

Patch pushed upstream in GIT hash cd3c62a5.

This resolves the bug report.

Thank you!