1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
# Distributed under the original FontForge BSD 3-clause license
#[=======================================================================[.rst:
BuiltUtils
----------
``build_option`` standardises the way in which to specify a build option.
Supports any type that the ``set()`` function supports. Options are
stored in the cache.
For ``BOOL`` options, passing in a 5th parameter (after the description)
will lead to that parameter being evaluated. If it evaluates to false,
the build option is forced to ``OFF``.
The ``AUTO`` type is for tri-state Boolean options. The ``value`` parameter
is ignored; it will always be initialised to ``AUTO``.
The ``ENUM`` type is for options that may be one of a number of defined
values. All arguments after the description are treated as allowed values
of the enumeration.
All other types are passed directly to ``set()``.
``print_build_options`` lists all build options, along with their
current status.
``set_default_build_type sets the default build type if none is
explicitly specified.
``set_default_rpath`` sets the default RPATH to be used on platforms
that support it. Can only be called after GNUInstallDirs has been
included.
``enable_sanitizer`` checks if the specified sanitizer is supported,
and adds the required compiler flags to enable it if so. If unsupported,
it will error out.
#]=======================================================================]
function(build_option variable type value description)
if(${type} STREQUAL BOOL)
if(${ARGC} EQUAL 4)
option("${variable}" "${description}" "${value}")
elseif(${ARGC} EQUAL 5)
if(${ARGV4})
option("${variable}" "${description}" "${value}")
else()
set("${variable}" OFF CACHE BOOL "${description}" FORCE)
endif()
else()
message(FATAL_ERROR "Invalid number of arguments for dependent option")
endif()
elseif(${type} STREQUAL AUTO)
set("${variable}" AUTO CACHE STRING "${description}")
set_property(CACHE "${variable}" PROPERTY STRINGS AUTO ON OFF)
elseif(${type} STREQUAL ENUM)
if(${ARGC} LESS 5)
message(FATAL_ERROR "Must pass at least one enum type")
endif()
set("${variable}" "${value}" CACHE STRING "${description} Valid values: ${ARGN}")
set_property(CACHE "${variable}" PROPERTY STRINGS ${ARGN})
if(NOT "${${variable}}" IN_LIST ARGN)
message(FATAL_ERROR "'${${variable}}' is not a valid value for ${variable}, expect one of ${ARGN}")
endif()
else()
set("${variable}" "${value}" CACHE "${type}" "${description}")
endif()
if(NOT "${variable}" IN_LIST BUILD_OPTIONS)
set(BUILD_OPTIONS "${BUILD_OPTIONS};${variable}" CACHE INTERNAL "List of build options")
endif()
endfunction()
function(print_build_options)
message(STATUS "Build options: ")
foreach(opt ${BUILD_OPTIONS})
if("${${opt}}" STREQUAL "AUTO" AND DEFINED ${opt}_RESULT)
if(${opt}_RESULT)
message(STATUS " ${opt} = ${${opt}} => ON")
else()
message(STATUS " ${opt} = ${${opt}} => OFF")
endif()
else()
message(STATUS " ${opt} = ${${opt}}")
endif()
endforeach()
endfunction()
function(set_default_build_type default_build_type)
# https://blog.kitware.com/cmake-and-the-default-build-type
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
if(NOT "CMAKE_BUILD_TYPE" IN_LIST BUILD_OPTIONS)
set(BUILD_OPTIONS "${BUILD_OPTIONS};CMAKE_BUILD_TYPE" CACHE INTERNAL "List of build options")
endif()
endfunction()
function(set_default_rpath)
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_FULL_LIBDIR}" _present)
if(_present LESS 0)
list(FIND CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}" _present)
if(_present LESS 0)
list(APPEND CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
endif()
endif()
if(APPLE)
list(APPEND CMAKE_INSTALL_RPATH "@loader_path/../lib")
list(APPEND CMAKE_INSTALL_RPATH "@loader_path/../..") # For fontforge.so
endif()
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH} PARENT_SCOPE)
endfunction()
function(enable_sanitizer type)
if("${type}" STREQUAL "none")
return()
elseif(NOT CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
message(FATAL_ERROR "Require a GCC-like compiler to enable sanitizers.")
endif()
include(CheckCCompilerFlag)
include(CMakePushCheckState)
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=${type}")
check_c_compiler_flag("-fsanitize=${type} -fno-omit-frame-pointer" "_sanitizer_${type}")
cmake_pop_check_state()
if(NOT _sanitizer_${type})
message(FATAL_ERROR "Sanitizer flags not supported: -fsanitize=${type} -fno-omit-frame-pointer")
endif()
# kind of dirty but what can you do
add_compile_options("-fsanitize=${type}" "-fno-omit-frame-pointer")
link_libraries("-fsanitize=${type}")
endfunction()
function(set_font_family type value)
if("${type}" STREQUAL "ui")
if("${value}" STREQUAL "default")
if(APPLE)
set(FONTFORGE_UI_FAMILIES "system-ui,Deja Vu Sans,Lucida Grande,sans" PARENT_SCOPE)
elseif(WIN32 OR CYGWIN)
set(FONTFORGE_UI_FAMILIES "system-ui,Deja Vu Sans,Calibri" PARENT_SCOPE)
else()
set(FONTFORGE_UI_FAMILIES "system-ui,Deja Vu Sans" PARENT_SCOPE)
endif()
else()
set(FONTFORGE_UI_FAMILIES "${value}" PARENT_SCOPE)
endif()
elseif("${type}" STREQUAL "label")
if("${value}" STREQUAL "default")
if(APPLE)
set(FONTFORGE_LABEL_FAMILIES "Deja Vu Sans,Lucida Grande,unifont,unifont upper" PARENT_SCOPE)
elseif(WIN32 OR CYGWIN)
set(FONTFORGE_LABEL_FAMILIES "Deja Vu Sans,Calibri,unifont,unifont upper" PARENT_SCOPE)
else()
set(FONTFORGE_LABEL_FAMILIES "Deja Vu Sans,unifont,unifont upper" PARENT_SCOPE)
endif()
else()
set(FONTFORGE_LABEL_FAMILIES "${value}" PARENT_SCOPE)
endif()
elseif("${type}" STREQUAL "serif")
if("${value}" STREQUAL "default")
if(APPLE)
set(FONTFORGE_SERIF_FAMILIES "serif" PARENT_SCOPE)
elseif(WIN32 OR CYGWIN)
set(FONTFORGE_SERIF_FAMILIES "serif" PARENT_SCOPE)
else()
set(FONTFORGE_SERIF_FAMILIES "serif" PARENT_SCOPE)
endif()
else()
set(FONTFORGE_SERIF_FAMILIES "${value}" PARENT_SCOPE)
endif()
elseif("${type}" STREQUAL "mono")
if("${value}" STREQUAL "default")
if(APPLE)
set(FONTFORGE_MONO_FAMILIES "monospace,unifont" PARENT_SCOPE)
elseif(WIN32 OR CYGWIN)
set(FONTFORGE_MONO_FAMILIES "monospace,unifont" PARENT_SCOPE)
else()
set(FONTFORGE_MONO_FAMILIES "monospace,unifont" PARENT_SCOPE)
endif()
else()
set(FONTFORGE_MONO_FAMILIES "${value}" PARENT_SCOPE)
endif()
endif()
endfunction()
|