* allow telling cmake where to find required fonts in system when user supplies the paths, as suggested by unC0Rr, e.g. -DFONTS_DIRS='/usr/share/fonts/truetype/wqy;/usr/share/fonts/truetype/dejavu'
authorsheepluva
Thu, 16 Jan 2014 19:50:18 +0100
changeset 9994 8455993a7a1b
parent 9993 76ad55807c24
child 9995 8bf092ddc536
* allow telling cmake where to find required fonts in system when user supplies the paths, as suggested by unC0Rr, e.g. -DFONTS_DIRS='/usr/share/fonts/truetype/wqy;/usr/share/fonts/truetype/dejavu' * the build system will use the paths to lookup fonts and install those not found * the engine will load the paths into physfs (mountpoint /Fonts) to make the fonts available at runtime * overriding fonts in packages should be possible again now
CMakeLists.txt
hedgewars/config.inc.in
hedgewars/uPhysFSLayer.pas
hedgewars/uStore.pas
share/hedgewars/Data/Fonts/CMakeLists.txt
--- a/CMakeLists.txt	Thu Jan 16 17:18:53 2014 +0100
+++ b/CMakeLists.txt	Thu Jan 16 19:50:18 2014 +0100
@@ -21,6 +21,13 @@
 #set this to ON when 2.1.0 becomes more widespread (and only for linux)
 option(PHYSFS_SYSTEM "Use system physfs (off)" OFF)
 
+#system paths for finding required fonts (see share/hedgewars/Data/fonts)
+#subdirectories will NOT be searched.
+#all founds that can't be found will be bundled with hedgewars
+option(PHYSFS_SYSTEM "Use system physfs (off)" OFF)
+
+option(BUILD_SHARED_LIBS "Build libraries as shared modules (on)" ON)
+
 if(WIN32 OR APPLE)
     option(LUA_SYSTEM "Use system lua (off)" OFF)
 else()
@@ -38,6 +45,7 @@
     set(DATA_INSTALL_DIR "share/hedgewars" CACHE STRING "Resource folder path")
 endif()
 
+set(FONTS_DIRS "" CACHE STRING "Additional paths to folders where required fonts can be found ( ; is separator)")
 
 #versioning
 set(CPACK_PACKAGE_VERSION_MAJOR 0)
--- a/hedgewars/config.inc.in	Thu Jan 16 17:18:53 2014 +0100
+++ b/hedgewars/config.inc.in	Thu Jan 16 19:50:18 2014 +0100
@@ -26,3 +26,4 @@
       cRevisionString = '${HEDGEWARS_REVISION}';
       cHashString = '${HEDGEWARS_HASH}';
       cDefaultPathPrefix = '${HEDGEWARS_FULL_DATADIR}/Data';
+      cFontsPaths = '${FONTS_DIRS}';
--- a/hedgewars/uPhysFSLayer.pas	Thu Jan 16 17:18:53 2014 +0100
+++ b/hedgewars/uPhysFSLayer.pas	Thu Jan 16 19:50:18 2014 +0100
@@ -3,6 +3,8 @@
 interface
 uses SDLh, LuaPas;
 
+{$INCLUDE "config.inc"}
+
 const PhysfsLibName = {$IFDEF PHYSFS_INTERNAL}'libhwphysfs'{$ELSE}'libphysfs'{$ENDIF};
 const PhyslayerLibName = 'libphyslayer';
 
@@ -31,7 +33,6 @@
 
 function  physfsReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; cdecl; external PhyslayerLibName;
 procedure physfsReaderSetBuffer(buf: pointer); cdecl; external PhyslayerLibName;
-procedure pfsPermitSymbolicLinks(allow: boolean);
 procedure hedgewarsMountPackage(filename: PChar); cdecl; external PhyslayerLibName;
 
 implementation
@@ -42,8 +43,6 @@
 function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl ; external PhyslayerLibName;
 function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external PhyslayerLibName;
 
-procedure PHYSFS_permitSymbolicLinks(allow: boolean); cdecl; external PhysfsLibName;
-
 function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongBool; cdecl; external PhysfsLibName;
 function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external PhysfsLibName;
 function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external PhysfsLibName;
@@ -131,27 +130,23 @@
         pfsBlockRead:= r
 end;
 
-procedure pfsPermitSymbolicLinks(allow: boolean);
-begin
-    PHYSFS_permitSymbolicLinks(allow);
-end;
-
 procedure pfsMount(path: AnsiString; mountpoint: PChar);
 begin
     if PHYSFS_mount(Str2PChar(path), mountpoint, false) then
-        AddFileLog('[PhysFS] mount ' + path + ': ok')
+        AddFileLog('[PhysFS] mount ' + path + ' at ' + mountpoint + ' : ok')
     else
-        AddFileLog('[PhysFS] mount ' + path + ': FAILED ("' + PHYSFS_getLastError() + '")');
+        AddFileLog('[PhysFS] mount ' + path + ' at ' + mountpoint + ' : FAILED ("' + PHYSFS_getLastError() + '")');
 end;
 
 procedure pfsMountAtRoot(path: AnsiString);
 begin
-    pfsMount(path, nil);
+    pfsMount(path, '/');
 end;
 
 procedure initModule;
 var i: LongInt;
     cPhysfsId: shortstring;
+    fp: AnsiString;
 begin
 {$IFDEF HWLIBRARY}
     //TODO: http://icculus.org/pipermail/physfs/2011-August/001006.html
@@ -163,6 +158,25 @@
     i:= PHYSFS_init(Str2PChar(cPhysfsId));
     AddFileLog('[PhysFS] init: ' + inttostr(i));
 
+    // mount system fonts paths first
+    fp := cFontsPaths;
+
+    // let's remove paths from fp and mount them until nothing is left
+    while length(fp) > 0 do
+        begin
+        AddFileLog('lol');
+        // search for ;
+        i := pos(';', fp);
+        // if there is no ; left, read to end
+        if i < 1 then
+            i := length(fp) + 1;
+        // don't mount empty path
+        if i > 2 then
+            pfsMount(copy(fp, 1, i-1), '/Fonts');
+        // remove mounted path from fp
+        fp := copy(fp, i+1, length(fp)-i);
+        end;
+
     pfsMountAtRoot(PathPrefix);
     pfsMountAtRoot(UserPathPrefix + '/Data');
 
@@ -176,9 +190,6 @@
             pfsMountAtRoot(ExtractFileDir(cScriptName));
             cScriptName := ExtractFileName(cScriptName);
         end;
-
-    // mounts fonts last - don't allow overwriting them as we allow symlinks there
-    pfsMount(PathPrefix + '/Fonts', '/Fonts');
 end;
 
 procedure freeModule;
--- a/hedgewars/uStore.pas	Thu Jan 16 17:18:53 2014 +0100
+++ b/hedgewars/uStore.pas	Thu Jan 16 19:50:18 2014 +0100
@@ -322,8 +322,6 @@
 AddFileLog('StoreLoad()');
 
 if not reload then
-    begin
-    pfsPermitSymbolicLinks(true);
     for fi:= Low(THWFont) to High(THWFont) do
         with Fontz[fi] do
             begin
@@ -334,8 +332,6 @@
             TTF_SetFontStyle(Handle, style);
             WriteLnToConsole(msgOK)
             end;
-    pfsPermitSymbolicLinks(false);
-    end;
 
 MakeCrossHairs;
 LoadGraves;
--- a/share/hedgewars/Data/Fonts/CMakeLists.txt	Thu Jan 16 17:18:53 2014 +0100
+++ b/share/hedgewars/Data/Fonts/CMakeLists.txt	Thu Jan 16 19:50:18 2014 +0100
@@ -1,4 +1,26 @@
-install(FILES
+set(FONTFILES
     DejaVuSans-Bold.ttf
-    wqy-zenhei.ttc
-    DESTINATION ${SHAREPATH}Data/Fonts)
+    wqy-zenhei.ttc)
+
+if (FONTS_DIRS)
+    foreach(fontfile ${FONTFILES})
+        set(missing 1)
+        foreach(fontdir ${FONTS_DIRS})
+            if (EXISTS "${fontdir}/${fontfile}")
+                message(STATUS "Fonts: Found ${fontfile} in ${fontdir}")
+                set(missing 0)
+                break()
+            endif()
+        endforeach(fontdir)
+        if(missing)
+            set(MISSINGFONTFILES ${MISSINGFONTFILES} ${fontfile})
+            message(STATUS "Fonts: Could not find ${fontfile}, it will be installed")
+        endif()
+    endforeach(fontfile)
+else()
+    set(MISSINGFONTFILES ${FONTFILES})
+endif()
+
+if (MISSINGFONTFILES)
+    install(FILES ${MISSINGFONTFILES} DESTINATION ${SHAREPATH}Data/Fonts)
+endif()