bugThe FreeType Project - Bugs: bug #53287, Support DLL builds in CMake builds

 
 

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

bug #53287: Support DLL builds in CMake builds

Submitter:  Chun-wei Fan <fanc999>
Submitted:  Mon 05 Mar 2018 04:58:33 AM UTC
   
 
Severity:  3 - Normal Item Group:  None
Status:  Fixed Privacy:  Public
Assigned to:  wl Open/Closed:  Closed
Planned Release:  2.9.1

Jump to the original submission

Mon 12 Mar 2018 10:40:05 AM UTC, comment #10: 

I just ran an MSYS/MingW build of git master (C_VISIBILITY_PRESET not set!) from my Windows machine with the command:

> cmake -G "MSYS Makefiles" -DCMAKE_MAKE_PROGRAM='C:\msys64\mingw64\bin\mingw32-make.exe' -DBUILD_SHARED_LIBS=ON ..


Files get compiled with a command line like this:

> /C/msys64/mingw64/bin/gcc.exe -DFT2_BUILD_LIBRARY -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -Dfreetype_EXPORTS @CMakeFiles/freetype.dir/includes_C.rsp  -o CMakeFiles/freetype.dir/src/gzip/ftgzip.c.obj   -c /C/UsersLocal/nikolaus.waxweiler/Development/freetype2/src/gzip/ftgzip.c


Linking:

> /C/msys64/mingw64/bin/gcc.exe    -shared -o libfreetype.dll -Wl,--out-implib,libfreetype.dll.a -Wl,--major-image-version,2,--minor-image-version,9 -Wl,--whole-archive CMakeFiles/freetype.dir/objects.a -Wl,--no-whole-archive @CMakeFiles/freetype.dir/linklibs.rsp


Running http://www.nirsoft.net/utils/dll_export_viewer.html on the resulting DLL shows only public API functions including TT_New_Context and TT_RunIns. Now that's funny.

Nikolaus Waxweiler <morksig>
Group Member
Sun 11 Mar 2018 05:11:16 PM UTC, comment #9: 

"C_VISIBILITY_PRESET hidden" is preferred to deprecated GenerateExportHeader. We should ask Behdad how HarfBuzz controls its symbol visibility.

Alexei Podtelezhnikov <podtelez>
Group Member
Sat 10 Mar 2018 11:24:53 PM UTC, comment #8: 

Ok, when re-running the `./builds/unix/libtool --mode=link gcc [...] -no-undefined` command without passing a symbol export file, I get the same results as the CMake file, i.e. truckloads of Harfbuzz symbols.

So it's really down to setting the exports explicitly...

Nikolaus Waxweiler <morksig>
Group Member
Sat 10 Mar 2018 04:04:03 PM UTC, comment #7: 

Ah, figured out the symbols thing. The CMake shared library declaration should read:


if (BUILD_SHARED_LIBS)
  set_target_properties(freetype PROPERTIES
    VERSION ${PROJECT_VERSION}
    SOVERSION ${SHARED_LIBRARY_VERSION}
    C_VISIBILITY_PRESET hidden
  )
endif ()


That brings the symbol table down to the exported functions plus __bss_start, _edata, _end, _fini, _init. The lib size stays the same though, ~750KB with autotools and strip-debug, ~1MB with CMake...

Nikolaus Waxweiler <morksig>
Group Member
Sat 10 Mar 2018 03:15:13 PM UTC, comment #6: 

"-fPIC" turns up when I define BUILD_SHARED_LIBS=ON (Fedora 27 x64, GCC 7.3.1, cmake 3.10.x).

The resulting library properly exports only the public ABI on Windows but exports everything, including a linked in statical Harfbuzz archive on F27.

Nikolaus Waxweiler <morksig>
Group Member
Fri 09 Mar 2018 04:13:57 PM UTC, comment #5: 

MSVC defines _DLL, libtool defines DLL_EXPORT.

Don't we need to define DLL_EXPORT for mingw/cygwin builds?

Furthermore, I do not see -fPIC defined. Also, I do not follow "COMPILE_DEFINITIONS freetype_EXPORTS" with the latter undefined.

We need more testing.

Alexei Podtelezhnikov <podtelez>
Group Member
Fri 09 Mar 2018 05:53:00 AM UTC, comment #4: 

Applied, thanks!  Please test.

Werner LEMBERG <wl>
Group administrator
Fri 09 Mar 2018 03:24:00 AM UTC, comment #3: 

Hi,

Hmm, I didn't realise that change was made to ftoptions.h, and it does seem to me that change there is enough.

Visual Studio builds automatically define _DLL when we build with /MD (release) or /MDd (debug)[1], which is the case for CMake builds.

[1]: https://msdn.microsoft.com/en-US/library/b0084kay.aspx

Here is the new patch.

With blessings, and cheers!

(file #43495)

Chun-wei Fan <fanc999>
Tue 06 Mar 2018 03:14:56 PM UTC, comment #2: 

Agree. Only the first two hanks of the patch might be useful.

Alexei Podtelezhnikov <podtelez>
Group Member
Mon 05 Mar 2018 05:38:20 AM UTC, comment #1: 

Thanks for the patch!  However, I wonder whether it is really necessary, since code for conditionally using `__declspec' has been added recently, cf.

http://git.savannah.gnu.org/cgit/freetype/freetype2.git/tree/include/freetype/config/ftconfig.h#n460

Werner LEMBERG <wl>
Group administrator
Mon 05 Mar 2018 04:58:33 AM UTC, original submission:  

Hi,

The current CMake build files only support Windows DLL builds when using the MinGW GCC compiler, but not Visual Studio, where only static .lib builds are supported.  This attempts to make DLL builds supported on Visual Studio as well, by defining FT_EXPORT and FT_EXPORT_DEF appropriately in ftoptions.h when BUILD_SHARED_LIBS is enabled.  I will post a patch shortly.

With blessings, thank you!

Chun-wei Fan <fanc999>

 

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

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by podtelez
  • -email is unavailable- added by morksig (Posted a comment)
  • -email is unavailable- added by podtelez (Posted a comment)
  • -email is unavailable- added by wl (Posted a comment)
  • -email is unavailable- added by fanc999 (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 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-03-11 podtelez Carbon-Copy- Added -email is unavailable-
    2018-03-09 wl StatusNeed Info Fixed
        Open/ClosedOpen Closed
        Planned ReleaseNone 2.9.1
    2018-03-09 fanc999 Attached File- Added 0001-CMakeLists.txt-win32-Allow-MSVC-DLL-builds-53287.patch, #43495
    2018-03-05 wl StatusNone Need Info
        Assigned toNone wl
    2018-03-05 fanc999 Attached File- Added 0001-CMakeLists.txt-win32-Allow-MSVC-DLL-builds-53287.patch, #43464

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code