Skip to content

Commit 7c817e4

Browse files
committed
PORT: Create a MacOS bundle based on Epilog.
1 parent 19f18da commit 7c817e4

5 files changed

Lines changed: 156 additions & 47 deletions

File tree

cmake/port/Darwin.cmake

Lines changed: 67 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ endif()
105105

106106
if(BUILD_MACOS_BUNDLE)
107107
set(MACOS_APP "SWI-Prolog")
108+
set(EPILOG_APP "${MACOS_APP}")
108109

109110
if(MACOS_UNIVERSAL_BINARY)
110111
set(SWIPL_CPACK_ARCH fat)
@@ -115,46 +116,78 @@ if(BUILD_MACOS_BUNDLE)
115116
# up. See URL below for the defined variables.
116117
# https://cmake.org/cmake/help/latest/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.html
117118

118-
set(MACOSX_BUNDLE_BUNDLE_NAME "SWI-Prolog")
119-
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${SWIPL_VERSION_STRING}")
120-
121-
set(X11_ROOT /opt/X11)
122-
set(Freetype_ROOT /opt/X11)
123-
set(FontConfig_ROOT /opt/X11)
124-
125-
find_program(MACOS_DEPLOYQT NAMES macdeployqt)
126-
if(NOT MACOS_DEPLOYQT)
127-
find_package(Qt5 COMPONENTS Widgets REQUIRED)
128-
129-
get_target_property(uic_location Qt5::uic IMPORTED_LOCATION)
130-
get_filename_component( _dir ${uic_location} DIRECTORY)
131-
set(MACOS_DEPLOYQT "${_dir}/macdeployqt")
132-
if(NOT EXISTS ${MACOS_DEPLOYQT})
133-
message(FATAL_ERROR "Failed to locate macdeployqt executable: [${MACOS_DEPLOYQT}]")
119+
if(EPILOG)
120+
set(CPACK_GENERATOR "DragNDrop")
121+
set(SWIPL_APP_NAME SWI-Prolog)
122+
set(CPACK_BUNDLE_NAME "${SWIPL_APP_NAME}")
123+
set(CPACK_BUNDLE_EXECUTABLE "${EPILOG_APP}")
124+
set(CPACK_BUNDLE_VERSION "${SWIPL_VERSION_STRING}")
125+
126+
set(CPACK_BUNDLE_ICON "swipl.icns")
127+
set(CPACK_BUNDLE_IDENTIFIER "org.swi-prolog.app")
128+
set(CPACK_BUNDLE_COPYRIGHT "BSD-2")
129+
set(CPACK_BUNDLE_PLIST "${CMAKE_SOURCE_DIR}/desktop/Info.plist.in")
130+
131+
function(deploy)
132+
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME ZZRuntime)
133+
install(FILES ${CMAKE_SOURCE_DIR}/man/macosx/SWIapp.html
134+
DESTINATION .
135+
RENAME Readme.html)
136+
install(FILES ${CMAKE_SOURCE_DIR}/man/macosx/License.html
137+
DESTINATION .)
138+
139+
install(CODE "set(fixup_script ${CMAKE_SOURCE_DIR}/scripts/macosx_bundle_fixup.sh)
140+
")
141+
install(CODE [===[
142+
execute_process(COMMAND ln -sf SWI-Prolog swipl-win
143+
WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/SWI-Prolog.app/Contents/MacOS)
144+
execute_process(COMMAND ${fixup_script} --epilog ${CMAKE_INSTALL_PREFIX}/SWI-Prolog.app)
145+
]===])
146+
endfunction()
147+
148+
deploy()
149+
else(EPILOG) # Qt based swipl-win
150+
set(MACOSX_BUNDLE_BUNDLE_NAME "SWI-Prolog")
151+
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${SWIPL_VERSION_STRING}")
152+
153+
set(X11_ROOT /opt/X11)
154+
set(Freetype_ROOT /opt/X11)
155+
set(FontConfig_ROOT /opt/X11)
156+
157+
find_program(MACOS_DEPLOYQT NAMES macdeployqt)
158+
if(NOT MACOS_DEPLOYQT)
159+
find_package(Qt5 COMPONENTS Widgets REQUIRED)
160+
161+
get_target_property(uic_location Qt5::uic IMPORTED_LOCATION)
162+
get_filename_component( _dir ${uic_location} DIRECTORY)
163+
set(MACOS_DEPLOYQT "${_dir}/macdeployqt")
164+
if(NOT EXISTS ${MACOS_DEPLOYQT})
165+
message(FATAL_ERROR "Failed to locate macdeployqt executable: [${MACOS_DEPLOYQT}]")
166+
endif()
134167
endif()
135-
endif()
136168

137-
set(CPACK_GENERATOR "DragNDrop")
169+
set(CPACK_GENERATOR "DragNDrop")
138170

139-
function(deployqt)
140-
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME ZZRuntime)
141-
install(FILES ${CMAKE_SOURCE_DIR}/man/macosx/SWIapp.html
142-
DESTINATION .
143-
RENAME Readme.html)
144-
install(FILES ${CMAKE_SOURCE_DIR}/man/macosx/License.html
145-
DESTINATION .)
171+
function(deployqt)
172+
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME ZZRuntime)
173+
install(FILES ${CMAKE_SOURCE_DIR}/man/macosx/SWIapp.html
174+
DESTINATION .
175+
RENAME Readme.html)
176+
install(FILES ${CMAKE_SOURCE_DIR}/man/macosx/License.html
177+
DESTINATION .)
146178

147-
install(CODE "set(deployqt ${MACOS_DEPLOYQT})
179+
install(CODE "set(deployqt ${MACOS_DEPLOYQT})
148180
set(fixup_script ${CMAKE_SOURCE_DIR}/scripts/macosx_bundle_fixup.sh)
149181
")
150-
install(CODE [===[
151-
execute_process(COMMAND ln -sf SWI-Prolog swipl-win
152-
WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/SWI-Prolog.app/Contents/MacOS)
153-
execute_process(COMMAND ${fixup_script} --deployqt=${deployqt} ${CMAKE_INSTALL_PREFIX}/SWI-Prolog.app)
154-
]===])
155-
endfunction()
156-
157-
deployqt()
182+
install(CODE [===[
183+
execute_process(COMMAND ln -sf SWI-Prolog swipl-win
184+
WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/SWI-Prolog.app/Contents/MacOS)
185+
execute_process(COMMAND ${fixup_script} --deployqt=${deployqt} ${CMAKE_INSTALL_PREFIX}/SWI-Prolog.app)
186+
]===])
187+
endfunction()
188+
189+
deployqt()
190+
endif(EPILOG)
158191
endif()
159192

160193
set(CMAKE_MACOSX_RPATH ON)

desktop/make_icns.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
# Usage: ./make_icns.sh input.png output.icns
4+
5+
if [ $# -ne 2 ]; then
6+
echo "Usage: $0 input.png output.icns"
7+
exit 1
8+
fi
9+
10+
INPUT="$1"
11+
OUTPUT="$2"
12+
ICONSET_DIR="temp.iconset"
13+
14+
mkdir -p "$ICONSET_DIR"
15+
16+
# Generate only the essential sizes
17+
sips -z 16 16 "$INPUT" --out "$ICONSET_DIR/icon_16x16.png"
18+
sips -z 32 32 "$INPUT" --out "$ICONSET_DIR/icon_16x16@2x.png"
19+
sips -z 128 128 "$INPUT" --out "$ICONSET_DIR/icon_128x128.png"
20+
sips -z 256 256 "$INPUT" --out "$ICONSET_DIR/icon_128x128@2x.png"
21+
22+
# Optionally add 512x512 if desired
23+
# sips -z 512 512 "$INPUT" --out "$ICONSET_DIR/icon_256x256@2x.png"
24+
25+
# Convert to .icns
26+
iconutil -c icns "$ICONSET_DIR" -o "$OUTPUT"
27+
28+
# Clean up
29+
rm -rf "$ICONSET_DIR"
30+
31+
echo "Created $OUTPUT"

desktop/swipl-256.png

48.7 KB
Loading

scripts/macosx_bundle_fixup.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/sh
22

33
deployqt=
4+
epilog=no
45

56
usage()
67
{ echo "Usage: $0 [--deployqt=prog] app"
@@ -14,6 +15,10 @@ while [ $done = no ]; do
1415
deployqt="$(echo $1 | sed 's/--deployqt=//')"
1516
shift
1617
;;
18+
--epilog)
19+
epilog=yes
20+
shift
21+
;;
1722
--*)
1823
usage
1924
;;

src/CMakeLists.txt

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,11 @@ config_data_files()
410410
file(WRITE "${SWIPL_BIN_ROOT}/swipl.home" "home\n")
411411
file(WRITE "${SWIPL_BIN_ROOT}/src/swipl.home" "../home\n")
412412
file(WRITE "${SWIPL_BIN_ROOT}/packages/swipl.home" "../home\n")
413-
symlink_or_copy(${SWIPL_BOOT_ROOT}/build_home.pl ${SWIPL_BIN_ROOT}/home/swipl.rc)
414-
symlink_or_copy(${SWIPL_BOOT_ROOT}/build_home.pl ${SWIPL_BIN_ROOT}/home/swipl-win.rc)
413+
set(RC_FILES swipl swipl-win ${EPILOG_APP})
414+
list(REMOVE_DUPLICATES RC_FILES)
415+
foreach(rc ${RC_FILES})
416+
symlink_or_copy(${SWIPL_BOOT_ROOT}/build_home.pl ${SWIPL_BIN_ROOT}/home/${rc}.rc)
417+
endforeach()
415418
# Final swipl.home for installed system
416419
file(WRITE "${SWIPL_BIN_ROOT}/dot.txt" ".\n")
417420
file(WRITE "${SWIPL_BIN_ROOT}/dotdot.txt" "..\n")
@@ -460,16 +463,25 @@ if(MINGW)
460463
endif()
461464

462465
if(EPILOG)
463-
if(WIN32)
464-
add_executable(swipl-win WIN32 ${SWIPL_SRC} swipl.rc)
465-
else()
466-
add_executable(swipl-win ${SWIPL_SRC})
467-
endif()
468-
target_compile_options(swipl-win PRIVATE -DSWIPL_EPILOG)
469-
target_link_libraries(swipl-win ${SWIPL_LIBRARIES} libswipl)
470-
if(MINGW)
471-
target_link_options(swipl-win PRIVATE -municode)
472-
endif()
466+
if(NOT EPILOG_APP)
467+
set(EPILOG_APP swipl-win)
468+
endif()
469+
470+
if(WIN32)
471+
add_executable(${EPILOG_APP} WIN32 ${SWIPL_SRC} swipl.rc)
472+
elseif(BUILD_MACOS_BUNDLE)
473+
add_executable(${EPILOG_APP} MACOSX_BUNDLE ${SWIPL_SRC})
474+
set_target_properties(${EPILOG_APP} PROPERTIES
475+
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_SOURCE_DIR}/desktop/Info.plist.in")
476+
else()
477+
add_executable(${EPILOG_APP} ${SWIPL_SRC})
478+
endif()
479+
480+
target_compile_options(${EPILOG_APP} PRIVATE -DSWIPL_EPILOG)
481+
target_link_libraries(${EPILOG_APP} ${SWIPL_LIBRARIES} libswipl)
482+
if(MINGW)
483+
target_link_options(${EPILOG_APP} PRIVATE -municode)
484+
endif()
473485
endif()
474486

475487
# build the library
@@ -634,6 +646,28 @@ add_custom_target(
634646
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
635647
COMMENT "Create TAGS file for main sources")
636648

649+
# Build the MacOS icon file
650+
if(EPILOG AND APPLE)
651+
set(desktop ${CMAKE_SOURCE_DIR}/desktop)
652+
653+
set(ICNS_FILE ${CMAKE_CURRENT_BINARY_DIR}/swipl.icns)
654+
655+
add_custom_command(
656+
OUTPUT ${ICNS_FILE}
657+
COMMAND sh ${desktop}/make_icns.sh ${desktop}/swipl-256.png ${ICNS_FILE}
658+
DEPENDS ${desktop}/make_icns.sh ${desktop}/swipl-256.png
659+
COMMENT "Create MacOS icons"
660+
VERBATIM
661+
)
662+
663+
add_custom_target(generate_icns ALL DEPENDS ${ICNS_FILE})
664+
add_dependencies(${EPILOG_APP} generate_icns)
665+
666+
if(BUILD_MACOS_BUNDLE)
667+
install(FILES ${ICNS_FILE} DESTINATION ${SWIPL_INSTALL_RESOURCES})
668+
endif()
669+
endif()
670+
637671
# Create cmake config files
638672
include(CMakePackageConfigHelpers)
639673
write_basic_package_version_file(SWIPLConfigVersion.cmake
@@ -670,7 +704,13 @@ install(FILES ${SWIPL_BOOT_FILE} ${SWIPL_ABI_FILE}
670704
DESTINATION ${SWIPL_INSTALL_PREFIX}
671705
)
672706
if(EPILOG)
673-
install(TARGETS swipl-win RUNTIME DESTINATION ${SWIPL_INSTALL_ARCH_EXE})
707+
if(APPLE)
708+
install(TARGETS ${EPILOG_APP} BUNDLE DESTINATION .)
709+
else()
710+
install(
711+
TARGETS ${EPILOG_APP}
712+
RUNTIME DESTINATION ${SWIPL_INSTALL_ARCH_EXE})
713+
endif()
674714
endif()
675715

676716
if(MINGW)

0 commit comments

Comments
 (0)