From 2a5d8e8ff8c1d831308411c61304c2feb0569ea3 Mon Sep 17 00:00:00 2001 From: Priyesh Kumar Date: Thu, 27 Aug 2020 23:28:05 +0530 Subject: [PATCH] [builds/windows] Changes to build 'dlg' with FreeType on Windows. We only support Visual C++ 2010 and newer. * builds/windows/vc2010/script.bat: New windows batch file to copy necessary 'dlg' files from `submodules/dlg` to `src/dlg`. This file is used as a pre-built event in Visual C++. * builds/windows/ftdebug.c: Synchronize with `src/base/ftdebug.c`. * builds/windows/vc2010/freetype.vcxproj.filters: Add `src/dlgwrap.c`. * builds/windows/vc2010/freetype.vcxproj (AdditionalIncludeDirectories): Add include files of dlg for 'Debug' and 'Debug Static' configurations on both 'x64' and 'win32' platforms. (PreprocessorDefinitions): Add `FT_LOGGING` for 'Debug' and 'Debug Static' configurations on both 'x64' and 'win32' platforms. Add `DLG_STATIC' for 'Debug' configuration on 'x64' and 'win32' platforms. (DisableLanguageExtensions): We need to disable the `/Za` option when building 'dlg' with FreeType as 'dlg' strictly follows the C99 standard. Visual C++ produces behaves unexpectedly when compiling a C99 file with `/Za` option enabled. --- ChangeLog | 30 ++- builds/windows/ftdebug.c | 251 +++++++++++++++++- builds/windows/vc2010/freetype.vcxproj | 47 ++-- .../windows/vc2010/freetype.vcxproj.filters | 3 + builds/windows/vc2010/script.bat | 11 + src/base/ftdebug.c | 1 - 6 files changed, 322 insertions(+), 21 deletions(-) create mode 100644 builds/windows/vc2010/script.bat diff --git a/ChangeLog b/ChangeLog index e6222f36f..15f54d58e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2020-11-30 Priyesh Kumar + + [builds/windows] Changes to build 'dlg' with FreeType on Windows. + + We only support Visual C++ 2010 and newer. + + * builds/windows/vc2010/script.bat: New windows batch file to copy + necessary 'dlg' files from `submodules/dlg` to `src/dlg`. This file + is used as a pre-built event in Visual C++. + + * builds/windows/ftdebug.c: Synchronize with `src/base/ftdebug.c`. + + * builds/windows/vc2010/freetype.vcxproj.filters: Add + `src/dlgwrap.c`. + + * builds/windows/vc2010/freetype.vcxproj + (AdditionalIncludeDirectories): Add include files of dlg for 'Debug' + and 'Debug Static' configurations on both 'x64' and 'win32' + platforms. + (PreprocessorDefinitions): Add `FT_LOGGING` for 'Debug' and 'Debug + Static' configurations on both 'x64' and 'win32' platforms. + Add `DLG_STATIC' for 'Debug' configuration on 'x64' and 'win32' + platforms. + (DisableLanguageExtensions): We need to disable the `/Za` option + when building 'dlg' with FreeType as 'dlg' strictly follows the C99 + standard. Visual C++ produces behaves unexpectedly when + compiling a C99 file with `/Za` option enabled. + 2020-11-30 Priyesh Kumar [base] Add public API to change log handling function. @@ -64,7 +92,7 @@ initialization and uninitialization of logging related variables. (ft_log_handler): New function to handle logs of FreeType. - * src/base/ftdebug.c: Add necessary logging related variables. + * src/base/ftdebug.c: Add necessary logging related variables. (ft_logging_init, ft_logging_deinit, ft_log_handler): Add function definitions. diff --git a/builds/windows/ftdebug.c b/builds/windows/ftdebug.c index d58949003..abbe32248 100644 --- a/builds/windows/ftdebug.c +++ b/builds/windows/ftdebug.c @@ -43,6 +43,51 @@ #include #include +#include + + +#ifdef FT_LOGGING + + /************************************************************************** + * + * Variables used to control logging. + * + * 1. `ft_default_trace_level` stores the value of trace levels, which are + * provided to FreeType using the `FT2_DEBUG` environment variable. + * + * 2. `ft_fileptr` stores the `FILE*` handle. + * + * 3. `ft_component` is a string that holds the name of `FT_COMPONENT`. + * + * 4. The flag `ft_component_flag` prints the name of `FT_COMPONENT` along + * with the actual log message if set to true. + * + * 5. The flag `ft_timestamp_flag` prints time along with the actual log + * message if set to ture. + * + * 6. `ft_have_newline_char` is used to differentiate between a log + * message with and without a trailing newline character. + * + * 7. `ft_custom_trace_level` stores the custom trace level value, which + * is provided by the user at run-time. + * + * We use `static` to avoid 'unused variable' warnings. + * + */ + static const char* ft_default_trace_level = NULL; + static FILE* ft_fileptr = NULL; + static const char* ft_component = NULL; + static FT_Bool ft_component_flag = FALSE; + static FT_Bool ft_timestamp_flag = FALSE; + static FT_Bool ft_have_newline_char = TRUE; + static const char* ft_custom_trace_level = NULL; + + /* declared in ftdebug.h */ + + dlg_handler ft_default_log_handler = NULL; + FT_Custom_Log_Handler custom_output_handler = NULL; + +#endif /* FT_LOGGING*/ #ifdef FT_DEBUG_LEVEL_ERROR @@ -207,9 +252,18 @@ FT_BASE_DEF( void ) ft_debug_init( void ) { - const char* ft2_debug = getenv( "FT2_DEBUG" ); + const char* ft2_debug = NULL; +#ifdef FT_LOGGING + if ( ft_custom_trace_level != NULL ) + ft2_debug = ft_custom_trace_level; + else + ft2_debug = ft_default_trace_level; +#else + ft2_debug = ft_getenv( "FT2_DEBUG" ); +#endif + if ( ft2_debug ) { const char* p = ft2_debug; @@ -222,6 +276,49 @@ if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' ) continue; +#ifdef FT_LOGGING + + /* check extra arguments for logging */ + if ( *p == '-' ) + { + const char* r = ++p; + + + if ( *r == 'v' ) + { + const char* s = ++r; + + + ft_component_flag = TRUE; + + if ( *s == 't' ) + { + ft_timestamp_flag = TRUE; + p++; + } + + p++; + } + + else if ( *r == 't' ) + { + const char* s = ++r; + + + ft_timestamp_flag = TRUE; + + if ( *s == 'v' ) + { + ft_component_flag = TRUE; + p++; + } + + p++; + } + } + +#endif /* FT_LOGGING */ + /* read toggle name, followed by ':' */ q = p; while ( *p && *p != ':' ) @@ -323,8 +420,158 @@ /* nothing */ } - #endif /* !FT_DEBUG_LEVEL_TRACE */ +#ifdef FT_LOGGING + + /************************************************************************** + * + * Initialize and de-initialize 'dlg' library. + * + */ + + FT_BASE_DEF( void ) + ft_logging_init( void ) + { + ft_default_log_handler = ft_log_handler; + ft_default_trace_level = ft_getenv( "FT2_DEBUG" ); + + if ( ft_getenv( "FT_LOGGING_FILE" ) ) + ft_fileptr = ft_fopen( ft_getenv( "FT_LOGGING_FILE" ), "w" ); + else + ft_fileptr = stderr; + + ft_debug_init(); + + /* Set the default output handler for 'dlg'. */ + dlg_set_handler( ft_default_log_handler, NULL ); + } + + + FT_BASE_DEF( void ) + ft_logging_deinit( void ) + { + ft_fclose( ft_fileptr ); + } + + + /************************************************************************** + * + * An output log handler for FreeType. + * + */ + FT_BASE_DEF( void ) + ft_log_handler( const struct dlg_origin* origin, + const char* string, + void* data ) + { + const char* features; + + FT_UNUSED( data ); + + + if ( ft_timestamp_flag && ft_component_flag && ft_have_newline_char ) + features = "[%h:%m %t] %c"; + else if ( ft_component_flag && ft_have_newline_char ) + features = "[%t] %c"; + else if ( ft_timestamp_flag && ft_have_newline_char ) + features = "[%h:%m] %c"; + else + features = "%c"; + + dlg_generic_outputf_stream( ft_fileptr, features, origin, string, + dlg_default_output_styles, true ); + + if ( strchr( string, '\n' ) ) + ft_have_newline_char = TRUE; + else + ft_have_newline_char = FALSE; + } + + + /* documentation is in ftdebug.h */ + FT_BASE_DEF( void ) + ft_add_tag( const char* tag ) + { + ft_component = tag; + + dlg_add_tag( tag, NULL ); + } + + + /* documentation is in ftdebug.h */ + FT_BASE_DEF( void ) + ft_remove_tag( const char* tag ) + { + dlg_remove_tag( tag, NULL ); + } + + + /* documentation is in ftlogging.h */ + + FT_EXPORT_DEF( void ) + FT_Trace_Set_Level( const char* level ) + { + ft_component_flag = FALSE; + ft_timestamp_flag = FALSE; + ft_custom_trace_level = level; + + ft_debug_init(); + } + + + /* documentation is in ftlogging.h */ + + FT_EXPORT_DEF( void ) + FT_Trace_Set_Default_Level( void ) + { + ft_component_flag = FALSE; + ft_timestamp_flag = FALSE; + ft_custom_trace_level = NULL; + + ft_debug_init(); + } + + + /************************************************************************** + * + * Functions to handle a custom log handler. + * + */ + + /* documentation is in ftlogging.h */ + + FT_EXPORT_DEF( void ) + FT_Set_Log_Handler( FT_Custom_Log_Handler handler ) + { + custom_output_handler = handler; + } + + + /* documentation is in ftlogging.h */ + + FT_EXPORT_DEF( void ) + FT_Set_Default_Log_Handler() + { + custom_output_handler = NULL; + } + + + /* documentation is in ftdebug.h */ + FT_BASE_DEF( void ) + FT_Logging_Callback( const char* fmt, + ... ) + { + va_list ap; + + + va_start( ap, fmt ); + custom_output_handler( ft_component, fmt, ap ); + va_end( ap ); + } + +#endif /* FT_LOGGING */ + + /* END */ diff --git a/builds/windows/vc2010/freetype.vcxproj b/builds/windows/vc2010/freetype.vcxproj index d61eeec5f..41080feb7 100644 --- a/builds/windows/vc2010/freetype.vcxproj +++ b/builds/windows/vc2010/freetype.vcxproj @@ -89,11 +89,11 @@ Disabled - $(UserOptionDirectory);..\..\..\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;FT_DEBUG_LEVEL_ERROR;FT_DEBUG_LEVEL_TRACE;FT2_BUILD_LIBRARY;DLL_EXPORT;$(UserDefines);%(PreprocessorDefinitions) + ..\..\..\src\dlg\;$(UserOptionDirectory);..\..\..\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;FT_DEBUG_LEVEL_ERROR;FT_DEBUG_LEVEL_TRACE;FT2_BUILD_LIBRARY;DLL_EXPORT;FT_LOGGING;$(UserDefines);%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL - true + false Level4 ProgramDatabase Default @@ -111,15 +111,18 @@ $(UserLibraryDirectories);%(AdditionalLibraryDirectories) $(UserDependencies);%(AdditionalDependencies) + + call $(SolutionDir)script.bat + Disabled - $(UserOptionDirectory);..\..\..\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;FT_DEBUG_LEVEL_ERROR;FT_DEBUG_LEVEL_TRACE;FT2_BUILD_LIBRARY;DLL_EXPORT;$(UserDefines);%(PreprocessorDefinitions) + ..\..\..\src\dlg\;$(UserOptionDirectory);..\..\..\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;FT_DEBUG_LEVEL_ERROR;FT_DEBUG_LEVEL_TRACE;FT2_BUILD_LIBRARY;DLL_EXPORT;FT_LOGGING;$(UserDefines);%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL - true + false Level4 ProgramDatabase Default @@ -137,15 +140,18 @@ $(UserLibraryDirectories);%(AdditionalLibraryDirectories) $(UserDependencies);%(AdditionalDependencies) + + call $(SolutionDir)script.bat + Disabled - $(UserOptionDirectory);..\..\..\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;FT_DEBUG_LEVEL_ERROR;FT_DEBUG_LEVEL_TRACE;FT2_BUILD_LIBRARY;$(UserDefines);%(PreprocessorDefinitions) + ..\..\..\src\dlg;$(UserOptionDirectory);..\..\..\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;FT_DEBUG_LEVEL_ERROR;FT_DEBUG_LEVEL_TRACE;FT2_BUILD_LIBRARY;FT_LOGGING;DLG_STATIC;$(UserDefines);%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebug - true + false Level4 ProgramDatabase Default @@ -163,15 +169,18 @@ $(UserLibraryDirectories);%(AdditionalLibraryDirectories) $(UserDependencies);%(AdditionalDependencies) + + call $(SolutionDir)script.bat + Disabled - $(UserOptionDirectory);..\..\..\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;FT_DEBUG_LEVEL_ERROR;FT_DEBUG_LEVEL_TRACE;FT2_BUILD_LIBRARY;$(UserDefines);%(PreprocessorDefinitions) + ..\..\..\src\dlg;$(UserOptionDirectory);..\..\..\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;FT_DEBUG_LEVEL_ERROR;FT_DEBUG_LEVEL_TRACE;FT2_BUILD_LIBRARY;FT_LOGGING;DLG_STATIC;$(UserDefines);%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebug - true + false Level4 ProgramDatabase Default @@ -189,12 +198,15 @@ $(UserLibraryDirectories);%(AdditionalLibraryDirectories) $(UserDependencies);%(AdditionalDependencies) + + call $(SolutionDir)script.bat + MaxSpeed AnySuitable - $(UserOptionDirectory);..\..\..\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories) + ..\..\..\src\dlg;$(UserOptionDirectory);..\..\..\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories) WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;FT2_BUILD_LIBRARY;DLL_EXPORT;$(UserDefines);%(PreprocessorDefinitions) MultiThreadedDLL true @@ -221,7 +233,7 @@ MaxSpeed AnySuitable - $(UserOptionDirectory);..\..\..\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories) + ..\..\..\src\dlg;$(UserOptionDirectory);..\..\..\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories) WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;FT2_BUILD_LIBRARY;DLL_EXPORT;$(UserDefines);%(PreprocessorDefinitions) MultiThreadedDLL true @@ -248,7 +260,7 @@ MaxSpeed AnySuitable - $(UserOptionDirectory);..\..\..\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories) + ..\..\..\src\dlg;$(UserOptionDirectory);..\..\..\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories) WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;FT2_BUILD_LIBRARY;$(UserDefines);%(PreprocessorDefinitions) MultiThreaded true @@ -275,7 +287,7 @@ MaxSpeed AnySuitable - $(UserOptionDirectory);..\..\..\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories) + ..\..\..\src\dlg;$(UserOptionDirectory);..\..\..\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories) WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;FT2_BUILD_LIBRARY;$(UserDefines);%(PreprocessorDefinitions) MultiThreaded true @@ -323,6 +335,7 @@ + @@ -348,4 +361,4 @@ - + \ No newline at end of file diff --git a/builds/windows/vc2010/freetype.vcxproj.filters b/builds/windows/vc2010/freetype.vcxproj.filters index 345e1f1a7..0fa15fd83 100644 --- a/builds/windows/vc2010/freetype.vcxproj.filters +++ b/builds/windows/vc2010/freetype.vcxproj.filters @@ -131,6 +131,9 @@ Source Files\FT_MODULES + + Source Files + diff --git a/builds/windows/vc2010/script.bat b/builds/windows/vc2010/script.bat new file mode 100644 index 000000000..1c0c7fb06 --- /dev/null +++ b/builds/windows/vc2010/script.bat @@ -0,0 +1,11 @@ +@echo OFF + +:: Move to Top Dir +cd ..\..\..\ + +:: Copy dlg's files from `submodules\dlg' to `src\dlg' +IF NOT EXIST src\dlg\dlg ( + mkdir src\dlg\dlg + COPY submodules\dlg\include\dlg\dlg.h src\dlg\dlg + COPY submodules\dlg\include\dlg\output.h src\dlg\dlg + COPY submodules\dlg\src\dlg\dlg.c src\dlg\ ) diff --git a/src/base/ftdebug.c b/src/base/ftdebug.c index 42a5ae077..c84b887a7 100644 --- a/src/base/ftdebug.c +++ b/src/base/ftdebug.c @@ -407,7 +407,6 @@ /* nothing */ } - #endif /* !FT_DEBUG_LEVEL_TRACE */