CMake Lists
CMake Lists
CMake Lists
0)
project(harfbuzz)
enable_testing()
## Disallow in-source builds, as CMake generated make files can collide with
autotools ones
if (NOT MSVC AND "${PROJECT_BINARY_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}")
message(FATAL_ERROR
"
In-source builds are not permitted! Make a separate folder for"
" building, e.g.,"
"
mkdir build; cd build; cmake .."
"
Before that, remove the files created by this failed run with"
"
rm -rf CMakeCache.txt CMakeFiles")
endif ()
option(HB_CHECK OFF "Do a configuration suitable for testing (shared library and
enable all options)")
if (HB_CHECK)
set (BUILD_SHARED_LIBS ON)
set (HB_BUILD_UTILS ON)
set (HB_BUILTIN_UCDN ON)
set (HB_HAVE_ICU)
set (HB_HAVE_GLIB ON)
#set (HB_HAVE_GOBJECT ON)
#set (HB_HAVE_INTROSPECTION ON)
set (HB_HAVE_FREETYPE ON)
set (HB_HAVE_GRAPHITE2 ON)
if (WIN32)
set (HB_HAVE_UNISCRIBE ON)
set (HB_HAVE_DIRECTWRITE ON)
elseif (APPLE)
set (HB_HAVE_CORETEXT ON)
endif ()
endif ()
include_directories(AFTER
${PROJECT_SOURCE_DIR}/src
${PROJECT_BINARY_DIR}/src
)
add_definitions(-DHAVE_OT)
add_definitions(-DHAVE_FALLBACK)
if (MSVC)
add_definitions(-wd4244 -wd4267 -D_CRT_SECURE_NO_WARNINGS
-D_CRT_NONSTDC_NO_WARNINGS)
endif ()
if (BUILD_SHARED_LIBS)
if (WIN32 AND NOT MINGW)
add_definitions("-DHB_EXTERN=__declspec(dllexport) extern")
else ()
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden")
endif ()
endif ()
# http://stackoverflow.com/a/27630120
function (add_prefix_to_list var prefix)
set (listVar "")
foreach (f ${${var}})
list(APPEND listVar "${prefix}${f}")
endforeach ()
set (${var} "${listVar}" PARENT_SCOPE)
endfunction ()
extract_make_variable(HB_BASE_sources ${SRCSOURCES})
add_prefix_to_list(HB_BASE_sources "${PROJECT_SOURCE_DIR}/src/")
extract_make_variable(HB_BASE_headers ${SRCSOURCES})
add_prefix_to_list(HB_BASE_headers "${PROJECT_SOURCE_DIR}/src/")
extract_make_variable(HB_FALLBACK_sources ${SRCSOURCES})
add_prefix_to_list(HB_FALLBACK_sources "${PROJECT_SOURCE_DIR}/src/")
extract_make_variable(HB_OT_sources ${SRCSOURCES})
add_prefix_to_list(HB_OT_sources "${PROJECT_SOURCE_DIR}/src/")
extract_make_variable(HB_OT_headers ${SRCSOURCES})
add_prefix_to_list(HB_OT_headers "${PROJECT_SOURCE_DIR}/src/")
extract_make_variable(HB_SUBSET_sources ${SRCSOURCES})
add_prefix_to_list(HB_SUBSET_sources "${PROJECT_SOURCE_DIR}/src/")
extract_make_variable(HB_SUBSET_headers ${SRCSOURCES})
add_prefix_to_list(HB_SUBSET_headers "${PROJECT_SOURCE_DIR}/src/")
extract_make_variable(HB_BASE_RAGEL_GENERATED_sources ${SRCSOURCES})
extract_make_variable(HB_OT_RAGEL_GENERATED_sources ${SRCSOURCES})
#if (IN_HB_DIST)
add_prefix_to_list(HB_BASE_RAGEL_GENERATED_sources "${PROJECT_SOURCE_DIR}/src/")
add_prefix_to_list(HB_OT_RAGEL_GENERATED_sources "${PROJECT_SOURCE_DIR}/src/")
#else ()
# add_prefix_to_list(HB_BASE_RAGEL_GENERATED_sources "${PROJECT_BINARY_DIR}/src/")
# add_prefix_to_list(HB_OT_RAGEL_GENERATED_sources "${PROJECT_BINARY_DIR}/src/")
#endif ()
extract_make_variable(HB_VIEW_sources ${UTILSOURCES})
add_prefix_to_list(HB_VIEW_sources "${PROJECT_SOURCE_DIR}/util/")
extract_make_variable(HB_SHAPE_sources ${UTILSOURCES})
add_prefix_to_list(HB_SHAPE_sources "${PROJECT_SOURCE_DIR}/util/")
extract_make_variable(HB_SUBSET_CLI_sources ${UTILSOURCES})
add_prefix_to_list(HB_SUBSET_CLI_sources "${PROJECT_SOURCE_DIR}/util/")
extract_make_variable(HB_OT_SHAPE_CLOSURE_sources ${UTILSOURCES})
add_prefix_to_list(HB_OT_SHAPE_CLOSURE_sources "${PROJECT_SOURCE_DIR}/util/")
extract_make_variable(LIBHB_UCDN_sources ${UCDNSOURCES})
add_prefix_to_list(LIBHB_UCDN_sources "${PROJECT_SOURCE_DIR}/src/hb-ucdn/")
# mark_as_advanced(RAGEL)
# endif ()
## Generate hb-version.h
# if (NOT IN_HB_DIST)
# 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)
# configure_file("${HB_VERSION_H_IN}" "${HB_VERSION_H}.tmp" @ONLY)
# execute_process(COMMAND "${CMAKE_COMMAND}" -E copy_if_different
# "${HB_VERSION_H}.tmp"
# "${HB_VERSION_H}"
# )
# file(REMOVE "${HB_VERSION_H}.tmp")
# endif ()
${HB_FALLBACK_sources}
${HB_OT_sources}
${HB_OT_RAGEL_GENERATED_sources}
)
set (subset_project_sources
${HB_SUBSET_sources}
)
set (project_extra_sources)
set (project_headers
#${HB_VERSION_H}
${HB_BASE_headers}
${HB_OT_headers}
)
set (subset_project_headers
${HB_SUBSET_headers}
)
if (HB_HAVE_GRAPHITE2)
add_definitions(-DHAVE_GRAPHITE2)
find_path(GRAPHITE2_INCLUDE_DIR graphite2/Font.h)
find_library(GRAPHITE2_LIBRARY graphite2)
include_directories(${GRAPHITE2_INCLUDE_DIR})
mark_as_advanced(GRAPHITE2_INCLUDE_DIR GRAPHITE2_LIBRARY)
endif ()
if (HB_BUILTIN_UCDN)
include_directories(src/hb-ucdn)
add_definitions(-DHAVE_UCDN)
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)
include_directories(${GLIBCONFIG_INCLUDE_DIR} ${GLIB_INCLUDE_DIR})
if (HB_HAVE_ICU)
add_definitions(-DHAVE_ICU)
# https://github.com/WebKit/webkit/blob/master/Source/cmake/FindICU.cmake
find_package(PkgConfig)
pkg_check_modules(PC_ICU QUIET icu-uc)
include_directories(${ICU_INCLUDE_DIR})
list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/hb-icu.cc)
list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-icu.h)
mark_as_advanced(ICU_INCLUDE_DIR ICU_LIBRARY)
endif ()
find_library(APPLICATION_SERVICES_FRAMEWORK ApplicationServices)
if (APPLICATION_SERVICES_FRAMEWORK)
list(APPEND THIRD_PARTY_LIBS ${APPLICATION_SERVICES_FRAMEWORK})
endif (APPLICATION_SERVICES_FRAMEWORK)
mark_as_advanced(APPLICATION_SERVICES_FRAMEWORK)
endif ()
if (HB_HAVE_GOBJECT)
include (FindPythonInterp)
include (FindPerl)
include_directories(${GOBJECTCONFIG_INCLUDE_DIR} ${GOBJECT_INCLUDE_DIR})
mark_as_advanced(GOBJECT_LIBRARIES GOBJECT_INCLUDE_DIR)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/src/hb-gobject-enums.h
COMMAND ${GLIB_MKENUMS_CMD}
--template=${PROJECT_SOURCE_DIR}/src/hb-gobject-enums.h.tmpl
--identifier-prefix hb_
--symbol-prefix hb_gobject
${hb_gobject_structs_headers}
${project_headers}
> ${CMAKE_CURRENT_BINARY_DIR}/src/hb-gobject-enums.h.tmp
COMMAND "${CMAKE_COMMAND}"
"-DENUM_INPUT_SRC=${CMAKE_CURRENT_BINARY_DIR}/src/hb-gobject-enums.h.tmp"
"-DENUM_OUTPUT_SRC=${CMAKE_CURRENT_BINARY_DIR}/src/hb-gobject-enums.h"
-P ${PROJECT_SOURCE_DIR}/replace-enum-strings.cmake
DEPENDS ${PROJECT_SOURCE_DIR}/src/hb-gobject-enums.h.tmpl
${hb_gobject_header}
${project_headers}
)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/src/hb-gobject-enums.cc
COMMAND ${GLIB_MKENUMS_CMD}
--template=${PROJECT_SOURCE_DIR}/src/hb-gobject-enums.cc.tmpl
--identifier-prefix hb_
--symbol-prefix hb_gobject
${hb_gobject_header}
${project_headers}
> ${CMAKE_CURRENT_BINARY_DIR}/src/hb-gobject-enums.cc.tmp
COMMAND "${CMAKE_COMMAND}"
"-DENUM_INPUT_SRC=${CMAKE_CURRENT_BINARY_DIR}/src/hb-gobject-enums.cc.tmp"
"-DENUM_OUTPUT_SRC=${CMAKE_CURRENT_BINARY_DIR}/src/hb-gobject-enums.cc"
-P ${PROJECT_SOURCE_DIR}/replace-enum-strings.cmake
DEPENDS ${PROJECT_SOURCE_DIR}/src/hb-gobject-enums.cc.tmpl
${CMAKE_CURRENT_BINARY_DIR}/src/hb-gobject-enums.h
${hb_gobject_header}
${project_headers}
)
endif ()
file(WRITE "${PROJECT_BINARY_DIR}/try_compile_solaris_atomic_ops.c"
" #include <atomic.h>
/* This requires Solaris Studio 12.2 or newer: */
#include <mbarrier.h>
void memory_barrier (void) { __machine_rw_barrier (); }
int atomic_add (volatile unsigned *i) { return atomic_add_int_nv (i,
1); }
void *atomic_ptr_cmpxchg (volatile void **target, void *cmp, void
*newval) { return atomic_cas_ptr (target, cmp, newval); }
int main () { return 0; }
")
try_compile(HB_HAVE_SOLARIS_ATOMIC_OPS
${PROJECT_BINARY_DIR}/try_compile_solaris_atomic_ops
${PROJECT_BINARY_DIR}/try_compile_solaris_atomic_ops.c)
if (HB_HAVE_SOLARIS_ATOMIC_OPS)
add_definitions(-DHAVE_SOLARIS_ATOMIC_OPS)
endif ()
if (UNIX OR MINGW)
# Make symbols link locally
link_libraries(-Bsymbolic-functions)
find_package(PkgConfig)
pkg_check_modules(PC_GI QUIET gobject-introspection-1.0)
find_program(G_IR_SCANNER g-ir-scanner
HINTS ${PC_g_ir_scanner}
)
find_program(G_IR_COMPILER g-ir-compiler
HINTS ${PC_g_ir_compiler}
)
set (introspected_sources)
foreach (f
${project_headers}
${project_sources}
${hb_gobject_gen_sources}
${hb_gobject_gen_headers}
${hb_gobject_sources}
${hb_gobject_headers}
)
if (WIN32)
# Nasty issue: We need to make drive letters lower case,
# otherwise g-ir-scanner won't like it and give us a bunch
# of invalid items and unresolved types...
STRING(SUBSTRING "${f}" 0 1 drive)
STRING(SUBSTRING "${f}" 1 -1 path)
if (drive MATCHES "[A-Z]")
STRING(TOLOWER ${drive} drive_lower)
list(APPEND introspected_sources "${drive_lower}${path}")
else ()
list(APPEND introspected_sources "${f}")
endif ()
else ()
list(APPEND introspected_sources "${f}")
endif ()
endforeach ()
add_custom_command(
TARGET harfbuzz-gobject
POST_BUILD
COMMAND "${G_IR_COMPILER}"
--verbose --debug
--includedir ${CMAKE_CURRENT_BINARY_DIR}
${hb_libpath}/HarfBuzz-0.0.gir
-o ${hb_libpath}/HarfBuzz-0.0.typelib
DEPENDS ${hb_libpath}/HarfBuzz-0.0.gir harfbuzz-gobject
)
endif ()
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-subset ${HB_SUBSET_CLI_sources})
target_link_libraries(hb-subset harfbuzz harfbuzz-subset)
add_executable(hb-ot-shape-closure ${HB_OT_SHAPE_CLOSURE_sources})
target_link_libraries(hb-ot-shape-closure harfbuzz)
mark_as_advanced(CAIRO_INCLUDE_DIRS CAIRO_LIBRARIESNAMES)
endif ()
## Install
include (GNUInstallDirs)
install(TARGETS hb-shape
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(TARGETS hb-ot-shape-closure
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif ()
if (HB_HAVE_GOBJECT)
install(TARGETS harfbuzz-gobject
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
if (HB_HAVE_INTROSPECTION)
if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio*")
set (hb_libpath "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>")
else ()
set (hb_libpath "$<TARGET_FILE_DIR:harfbuzz-gobject>")
endif ()
install(FILES "${hb_libpath}/HarfBuzz-0.0.gir"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/gir-1.0
)
install(FILES "${hb_libpath}/HarfBuzz-0.0.typelib"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/girepository-1.0
)
endif ()
endif ()
endif ()