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