cmake_minimum_required(VERSION 3.15)
project(hush C)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
include(FetchContent)
include(GNUInstallDirs)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(SDL_SHARED OFF CACHE BOOL "" FORCE)
set(SDL_STATIC ON CACHE BOOL "" FORCE)
set(SDL_TEST OFF CACHE BOOL "" FORCE)
set(SDL_AUDIO OFF CACHE BOOL "" FORCE)
set(SDL_JOYSTICK OFF CACHE BOOL "" FORCE)
set(SDL_HAPTIC OFF CACHE BOOL "" FORCE)
set(SDL_SENSOR OFF CACHE BOOL "" FORCE)
FetchContent_Declare(
SDL2
GIT_REPOSITORY https://github.com/libsdl-org/SDL.git
GIT_TAG release-2.32.10
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(SDL2)
set(SDL2TTF_VENDORED ON CACHE BOOL "" FORCE)
set(SDL2TTF_HARFBUZZ OFF CACHE BOOL "" FORCE)
FetchContent_Declare(
SDL2_ttf
GIT_REPOSITORY https://github.com/libsdl-org/SDL_ttf.git
GIT_TAG release-2.24.0
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(SDL2_ttf)
# SDL2_image is never functionally exercised by hush (no image rendering) -- it's linked solely
# because the vendored Clay SDL2 renderer's #include <SDL_image.h> needs the headers to resolve.
# The heavier optional formats are turned off since nothing here ever loads an image.
set(SDL2IMAGE_VENDORED ON CACHE BOOL "" FORCE)
set(SDL2IMAGE_AVIF OFF CACHE BOOL "" FORCE)
set(SDL2IMAGE_TIF OFF CACHE BOOL "" FORCE)
set(SDL2IMAGE_WEBP OFF CACHE BOOL "" FORCE)
FetchContent_Declare(
SDL2_image
GIT_REPOSITORY https://github.com/libsdl-org/SDL_image.git
GIT_TAG release-2.8.12
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(SDL2_image)
add_executable(hush
src/clay_impl.c
src/strbuf.c
src/document.c
src/inline_parse.c
src/wrap.c
src/fonts.c
src/layout_cache.c
src/hittest.c
src/theme.c
src/undo.c
src/keymap.c
src/config.c
src/lang.c
src/paths.c
src/editor.c
src/block_type_menu.c
src/image_cache.c
src/render.c
src/markdown_io.c
src/main.c
)
target_include_directories(hush PRIVATE vendor)
target_link_libraries(hush PRIVATE SDL2::SDL2-static SDL2_ttf::SDL2_ttf-static SDL2_image::SDL2_image-static m)
target_compile_definitions(hush PRIVATE ASSETS_DIR="${CMAKE_SOURCE_DIR}/assets")
if (UNIX AND NOT APPLE)
target_link_libraries(hush PRIVATE dl pthread)
endif()
target_compile_options(hush PRIVATE -Wall -Wextra -Wno-unused-parameter)
if(APPLE)
set_source_files_properties(
"${CMAKE_SOURCE_DIR}/Hush.icns"
PROPERTIES MACOSX_PACKAGE_LOCATION Resources
)
target_sources(hush PRIVATE "${CMAKE_SOURCE_DIR}/Hush.icns")
set_target_properties(hush PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_BUNDLE_NAME "Hush"
MACOSX_BUNDLE_GUI_IDENTIFIER "com.hush.editor"
MACOSX_BUNDLE_ICON_FILE "Hush.icns"
)
endif()
# `cmake --install build` (or `sudo make install` from build/) puts hush on PATH: the binary
# goes to <prefix>/bin (CMAKE_INSTALL_PREFIX defaults to /usr/local, whose bin/ is already on
# PATH on virtually every Linux distro) and its fonts/language files go to
# <prefix>/share/hush/assets, found at runtime relative to the installed binary (see
# src/paths.c) -- so the install is fully relocatable and doesn't depend on this source tree
# still being around afterward. Pass -DCMAKE_INSTALL_PREFIX=$HOME/.local to install for just
# your user instead (no sudo needed, as long as ~/.local/bin is already on your PATH).
install(TARGETS hush
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(DIRECTORY assets/ DESTINATION ${CMAKE_INSTALL_DATADIR}/hush/assets)
# Headless logic test: no window/GPU context is created, so it can run in CI or over SSH.
add_executable(hush_test
src/clay_impl.c
src/strbuf.c
src/document.c
src/inline_parse.c
src/wrap.c
src/fonts.c
src/layout_cache.c
src/hittest.c
src/theme.c
src/undo.c
src/keymap.c
src/config.c
src/lang.c
src/paths.c
src/editor.c
src/block_type_menu.c
src/image_cache.c
src/render.c
src/markdown_io.c
src/test_main.c
)
target_include_directories(hush_test PRIVATE vendor)
target_link_libraries(hush_test PRIVATE SDL2::SDL2-static SDL2_ttf::SDL2_ttf-static SDL2_image::SDL2_image-static m)
target_compile_definitions(hush_test PRIVATE ASSETS_DIR="${CMAKE_SOURCE_DIR}/assets")
if (UNIX AND NOT APPLE)
target_link_libraries(hush_test PRIVATE dl pthread)
endif()