[cmake] Add utils build support (#460)
This commit is contained in:
parent
bc1244e239
commit
3a8bc57211
150
CMakeLists.txt
150
CMakeLists.txt
|
@ -22,6 +22,12 @@ option(HB_HAVE_UNISCRIBE "Enable Uniscribe shaper on Windows" OFF)
|
|||
option(HB_HAVE_DIRECWRITE "Enable DirectWrite shaper on Windows" OFF)
|
||||
option(HB_HAVE_CORETEXT "Enable CoreText shaper on macOS" ON)
|
||||
option(HB_BUILTIN_UCDN "Use HarfBuzz provided UCDN" ON)
|
||||
option(HB_HAVE_GLIB "Use glib unicode functions" OFF)
|
||||
option(HB_BUILD_UTILS "Build harfbuzz utils, needs cairo, freetype, and glib properly be installed" OFF)
|
||||
if (HB_BUILD_UTILS)
|
||||
set(HB_HAVE_GLIB ON)
|
||||
set(HB_HAVE_FREETYPE ON)
|
||||
endif ()
|
||||
|
||||
include_directories(AFTER
|
||||
${PROJECT_SOURCE_DIR}/src
|
||||
|
@ -53,30 +59,60 @@ if (EXISTS "${PROJECT_SOURCE_DIR}/src/hb-version.h")
|
|||
set(HB_VERSION_H "${PROJECT_SOURCE_DIR}/src/hb-version.h")
|
||||
endif ()
|
||||
|
||||
## Extract variables from src/Makefile.sources
|
||||
file(READ ${PROJECT_SOURCE_DIR}/src/Makefile.sources MAKEFILESOURCES)
|
||||
function (extract_make_variable variable directory)
|
||||
string(REGEX MATCH "${variable} = ([^$]+)" temp ${MAKEFILESOURCES})
|
||||
string(REGEX REPLACE "\thb" "${directory}/hb" temp ${temp})
|
||||
string(REGEX MATCHALL "src/[^ ]+" temp ${temp})
|
||||
set(${variable} ${temp} PARENT_SCOPE)
|
||||
## Extract variables from Makefile files
|
||||
# http://stackoverflow.com/a/27630120/1414809
|
||||
function (prepend var prefix)
|
||||
set(listVar "")
|
||||
foreach (f ${ARGN})
|
||||
list(APPEND listVar "${prefix}${f}")
|
||||
endforeach (f)
|
||||
set(${var} "${listVar}" PARENT_SCOPE)
|
||||
endfunction ()
|
||||
|
||||
extract_make_variable(HB_BASE_sources "${PROJECT_SOURCE_DIR}/src")
|
||||
extract_make_variable(HB_BASE_headers "${PROJECT_SOURCE_DIR}/src")
|
||||
extract_make_variable(HB_OT_sources "${PROJECT_SOURCE_DIR}/src")
|
||||
extract_make_variable(HB_OT_headers "${PROJECT_SOURCE_DIR}/src")
|
||||
file(READ ${PROJECT_SOURCE_DIR}/src/Makefile.sources SRCSOURCES)
|
||||
file(READ ${PROJECT_SOURCE_DIR}/util/Makefile.sources UTILSOURCES)
|
||||
function (extract_make_variable variable file)
|
||||
string(REGEX MATCH "${variable} = ([^$]+)\\$" temp ${file})
|
||||
string(REGEX MATCHALL "[^ \n\t\\]+" list ${CMAKE_MATCH_1})
|
||||
set(${variable} ${list} PARENT_SCOPE)
|
||||
endfunction ()
|
||||
|
||||
extract_make_variable(HB_BASE_sources ${SRCSOURCES})
|
||||
extract_make_variable(HB_BASE_headers ${SRCSOURCES})
|
||||
extract_make_variable(HB_OT_sources ${SRCSOURCES})
|
||||
extract_make_variable(HB_OT_headers ${SRCSOURCES})
|
||||
extract_make_variable(HB_BASE_RAGEL_GENERATED_sources ${SRCSOURCES})
|
||||
extract_make_variable(HB_OT_RAGEL_GENERATED_sources ${SRCSOURCES})
|
||||
|
||||
extract_make_variable(HB_VIEW_sources ${UTILSOURCES})
|
||||
extract_make_variable(HB_SHAPE_sources ${UTILSOURCES})
|
||||
extract_make_variable(HB_OT_SHAPE_CLOSURE_sources ${UTILSOURCES})
|
||||
|
||||
prepend(HB_BASE_sources "${PROJECT_SOURCE_DIR}/src/" ${HB_BASE_sources})
|
||||
prepend(HB_BASE_headers "${PROJECT_SOURCE_DIR}/src/" ${HB_BASE_headers})
|
||||
prepend(HB_OT_sources "${PROJECT_SOURCE_DIR}/src/" ${HB_OT_sources})
|
||||
prepend(HB_OT_headers "${PROJECT_SOURCE_DIR}/src/" ${HB_OT_headers})
|
||||
if (IN_HB_DIST)
|
||||
extract_make_variable(HB_BASE_RAGEL_GENERATED_sources "${PROJECT_SOURCE_DIR}/src")
|
||||
extract_make_variable(HB_OT_RAGEL_GENERATED_sources "${PROJECT_SOURCE_DIR}/src")
|
||||
prepend(HB_BASE_RAGEL_GENERATED_sources "${PROJECT_SOURCE_DIR}/src/" ${HB_BASE_RAGEL_GENERATED_sources})
|
||||
prepend(HB_OT_RAGEL_GENERATED_sources "${PROJECT_SOURCE_DIR}/src/" ${HB_OT_RAGEL_GENERATED_sources})
|
||||
else ()
|
||||
extract_make_variable(HB_BASE_RAGEL_GENERATED_sources "${PROJECT_BINARY_DIR}/src")
|
||||
extract_make_variable(HB_OT_RAGEL_GENERATED_sources "${PROJECT_BINARY_DIR}/src")
|
||||
prepend(HB_BASE_RAGEL_GENERATED_sources "${PROJECT_BINARY_DIR}/src/" ${HB_BASE_RAGEL_GENERATED_sources})
|
||||
prepend(HB_OT_RAGEL_GENERATED_sources "${PROJECT_BINARY_DIR}/src/" ${HB_OT_RAGEL_GENERATED_sources})
|
||||
endif ()
|
||||
prepend(HB_VIEW_sources "${PROJECT_SOURCE_DIR}/util/" ${HB_VIEW_sources})
|
||||
prepend(HB_SHAPE_sources "${PROJECT_SOURCE_DIR}/util/" ${HB_SHAPE_sources})
|
||||
prepend(HB_OT_SHAPE_CLOSURE_sources "${PROJECT_SOURCE_DIR}/util/" ${HB_OT_SHAPE_CLOSURE_sources})
|
||||
|
||||
file(READ configure.ac CONFIGUREAC)
|
||||
string(REGEX MATCH "\\[(([0-9]+)\\.([0-9]+)\\.([0-9]+))\\]" HB_VERSION_MATCH ${CONFIGUREAC})
|
||||
set(HB_VERSION ${CMAKE_MATCH_1})
|
||||
set(HB_VERSION_MAJOR ${CMAKE_MATCH_2})
|
||||
set(HB_VERSION_MINOR ${CMAKE_MATCH_3})
|
||||
set(HB_VERSION_MICRO ${CMAKE_MATCH_4})
|
||||
##
|
||||
|
||||
if (NOT IN_HB_DIST)
|
||||
## execute ragel tasks
|
||||
## Define ragel tasks
|
||||
find_program(RAGEL "ragel")
|
||||
|
||||
if (RAGEL)
|
||||
|
@ -97,13 +133,6 @@ if (NOT IN_HB_DIST)
|
|||
##
|
||||
|
||||
## Generate hb-version.h
|
||||
file(READ configure.ac CONFIGUREAC)
|
||||
string(REGEX MATCH "\\[(([0-9]+)\\.([0-9]+)\\.([0-9]+))\\]" HB_VERSION_MATCH ${CONFIGUREAC})
|
||||
set(HB_VERSION ${CMAKE_MATCH_1})
|
||||
set(HB_VERSION_MAJOR ${CMAKE_MATCH_2})
|
||||
set(HB_VERSION_MINOR ${CMAKE_MATCH_3})
|
||||
set(HB_VERSION_MICRO ${CMAKE_MATCH_4})
|
||||
|
||||
set(HB_VERSION_H_IN "${PROJECT_SOURCE_DIR}/src/hb-version.h.in")
|
||||
set(HB_VERSION_H "${PROJECT_BINARY_DIR}/src/hb-version.h")
|
||||
set_source_files_properties("${HB_VERSION_H}" PROPERTIES GENERATED true)
|
||||
|
@ -115,7 +144,7 @@ if (NOT IN_HB_DIST)
|
|||
##
|
||||
endif ()
|
||||
|
||||
## Define source and headers of projects
|
||||
## Define sources and headers of the project
|
||||
set(project_sources
|
||||
${HB_BASE_sources}
|
||||
${HB_BASE_RAGEL_GENERATED_sources}
|
||||
|
@ -157,60 +186,75 @@ if (HB_HAVE_FREETYPE)
|
|||
endif ()
|
||||
|
||||
if (FREETYPE_INCLUDE_DIR AND FREETYPE_ACTUAL_LIBRARY)
|
||||
set(THIRD_PARTY_LIBS ${THIRD_PARTY_LIBS} ${FREETYPE_ACTUAL_LIBRARY})
|
||||
list(APPEND THIRD_PARTY_LIBS ${FREETYPE_ACTUAL_LIBRARY})
|
||||
add_definitions(-DHAVE_FREETYPE=1 -DHAVE_FT_FACE_GETCHARVARIANTINDEX=1)
|
||||
endif ()
|
||||
|
||||
set(project_sources ${project_sources} ${PROJECT_SOURCE_DIR}/src/hb-ft.cc)
|
||||
set(project_headers ${project_headers} ${PROJECT_SOURCE_DIR}/src/hb-ft.h)
|
||||
list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/hb-ft.cc)
|
||||
list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-ft.h)
|
||||
endif ()
|
||||
|
||||
if (HB_BUILTIN_UCDN)
|
||||
include_directories(src/hb-ucdn)
|
||||
add_definitions(-DHAVE_UCDN)
|
||||
|
||||
set(project_headers ${project_headers} ${PROJECT_SOURCE_DIR}/src/hb-ucdn/ucdn.h)
|
||||
|
||||
set(project_sources
|
||||
${project_sources}
|
||||
list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-ucdn/ucdn.h)
|
||||
|
||||
list(APPEND project_sources
|
||||
${PROJECT_SOURCE_DIR}/src/hb-ucdn.cc
|
||||
${PROJECT_SOURCE_DIR}/src/hb-ucdn/ucdn.c
|
||||
${PROJECT_SOURCE_DIR}/src/hb-ucdn/unicodedata_db.h)
|
||||
else ()
|
||||
add_definitions(-DHB_NO_UNICODE_FUNCS)
|
||||
endif ()
|
||||
|
||||
if (HB_HAVE_GLIB)
|
||||
add_definitions(-DHAVE_GLIB)
|
||||
|
||||
# https://github.com/WebKit/webkit/blob/master/Source/cmake/FindGLIB.cmake
|
||||
find_package(PkgConfig)
|
||||
pkg_check_modules(PC_GLIB QUIET glib-2.0)
|
||||
|
||||
find_library(GLIB_LIBRARIES NAMES glib-2.0 HINTS ${PC_GLIB_LIBDIR} ${PC_GLIB_LIBRARY_DIRS})
|
||||
find_path(GLIBCONFIG_INCLUDE_DIR NAMES glibconfig.h HINTS ${PC_LIBDIR} ${PC_LIBRARY_DIRS} ${PC_GLIB_INCLUDEDIR} ${PC_GLIB_INCLUDE_DIRS} PATH_SUFFIXES glib-2.0/include)
|
||||
find_path(GLIB_INCLUDE_DIR NAMES glib.h HINTS ${PC_GLIB_INCLUDEDIR} ${PC_GLIB_INCLUDE_DIRS} PATH_SUFFIXES glib-2.0)
|
||||
|
||||
include_directories(${GLIBCONFIG_INCLUDE_DIR} ${GLIB_INCLUDE_DIR})
|
||||
|
||||
list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/hb-glib.cc)
|
||||
list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-glib.h)
|
||||
|
||||
list(APPEND THIRD_PARTY_LIBS ${GLIB_LIBRARIES})
|
||||
endif ()
|
||||
|
||||
if (APPLE AND HB_HAVE_CORETEXT)
|
||||
# Apple Advanced Typography
|
||||
add_definitions(-DHAVE_CORETEXT)
|
||||
|
||||
set(project_sources ${project_sources} ${PROJECT_SOURCE_DIR}/src/hb-coretext.cc)
|
||||
set(project_headers ${project_headers} ${PROJECT_SOURCE_DIR}/src/hb-coretext.h)
|
||||
list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/hb-coretext.cc)
|
||||
list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-coretext.h)
|
||||
|
||||
find_library(APPLICATION_SERVICES_FRAMEWORK ApplicationServices)
|
||||
mark_as_advanced(APPLICATION_SERVICES_FRAMEWORK)
|
||||
if (APPLICATION_SERVICES_FRAMEWORK)
|
||||
set(THIRD_PARTY_LIBS ${THIRD_PARTY_LIBS} ${APPLICATION_SERVICES_FRAMEWORK})
|
||||
list(APPEND THIRD_PARTY_LIBS ${APPLICATION_SERVICES_FRAMEWORK})
|
||||
endif (APPLICATION_SERVICES_FRAMEWORK)
|
||||
endif ()
|
||||
|
||||
if (WIN32 AND HB_HAVE_UNISCRIBE)
|
||||
add_definitions(-DHAVE_UNISCRIBE)
|
||||
|
||||
set(project_sources ${project_sources} ${PROJECT_SOURCE_DIR}/src/hb-uniscribe.cc)
|
||||
set(project_headers ${project_headers} ${PROJECT_SOURCE_DIR}/src/hb-uniscribe.h)
|
||||
list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/hb-uniscribe.cc)
|
||||
list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-uniscribe.h)
|
||||
|
||||
set(THIRD_PARTY_LIBS ${THIRD_PARTY_LIBS} usp10 gdi32 rpcrt4)
|
||||
list(APPEND THIRD_PARTY_LIBS usp10 gdi32 rpcrt4)
|
||||
endif ()
|
||||
|
||||
if (WIN32 AND HB_HAVE_DIRECTWRITE)
|
||||
add_definitions(-DHAVE_DIRECTWRITE)
|
||||
|
||||
set(project_sources ${project_sources} ${PROJECT_SOURCE_DIR}/src/hb-directwrite.cc)
|
||||
set(project_headers ${project_headers} ${PROJECT_SOURCE_DIR}/src/hb-directwrite.h)
|
||||
list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/hb-directwrite.cc)
|
||||
list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-directwrite.h)
|
||||
|
||||
set(THIRD_PARTY_LIBS ${THIRD_PARTY_LIBS} dwrite rpcrt4)
|
||||
list(APPEND THIRD_PARTY_LIBS dwrite rpcrt4)
|
||||
endif ()
|
||||
|
||||
set(project_sources ${project_sources} ${project_headers})
|
||||
|
@ -219,6 +263,28 @@ set(project_sources ${project_sources} ${project_headers})
|
|||
add_library(harfbuzz ${project_sources})
|
||||
target_link_libraries(harfbuzz ${THIRD_PARTY_LIBS})
|
||||
|
||||
if (HB_BUILD_UTILS)
|
||||
# https://github.com/WebKit/webkit/blob/master/Source/cmake/FindCairo.cmake
|
||||
find_package(PkgConfig)
|
||||
pkg_check_modules(PC_CAIRO QUIET cairo)
|
||||
|
||||
find_path(CAIRO_INCLUDE_DIRS NAMES cairo.h HINTS ${PC_CAIRO_INCLUDEDIR} ${PC_CAIRO_INCLUDE_DIRS} PATH_SUFFIXES cairo)
|
||||
find_library(CAIRO_LIBRARIESNAMES cairo HINTS ${PC_CAIRO_LIBDIR} ${PC_CAIRO_LIBRARY_DIRS})
|
||||
|
||||
add_definitions("-DPACKAGE_NAME=\"HarfBuzz\"")
|
||||
add_definitions("-DPACKAGE_VERSION=\"${HB_VERSION}\"")
|
||||
include_directories(${CAIRO_INCLUDE_DIRS})
|
||||
|
||||
add_executable(hb-view ${HB_VIEW_sources})
|
||||
target_link_libraries(hb-view harfbuzz ${CAIRO_LIBRARIESNAMES})
|
||||
|
||||
add_executable(hb-shape ${HB_SHAPE_sources})
|
||||
target_link_libraries(hb-shape harfbuzz)
|
||||
|
||||
add_executable(hb-ot-shape-closure ${HB_OT_SHAPE_CLOSURE_sources})
|
||||
target_link_libraries(hb-ot-shape-closure harfbuzz)
|
||||
endif ()
|
||||
|
||||
## Install
|
||||
if (NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL)
|
||||
install(FILES ${project_headers} DESTINATION include/harfbuzz)
|
||||
|
|
Loading…
Reference in New Issue