| 1 | cmake_minimum_required(VERSION 3.16) |
| 2 | project(fortty LANGUAGES Fortran C) |
| 3 | |
| 4 | # C standard for GLAD |
| 5 | set(CMAKE_C_STANDARD 11) |
| 6 | set(CMAKE_C_STANDARD_REQUIRED ON) |
| 7 | |
| 8 | # Compiler warnings |
| 9 | if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") |
| 10 | add_compile_options(-Wall -Wextra -pedantic) |
| 11 | endif() |
| 12 | |
| 13 | # Find dependencies |
| 14 | find_package(glfw3 REQUIRED) |
| 15 | find_package(OpenGL REQUIRED) |
| 16 | find_package(Freetype REQUIRED) |
| 17 | |
| 18 | # Optional: fontconfig for portable font discovery |
| 19 | find_package(PkgConfig) |
| 20 | if(PkgConfig_FOUND) |
| 21 | pkg_check_modules(FONTCONFIG fontconfig) |
| 22 | endif() |
| 23 | |
| 24 | # C helper libraries (GLAD + FreeType + PTY wrappers) |
| 25 | add_library(helpers STATIC |
| 26 | src/gl/glad.c |
| 27 | c_src/gl_loader.c |
| 28 | c_src/freetype_helpers.c |
| 29 | c_src/pty_helpers.c |
| 30 | ) |
| 31 | target_include_directories(helpers PUBLIC ${CMAKE_SOURCE_DIR}/include) |
| 32 | target_include_directories(helpers PRIVATE ${FREETYPE_INCLUDE_DIRS}) |
| 33 | target_link_libraries(helpers PRIVATE glfw ${FREETYPE_LIBRARIES} util) |
| 34 | |
| 35 | # Link fontconfig if available |
| 36 | if(FONTCONFIG_FOUND) |
| 37 | target_compile_definitions(helpers PRIVATE HAVE_FONTCONFIG) |
| 38 | target_include_directories(helpers PRIVATE ${FONTCONFIG_INCLUDE_DIRS}) |
| 39 | target_link_libraries(helpers PRIVATE ${FONTCONFIG_LIBRARIES}) |
| 40 | message(STATUS "Fontconfig found - enabling portable font discovery") |
| 41 | else() |
| 42 | message(STATUS "Fontconfig not found - using hardcoded font paths") |
| 43 | endif() |
| 44 | |
| 45 | # Fortran module output directory |
| 46 | set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/modules) |
| 47 | |
| 48 | # Fortran sources (order matters for module dependencies) |
| 49 | set(FORTRAN_SOURCES |
| 50 | src/core/types.f90 |
| 51 | src/gl/gl_bindings.f90 |
| 52 | src/text/glyph.f90 |
| 53 | src/gl/shader.f90 |
| 54 | src/text/font.f90 |
| 55 | src/text/atlas.f90 |
| 56 | src/text/renderer.f90 |
| 57 | src/terminal/cell.f90 |
| 58 | src/config/toml_parser.f90 |
| 59 | src/config/config.f90 |
| 60 | src/terminal/screen.f90 |
| 61 | src/terminal/cursor.f90 |
| 62 | src/terminal/scrollback.f90 |
| 63 | src/terminal/terminal.f90 |
| 64 | src/terminal/parser.f90 |
| 65 | src/pty/pty_bindings.f90 |
| 66 | src/pty/pty.f90 |
| 67 | src/window/glfw_bindings.f90 |
| 68 | src/window/window.f90 |
| 69 | src/fortty.f90 |
| 70 | ) |
| 71 | |
| 72 | # Main executable |
| 73 | add_executable(fortty ${FORTRAN_SOURCES}) |
| 74 | target_include_directories(fortty PRIVATE ${CMAKE_BINARY_DIR}/modules) |
| 75 | target_link_libraries(fortty PRIVATE helpers glfw OpenGL::GL ${FREETYPE_LIBRARIES}) |
| 76 | |
| 77 | # For Linux, we need dl for GLAD's dlopen |
| 78 | if(UNIX AND NOT APPLE) |
| 79 | target_link_libraries(fortty PRIVATE dl) |
| 80 | endif() |
| 81 |