1# Distributed under the original FontForge BSD 3-clause license
2
3#[=======================================================================[.rst:
4FontForgeConfigure
5------------------
6
7Sets up the required state to generate the config header for FontForge.
8
9This could do with a lot of cleanup, especially in simplifying how some
10of these defines work.
11
12There are multiple definitions that are not covered by the config header,
13but which are used throughout FontForge.
14
15Defines that are not included, because they are obsolete, include:
16
17_NO_LIBCAIRO
18
19There are other defines where it is not clear if they should be
20configured, or if they are defined locally in source only:
21
22BIGICONS, CHUNKDEBUG, DEBUG, DEBUG_FREEHAND, ESCAPE_LIBXML_STRINGS,
23FF_OVERLAP_VERBOSE, FF_RELATIONAL_GEOM, FLAG, GLYPH_DATA_DEBUG,
24HANYANG, KNIFE_CONTINUOUS, KOREAN, MEMORY_MASK, MyMemory,
25NATIVE_CALLBACKS, NEED_WIDE_CHAR, OPTIMIZE_TTF_INSTRS, THIRDS_IN_WIDTH,
26UsingPThreads, _COMPOSITE_BROKEN, _DEBUGCRASHFONTFORGE, _WACOM_DRV_BROKEN
27
28#]=======================================================================]
29
30function(_set_negated outval inval)
31  if(${inval})
32    set(${outval} 0 PARENT_SCOPE)
33  else()
34    set(${outval} 1 PARENT_SCOPE)
35  endif()
36endfunction()
37
38function(fontforge_generate_config template destination)
39  include(CheckSymbolExists)
40  include(CheckIncludeFile)
41  include(TestBigEndian)
42
43  # Platform specific checks
44  test_big_endian(WORDS_BIGENDIAN)
45  if(APPLE)
46    set(_CursorsMustBe16x16 1)
47    set(_Keyboard 1)
48    set(__Mac 1)
49  elseif(CYGWIN)
50    set(__CygWin 1)
51    set(_ModKeysAutoRepeat 1)
52  endif()
53
54  # Header checks
55  check_include_file(execinfo.h HAVE_EXECINFO_H)
56  check_include_file(ieeefp.h HAVE_IEEEFP_H)
57  check_include_file(langinfo.h HAVE_LANGINFO_H)
58  check_symbol_exists(nl_langinfo "langinfo.h" HAVE_NL_LANGINFO)
59
60  # These are hard requirements/unsupported, should get rid of these
61  set(HAVE_ICONV_H 1)
62  set(HAVE_LIBINTL_H 1)
63  set(_NO_LIBUNICODENAMES 1)
64
65  # Configurable settings
66  set(FONTFORGE_CONFIG_SHOW_RAW_POINTS ${ENABLE_DEBUG_RAW_POINTS})
67  set(FONTFORGE_CONFIG_TILEPATH ${ENABLE_TILE_PATH})
68  set(FONTFORGE_CONFIG_WRITE_PFM ${ENABLE_WRITE_PFM})
69  if(REAL_TYPE STREQUAL "double")
70    set(FONTFORGE_CONFIG_USE_DOUBLE 1)
71  endif()
72  if(ENABLE_FREETYPE_DEBUGGER) # this is a file path
73    set(FREETYPE_HAS_DEBUGGER 1)
74  endif()
75
76  # Configurable features
77  _set_negated(_NO_XKB "${X11_Xkb_FOUND}")
78  _set_negated(_NO_XINPUT "${X11_Xi_FOUND}")
79
80  if(NOT ENABLE_GUI OR NOT ENABLE_X11)
81    set(X_DISPLAY_MISSING 1)
82  endif()
83
84  if(ENABLE_GUI AND NOT ENABLE_X11)
85    set(FONTFORGE_CAN_USE_GDK 1)
86  endif()
87
88  set(FONTFORGE_CAN_USE_WOFF2 ${ENABLE_WOFF2_RESULT})
89
90  _set_negated(_NO_FFSCRIPT "${ENABLE_NATIVE_SCRIPTING}")
91  _set_negated(_NO_LIBJPEG "${ENABLE_LIBJPEG_RESULT}")
92  _set_negated(_NO_LIBPNG "${ENABLE_LIBPNG_RESULT}")
93  _set_negated(_NO_LIBSPIRO "${ENABLE_LIBSPIRO_RESULT}")
94  _set_negated(_NO_LIBTIFF "${ENABLE_LIBTIFF_RESULT}")
95  _set_negated(_NO_LIBUNGIF "${ENABLE_LIBGIF_RESULT}")
96  _set_negated(_NO_LIBUNINAMESLIST "${ENABLE_LIBUNINAMESLIST_RESULT}")
97  _set_negated(_NO_PYTHON "${ENABLE_PYTHON_SCRIPTING_RESULT}")
98  _set_negated(_NO_LIBREADLINE "${ENABLE_LIBREADLINE_RESULT}")
99
100  if(ENABLE_LIBSPIRO_RESULT)
101    set(_LIBSPIRO_FUN ${Libspiro_FEATURE_LEVEL})
102  endif()
103  if(ENABLE_LIBUNINAMESLIST_RESULT)
104    set(_LIBUNINAMESLIST_FUN ${Libuninameslist_FEATURE_LEVEL})
105  endif()
106
107  configure_file(${template} ${destination} ESCAPE_QUOTES @ONLY)
108endfunction()
109
110function(_get_git_version)
111  if(NOT DEFINED FONTFORGE_GIT_VERSION)
112    find_package(Git)
113    if(Git_FOUND)
114      execute_process(
115        COMMAND
116          "${GIT_EXECUTABLE}" "log" "--pretty=format:%H" "-n" "1"
117        WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
118        RESULT_VARIABLE GIT_RETVAL
119        OUTPUT_VARIABLE GIT_OUTPUT
120        ERROR_QUIET
121        OUTPUT_STRIP_TRAILING_WHITESPACE
122      )
123      if(${GIT_RETVAL} EQUAL 0)
124        set(_git_version "${GIT_OUTPUT}")
125      endif()
126    endif()
127    set(FONTFORGE_GIT_VERSION "${_git_version}" CACHE INTERNAL "Git revision that FontForge was built off")
128  endif()
129endfunction()
130
131function(_get_modtime)
132  if(NOT DEFINED FONTFORGE_MODTIME)
133    set(_modtime "0")
134    if(${CMAKE_VERSION} VERSION_LESS "3.6.0") # so unfortunate
135      if(DEFINED ENV{SOURCE_DATE_EPOCH} AND "$ENV{SOURCE_DATE_EPOCH}" MATCHES "^[0-9]+$")
136        set(_modtime "$ENV{SOURCE_DATE_EPOCH}")
137      else()
138        execute_process(
139          COMMAND "date" "+%s"
140          RESULT_VARIABLE DATE_RETVAL
141          OUTPUT_VARIABLE DATE_OUTPUT
142          ERROR_QUIET
143          OUTPUT_STRIP_TRAILING_WHITESPACE
144        )
145        if(${DATE_RETVAL} EQUAL 0 AND "${DATE_OUTPUT}" MATCHES "^[0-9]+$")
146          set(_modtime "${DATE_OUTPUT}")
147        endif()
148      endif()
149    else()
150      string(TIMESTAMP _modtime "%s")
151    endif()
152    set(FONTFORGE_MODTIME "${_modtime}" CACHE INTERNAL "Unix epoch of when the build was initially configured")
153  endif()
154endfunction()
155
156function(_get_modtime_str _modtime)
157  if(NOT DEFINED FONTFORGE_MODTIME_STR)
158    if(${CMAKE_VERSION} VERSION_LESS "3.6.0")
159      execute_process(
160        COMMAND "date" "-u" "--date=@${_modtime}" "+%Y-%m-%d %H:%M UTC"
161        RESULT_VARIABLE DATE_RETVAL
162        OUTPUT_VARIABLE DATE_OUTPUT
163        ERROR_QUIET
164        OUTPUT_STRIP_TRAILING_WHITESPACE
165      )
166      if(${DATE_RETVAL} EQUAL 0)
167        set(_modtime_str "${DATE_OUTPUT}")
168      endif()
169    else()
170      string(TIMESTAMP _modtime_str "%Y-%m-%d %H:%M UTC" UTC)
171    endif()
172    set(FONTFORGE_MODTIME_STR "${_modtime_str}" CACHE INTERNAL "Human readable string of when the build was initially configured")
173  endif()
174endfunction()
175
176function(fontforge_generate_version_extras template destination)
177    _get_git_version()
178    _get_modtime()
179    _get_modtime_str(${FONTFORGE_MODTIME})
180
181    configure_file(${template} ${destination} ESCAPE_QUOTES @ONLY)
182endfunction()
183