| 1 |
# Distributed under the original FontForge BSD 3-clause license |
| 2 |
|
| 3 |
# Enable generator expressions in install(CODE) |
| 4 |
cmake_policy(SET CMP0087 NEW) |
| 5 |
|
| 6 |
add_library(fontforge_pyhook MODULE fontforgepyhook.c) |
| 7 |
add_library(psMat_pyhook MODULE psMatpyhook.c) |
| 8 |
|
| 9 |
set_target_properties(fontforge_pyhook PROPERTIES OUTPUT_NAME "fontforge" PREFIX "") |
| 10 |
set_target_properties(psMat_pyhook PROPERTIES OUTPUT_NAME "psMat" PREFIX "") |
| 11 |
|
| 12 |
if(WIN32) |
| 13 |
set_target_properties(fontforge_pyhook PROPERTIES SUFFIX ".pyd") |
| 14 |
set_target_properties(psMat_pyhook PROPERTIES SUFFIX ".pyd") |
| 15 |
# Put import libraries in a subdirectory to avoid collision with fontforge.lib from the main DLL |
| 16 |
set_target_properties(fontforge_pyhook psMat_pyhook PROPERTIES |
| 17 |
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/pyhook") |
| 18 |
endif() |
| 19 |
|
| 20 |
target_link_libraries(fontforge_pyhook PRIVATE fontforge Python3::Module) |
| 21 |
target_link_libraries(psMat_pyhook PRIVATE fontforge Python3::Module) |
| 22 |
|
| 23 |
if(BUILDING_WHEEL) |
| 24 |
# Wheel build: modules find libfontforge in same directory via $ORIGIN RPATH |
| 25 |
if(NOT WIN32) |
| 26 |
set_target_properties(fontforge_pyhook psMat_pyhook PROPERTIES |
| 27 |
INSTALL_RPATH "$ORIGIN" |
| 28 |
BUILD_WITH_INSTALL_RPATH TRUE |
| 29 |
) |
| 30 |
endif() |
| 31 |
# scikit-build-core handles install location via CMAKE_INSTALL_PREFIX |
| 32 |
install(TARGETS fontforge_pyhook psMat_pyhook LIBRARY DESTINATION ".") |
| 33 |
else() |
| 34 |
# System install: use Python's site-packages |
| 35 |
# FindPython3 provides Python3_SITEARCH, but this is an absolute path |
| 36 |
# So do it ourselves, getting the prefix-relative path instead |
| 37 |
if(NOT DEFINED PYHOOK_INSTALL_DIR) |
| 38 |
if(APPLE) |
| 39 |
set(_PLATFORM "APPLE") |
| 40 |
endif() |
| 41 |
execute_process( |
| 42 |
COMMAND "${Python3_EXECUTABLE}" |
| 43 |
"${CMAKE_CURRENT_LIST_DIR}/get_pyhook_install_dir.py" |
| 44 |
"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}" |
| 45 |
"${_PLATFORM}" |
| 46 |
RESULT_VARIABLE _pyhook_install_dir_result |
| 47 |
OUTPUT_VARIABLE PYHOOK_INSTALL_DIR |
| 48 |
OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 49 |
if(NOT PYHOOK_INSTALL_DIR OR _pyhook_install_dir_result) |
| 50 |
message(FATAL_ERROR "Could not determine the path to install pyhook binaries to, got '${PYHOOK_INSTALL_DIR}' with return value ${_pyhook_install_dir_result}") |
| 51 |
endif() |
| 52 |
set(PYHOOK_INSTALL_DIR "${PYHOOK_INSTALL_DIR}" CACHE STRING "Path to install pyhook to") |
| 53 |
endif() |
| 54 |
|
| 55 |
# Check at install time if pip-installed modules should be preserved |
| 56 |
# We check the INSTALLER file in dist-info to determine the install source: |
| 57 |
# - "pip" or other package managers → skip, preserve pip install |
| 58 |
# - "fontforge-app" → proceed, update previous app install |
| 59 |
# - no dist-info → fresh install, proceed |
| 60 |
install(CODE " |
| 61 |
set(_python_exe \"${Python3_EXECUTABLE}\") |
| 62 |
set(_skip_pyhook FALSE) |
| 63 |
# Handle DESTDIR for staged installs (AppImage, packaging) |
| 64 |
set(_destdir \"\$ENV{DESTDIR}\") |
| 65 |
set(_dest \"\${_destdir}\${CMAKE_INSTALL_PREFIX}/${PYHOOK_INSTALL_DIR}\") |
| 66 |
|
| 67 |
# Look for existing fontforge dist-info directory |
| 68 |
file(GLOB _existing_distinfo \"\${_dest}/fontforge-*.dist-info\") |
| 69 |
|
| 70 |
if(_existing_distinfo) |
| 71 |
# Get the first match (should only be one) |
| 72 |
list(GET _existing_distinfo 0 _distinfo_dir) |
| 73 |
set(_installer_file \"\${_distinfo_dir}/INSTALLER\") |
| 74 |
|
| 75 |
if(EXISTS \"\${_installer_file}\") |
| 76 |
file(READ \"\${_installer_file}\" _installer_content) |
| 77 |
string(STRIP \"\${_installer_content}\" _installer_content) |
| 78 |
|
| 79 |
if(_installer_content STREQUAL \"fontforge-app\") |
| 80 |
message(STATUS \"Existing fontforge module was installed by app, will be updated\") |
| 81 |
else() |
| 82 |
message(STATUS \"Existing fontforge module was installed by '\${_installer_content}', skipping Python module installation\") |
| 83 |
message(STATUS \"To reinstall app modules, first run: pip uninstall fontforge\") |
| 84 |
set(_skip_pyhook TRUE) |
| 85 |
endif() |
| 86 |
else() |
| 87 |
# dist-info exists but no INSTALLER file - treat as external install |
| 88 |
message(STATUS \"Existing fontforge dist-info found without INSTALLER file, skipping Python module installation\") |
| 89 |
message(STATUS \"To reinstall app modules, first run: pip uninstall fontforge\") |
| 90 |
set(_skip_pyhook TRUE) |
| 91 |
endif() |
| 92 |
endif() |
| 93 |
|
| 94 |
if(NOT _skip_pyhook) |
| 95 |
set(_version \"${FONTFORGE_PYTHON_VERSION}\") |
| 96 |
|
| 97 |
# Remove any existing app-installed dist-info (handles version upgrades) |
| 98 |
if(_existing_distinfo) |
| 99 |
foreach(_old_distinfo IN LISTS _existing_distinfo) |
| 100 |
message(STATUS \"Removing old dist-info: \${_old_distinfo}\") |
| 101 |
file(REMOVE_RECURSE \"\${_old_distinfo}\") |
| 102 |
endforeach() |
| 103 |
endif() |
| 104 |
|
| 105 |
# Install the module files |
| 106 |
file(INSTALL |
| 107 |
DESTINATION \"${CMAKE_INSTALL_PREFIX}/${PYHOOK_INSTALL_DIR}\" |
| 108 |
TYPE MODULE |
| 109 |
FILES |
| 110 |
\"$<TARGET_FILE:fontforge_pyhook>\" |
| 111 |
\"$<TARGET_FILE:psMat_pyhook>\" |
| 112 |
) |
| 113 |
|
| 114 |
# Create dist-info directory so pip recognizes this installation |
| 115 |
set(_distinfo \"\${_dest}/fontforge-\${_version}.dist-info\") |
| 116 |
file(MAKE_DIRECTORY \"\${_distinfo}\") |
| 117 |
|
| 118 |
# METADATA - minimal package metadata |
| 119 |
file(WRITE \"\${_distinfo}/METADATA\" \"Metadata-Version: 2.1 |
| 120 |
Name: fontforge |
| 121 |
Version: \${_version} |
| 122 |
Summary: FontForge font editor - Python bindings (installed with app) |
| 123 |
Home-page: https://fontforge.org |
| 124 |
License: GPL-3.0-or-later |
| 125 |
\") |
| 126 |
|
| 127 |
# INSTALLER - marks this as installed by the app, not pip |
| 128 |
file(WRITE \"\${_distinfo}/INSTALLER\" \"fontforge-app\") |
| 129 |
|
| 130 |
# top_level.txt - which top-level modules are installed |
| 131 |
file(WRITE \"\${_distinfo}/top_level.txt\" \"fontforge |
| 132 |
psMat |
| 133 |
\") |
| 134 |
|
| 135 |
# RECORD - list of installed files (with empty hashes, which is allowed) |
| 136 |
# Get the actual filenames |
| 137 |
get_filename_component(_ff_name \"$<TARGET_FILE:fontforge_pyhook>\" NAME) |
| 138 |
get_filename_component(_psmat_name \"$<TARGET_FILE:psMat_pyhook>\" NAME) |
| 139 |
file(WRITE \"\${_distinfo}/RECORD\" \"\${_ff_name},, |
| 140 |
\${_psmat_name},, |
| 141 |
fontforge-\${_version}.dist-info/METADATA,, |
| 142 |
fontforge-\${_version}.dist-info/INSTALLER,, |
| 143 |
fontforge-\${_version}.dist-info/top_level.txt,, |
| 144 |
fontforge-\${_version}.dist-info/RECORD,, |
| 145 |
\") |
| 146 |
|
| 147 |
message(STATUS \"Created fontforge-\${_version}.dist-info for pip compatibility\") |
| 148 |
endif() |
| 149 |
") |
| 150 |
endif() |