bugThe FreeType Project - Bugs: bug #54450, Check for CMake target for...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #54450: Check for CMake target for third-party libs before using system libs

Submitter:  Steve Robinson <ssrobins>
Submitted:  Sun 05 Aug 2018 11:27:18 PM UTC
   
 
Severity:  3 - Normal Item Group:  Wishlist
Status:  Need Info Privacy:  Public
Assigned to:  morksig Open/Closed:  Open
Planned Release:  None

Sun 07 Oct 2018 12:01:49 PM UTC, comment #5: 

Looking at this. Which CMake version are you using and what's the exact command line you use to configure the build?

The following works for me on my Fedora 28 workstation with CMake 3.11.2:


freetype2 (master) $ cmake -E remove_directory build && cmake -E make_directory build && cmake -E chdir build cmake -G Ninja .. -DCMAKE_DISABLE_FIND_PACKAGE_PNG=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_HarfBuzz=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_BZip2=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_ZLIB=TRUE -DBUILD_SHARED_LIBS=ON && cmake --build build
-- The C compiler identification is GNU 8.1.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Looking for fcntl.h
-- Looking for fcntl.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nikolaus/Entwicklung/freetype2/build
[42/42] Creating library symlink libfreetype.so.6 libfreetype.so

freetype2 (master) $ ldd build/libfreetype.so
        linux-vdso.so.1 (0x00007ffee329b000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f7b2b653000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f7b2bcfc000)


Nikolaus Waxweiler <morksig>
Group Member
Mon 06 Aug 2018 06:15:42 AM UTC, comment #4: 

That's funny. I use the current CMake file for building the library for bundling with freetype-py and disable everything except HarfBuzz there and it works for macOS, Linux and Windows. Investigating later...

Nikolaus Waxweiler <morksig>
Group Member
Mon 06 Aug 2018 05:18:32 AM UTC, comment #3: 

Since you don't have the GNU autotool support stuff on your system, please copy the files

  aclocal.m4
  config.guess
  config.sub
  configure.ac
  configure
  install-sh
  ltmain.sh

(in directory `builds/unix') from the 2.9.1 FreeType tarball and retry.  There were some changes since the 2.9.1 release, but they don't affect handling of libpng.

I'm not a cmake user, so I leave it to Nikolaus to comment this part.

Werner LEMBERG <wl>
Group administrator
Mon 06 Aug 2018 05:02:56 AM UTC, comment #2: 

Sorry for the confusion, the CMakeLists.txt file I attached is the one from the 2.9.1 release archive plus these bug fixes:
https://savannah.nongnu.org/bugs/index.php?54450
https://savannah.nongnu.org/bugs/index.php?54048
https://savannah.nongnu.org/bugs/index.php?53816
https://savannah.nongnu.org/bugs/index.php?53815

The entire change is in my original message.  It's adding an if(TARGET and change the if(___FOUND) to an elseif for the zlib, png, and bzip2 libs.  I should note that while zlib and png have CMake configs (and therefore set CMake target names) included with the library source, bzip2 did not have a CMake config so I made one.  This solution works great for me and likely anyone who is building all their third-party libs for a consistent builds (example: debug symbols all the way through), easy upgrades, and easy deployments (single binary).  If it's too far from how people typically build your library, I'd understand if you opt out of that change.  This bug is more about the build errors when bzip2 and png are disabled anyway.

autogen/configure/make is not working for me, though I've never tried before so maybe I'm missing something:
steve$ ./autogen.sh && ./configure --with-png=no && make
./autogen.sh: line 102: aclocal: command not found
./autogen.sh: line 55: test: 1: unary operator expected
./autogen.sh: line 59: test: 1: unary operator expected
./autogen.sh: line 67: test: 10: unary operator expected
./autogen.sh: line 71: test: 10: unary operator expected
./autogen.sh: line 102: glibtoolize: command not found
./autogen.sh: line 55: test: 2: unary operator expected
./autogen.sh: line 59: test: 2: unary operator expected
./autogen.sh: line 67: test: 2: unary operator expected
./autogen.sh: line 71: test: 2: unary operator expected
./autogen.sh: line 102: autoconf: command not found
./autogen.sh: line 55: test: 2: unary operator expected
./autogen.sh: line 59: test: 2: unary operator expected
./autogen.sh: line 67: test: 62: unary operator expected
./autogen.sh: line 71: test: 62: unary operator expected
generating `configure.ac'
running `aclocal -I . --force'
./autogen.sh: line 15: aclocal: command not found
error while running `aclocal -I . --force'

Steve Robinson <ssrobins>
Mon 06 Aug 2018 04:34:12 AM UTC, comment #1: 

I see some changes in the cmake code after the last release, so please clone the current git and retry.

And to assure that the problem is with FreeType's cmake setup and not in the C code: Please check whether `./autogen.sh && ./configure --with-png=no && make' works on your Mac.  For me, it works just fine on my GNU/Linux box.

Nikolaus, please have a look.

Werner LEMBERG <wl>
Group administrator
Sun 05 Aug 2018 11:27:18 PM UTC, original submission:  

I discovered that my program was not running on some Macs and traced the problem back to an XQuartz install on my build machine loading libpng from a nonstandard location, which would not work on Macs that don't have XQuartz installed.

The following comment is in the freetype CMakeLists.txt file:
# . Set the `FT_WITH_ZLIB', `FT_WITH_BZIP2', `FT_WITH_PNG', and
#   `FT_WITH_HARFBUZZ' CMake variables to `ON' to force using a dependency.
#   Leave a variable undefined (which is the default) to use the dependency
#   only if it is available.  Set `CMAKE_DISABLE_FIND_PACKAGE_HarfBuzz=TRUE' to
#   disable a dependency completely

This implies to me that freetype can be built without these libraries (likely at the cost of certain features).  When I disable PNG, I get the following build error on Mac (and maybe other platforms, I didn't check):
In file included from /Users/steve/Documents/games_xcode_build/3rdparty/freetype/freetype-2.9.1/src/sfnt/sfnt.c:22:
/Users/steve/Documents/games_xcode_build/3rdparty/freetype/freetype-2.9.1/src/sfnt/pngshim.c:32:10: fatal error: 'png.h' file not found
#include <png.h>

With BZip2 disabled, I get the following linker error on Mac:
Undefined symbols for architecture x86_64:
  "_BZ2_bzDecompress", referenced from:
      _ft_bzip2_file_fill_output in libfreetyped.a(ftbzip2.o)
  "_BZ2_bzDecompressEnd", referenced from:
      _ft_bzip2_file_reset in libfreetyped.a(ftbzip2.o)
      _ft_bzip2_file_done in libfreetyped.a(ftbzip2.o)
  "_BZ2_bzDecompressInit", referenced from:
      _ft_bzip2_file_init in libfreetyped.a(ftbzip2.o)
      _ft_bzip2_file_reset in libfreetyped.a(ftbzip2.o)


To better work with my build system, I've added if statements that check for a CMake target for one of these libs and use that instead:
if (TARGET zlibstatic)
  target_link_libraries(freetype PRIVATE zlibstatic)
elseif (ZLIB_FOUND)
  target_link_libraries(freetype PRIVATE ${ZLIB_LIBRARIES})
  target_include_directories(freetype PRIVATE ${ZLIB_INCLUDE_DIRS})
  list(APPEND PKG_CONFIG_REQUIRED_PRIVATE zlib)
endif ()
if (TARGET bzip2)
  target_link_libraries(freetype PRIVATE bzip2)
elseif (BZIP2_FOUND)
  target_link_libraries(freetype PRIVATE ${BZIP2_LIBRARIES})
  target_include_directories(freetype PRIVATE ${BZIP2_INCLUDE_DIR}) # not BZIP2_INCLUDE_DIRS
  list(APPEND PKG_CONFIG_REQUIRED_PRIVATE bzip2)
endif ()
if (TARGET png_static)
  target_link_libraries(freetype PRIVATE png_static)
elseif (PNG_FOUND)
  target_link_libraries(freetype PRIVATE ${PNG_LIBRARIES})
  target_compile_definitions(freetype PRIVATE ${PNG_DEFINITIONS})
  target_include_directories(freetype PRIVATE ${PNG_INCLUDE_DIRS})
  list(APPEND PKG_CONFIG_REQUIRED_PRIVATE libpng)
endif ()

This way, I only have one version of a given library, I have more control on how I package it, and I guarantee I have it for all platforms.  Before I made this change, Windows wasn't finding libpng.  I can imagine a scenario down the line where there is a Windows-only bug in my program that can be traced back to not having that library.

I didn't do anything with harfbuzz.  It did not get found, freetype library built, and my program worked so it didn't seem necessary.

I attached the whole freetype CMakeLists.txt file in case you want to use it.



Steve Robinson <ssrobins>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #44719:  CMakeLists-freetype.txt added by ssrobins (15KiB - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by morksig (Posted a comment)
  • -email is unavailable- added by wl (Posted a comment)
  • -email is unavailable- added by ssrobins (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-08-06 wl StatusNone Need Info
        Assigned toNone morksig
    2018-08-05 ssrobins Attached File- Added CMakeLists-freetype.txt, #44719

    Back to the top

    Powered by Savane 3.13-cf05.
    Corresponding source code