| 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 | set(HELPER_SOURCES |
| 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 | |
| 32 | # macOS window helpers placeholder - blur requires Cocoa which conflicts with Fortran build |
| 33 | # TODO: Enable when CMake framework flag issue is resolved |
| 34 | |
| 35 | add_library(helpers STATIC ${HELPER_SOURCES}) |
| 36 | target_include_directories(helpers PUBLIC ${CMAKE_SOURCE_DIR}/include) |
| 37 | target_include_directories(helpers PRIVATE ${FREETYPE_INCLUDE_DIRS}) |
| 38 | target_link_libraries(helpers PRIVATE glfw ${FREETYPE_LIBRARIES}) |
| 39 | |
| 40 | # Link util library for PTY on Linux (not needed on macOS) |
| 41 | if(UNIX AND NOT APPLE) |
| 42 | target_link_libraries(helpers PRIVATE util) |
| 43 | endif() |
| 44 | |
| 45 | # Note: Cocoa framework linked at executable level to avoid flag conflicts with Fortran |
| 46 | |
| 47 | # Link fontconfig if available |
| 48 | if(FONTCONFIG_FOUND) |
| 49 | target_compile_definitions(helpers PRIVATE HAVE_FONTCONFIG) |
| 50 | target_include_directories(helpers PRIVATE ${FONTCONFIG_INCLUDE_DIRS}) |
| 51 | target_link_directories(helpers PRIVATE ${FONTCONFIG_LIBRARY_DIRS}) |
| 52 | target_link_libraries(helpers PRIVATE ${FONTCONFIG_LIBRARIES}) |
| 53 | message(STATUS "Fontconfig found - enabling portable font discovery") |
| 54 | else() |
| 55 | message(STATUS "Fontconfig not found - using hardcoded font paths") |
| 56 | endif() |
| 57 | |
| 58 | # Fortran module output directory |
| 59 | set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/modules) |
| 60 | |
| 61 | # Fortran sources (order matters for module dependencies) |
| 62 | set(FORTRAN_SOURCES |
| 63 | src/core/types.f90 |
| 64 | src/gl/gl_bindings.f90 |
| 65 | src/text/glyph.f90 |
| 66 | src/gl/shader.f90 |
| 67 | src/text/font.f90 |
| 68 | src/text/atlas.f90 |
| 69 | src/text/renderer.f90 |
| 70 | src/terminal/cell.f90 |
| 71 | src/terminal/wcwidth.f90 |
| 72 | src/config/toml_parser.f90 |
| 73 | src/config/config.f90 |
| 74 | src/terminal/screen.f90 |
| 75 | src/terminal/cursor.f90 |
| 76 | src/terminal/selection.f90 |
| 77 | src/terminal/scrollback.f90 |
| 78 | src/terminal/terminal.f90 |
| 79 | src/terminal/parser.f90 |
| 80 | src/pty/pty_bindings.f90 |
| 81 | src/pty/pty.f90 |
| 82 | src/window/glfw_bindings.f90 |
| 83 | src/window/window.f90 |
| 84 | src/panes/pane.f90 |
| 85 | src/panes/layout.f90 |
| 86 | src/tabs/tab_manager.f90 |
| 87 | src/tabs/tab_bar.f90 |
| 88 | src/fortty.f90 |
| 89 | ) |
| 90 | |
| 91 | # Main executable |
| 92 | add_executable(fortty ${FORTRAN_SOURCES}) |
| 93 | target_include_directories(fortty PRIVATE ${CMAKE_BINARY_DIR}/modules) |
| 94 | |
| 95 | # Work around CMake framework flag issue: flang doesn't understand -F flag |
| 96 | if(APPLE) |
| 97 | # Remove -F flags from Fortran compile options |
| 98 | string(REPLACE "-F/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks" "" |
| 99 | CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}") |
| 100 | # Also set a compile option filter for the target |
| 101 | set_target_properties(fortty PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "") |
| 102 | endif() |
| 103 | |
| 104 | # Link libraries - glfw linked through helpers |
| 105 | target_link_libraries(fortty PRIVATE helpers OpenGL::GL ${FREETYPE_LIBRARIES}) |
| 106 | |
| 107 | # Add fontconfig link directory if available (needed for linker to find it) |
| 108 | if(FONTCONFIG_FOUND) |
| 109 | target_link_directories(fortty PRIVATE ${FONTCONFIG_LIBRARY_DIRS}) |
| 110 | endif() |
| 111 | |
| 112 | # For Linux, we need dl for GLAD's dlopen |
| 113 | if(UNIX AND NOT APPLE) |
| 114 | target_link_libraries(fortty PRIVATE dl) |
| 115 | endif() |
| 116 | |
| 117 | # TODO: Link Cocoa framework for blur when CMake framework flag issue is resolved |
| 118 |