| 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 and security flags |
| 9 | if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") |
| 10 | add_compile_options(-Wall -Wextra -pedantic) |
| 11 | # Avoid trampolines which require executable stack |
| 12 | add_compile_options(-fno-trampolines) |
| 13 | endif() |
| 14 | |
| 15 | # Find dependencies |
| 16 | find_package(glfw3 REQUIRED) |
| 17 | find_package(OpenGL REQUIRED) |
| 18 | find_package(Freetype REQUIRED) |
| 19 | |
| 20 | # Optional: fontconfig for portable font discovery |
| 21 | find_package(PkgConfig) |
| 22 | if(PkgConfig_FOUND) |
| 23 | pkg_check_modules(FONTCONFIG fontconfig) |
| 24 | endif() |
| 25 | |
| 26 | # C helper libraries (GLAD + FreeType + PTY wrappers) |
| 27 | set(HELPER_SOURCES |
| 28 | src/gl/glad.c |
| 29 | c_src/gl_loader.c |
| 30 | c_src/freetype_helpers.c |
| 31 | c_src/pty_helpers.c |
| 32 | ) |
| 33 | |
| 34 | # macOS window helpers placeholder - blur requires Cocoa which conflicts with Fortran build |
| 35 | # TODO: Enable when CMake framework flag issue is resolved |
| 36 | |
| 37 | add_library(helpers STATIC ${HELPER_SOURCES}) |
| 38 | target_include_directories(helpers PUBLIC ${CMAKE_SOURCE_DIR}/include) |
| 39 | target_include_directories(helpers PRIVATE ${FREETYPE_INCLUDE_DIRS}) |
| 40 | target_link_libraries(helpers PRIVATE glfw ${FREETYPE_LIBRARIES}) |
| 41 | |
| 42 | # Link util library for PTY on Linux (not needed on macOS) |
| 43 | if(UNIX AND NOT APPLE) |
| 44 | target_link_libraries(helpers PRIVATE util) |
| 45 | endif() |
| 46 | |
| 47 | # Note: Cocoa framework linked at executable level to avoid flag conflicts with Fortran |
| 48 | |
| 49 | # Link fontconfig if available |
| 50 | if(FONTCONFIG_FOUND) |
| 51 | target_compile_definitions(helpers PRIVATE HAVE_FONTCONFIG) |
| 52 | target_include_directories(helpers PRIVATE ${FONTCONFIG_INCLUDE_DIRS}) |
| 53 | target_link_directories(helpers PRIVATE ${FONTCONFIG_LIBRARY_DIRS}) |
| 54 | target_link_libraries(helpers PRIVATE ${FONTCONFIG_LIBRARIES}) |
| 55 | message(STATUS "Fontconfig found - enabling portable font discovery") |
| 56 | else() |
| 57 | message(STATUS "Fontconfig not found - using hardcoded font paths") |
| 58 | endif() |
| 59 | |
| 60 | # Fortran module output directory |
| 61 | set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/modules) |
| 62 | |
| 63 | # Fortran sources (order matters for module dependencies) |
| 64 | set(FORTRAN_SOURCES |
| 65 | src/core/types.f90 |
| 66 | src/gl/gl_bindings.f90 |
| 67 | src/text/glyph.f90 |
| 68 | src/gl/shader.f90 |
| 69 | src/text/font.f90 |
| 70 | src/text/atlas.f90 |
| 71 | src/text/renderer.f90 |
| 72 | src/terminal/cell.f90 |
| 73 | src/terminal/wcwidth.f90 |
| 74 | src/config/toml_parser.f90 |
| 75 | src/config/config.f90 |
| 76 | src/terminal/screen.f90 |
| 77 | src/terminal/cursor.f90 |
| 78 | src/terminal/selection.f90 |
| 79 | src/terminal/scrollback.f90 |
| 80 | src/terminal/terminal.f90 |
| 81 | src/terminal/parser.f90 |
| 82 | src/pty/pty_bindings.f90 |
| 83 | src/pty/pty.f90 |
| 84 | src/window/glfw_bindings.f90 |
| 85 | src/window/window.f90 |
| 86 | src/panes/pane.f90 |
| 87 | src/panes/layout.f90 |
| 88 | src/tabs/tab_manager.f90 |
| 89 | src/tabs/tab_bar.f90 |
| 90 | src/render_state.f90 |
| 91 | src/fortty.f90 |
| 92 | ) |
| 93 | |
| 94 | # Main executable |
| 95 | add_executable(fortty ${FORTRAN_SOURCES}) |
| 96 | target_include_directories(fortty PRIVATE ${CMAKE_BINARY_DIR}/modules) |
| 97 | |
| 98 | # Work around CMake framework flag issue: flang doesn't understand -F flag |
| 99 | if(APPLE) |
| 100 | # Remove -F flags from Fortran compile options |
| 101 | string(REPLACE "-F/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks" "" |
| 102 | CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}") |
| 103 | # Also set a compile option filter for the target |
| 104 | set_target_properties(fortty PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "") |
| 105 | endif() |
| 106 | |
| 107 | # Link libraries - glfw linked through helpers |
| 108 | target_link_libraries(fortty PRIVATE helpers OpenGL::GL ${FREETYPE_LIBRARIES}) |
| 109 | |
| 110 | # Add fontconfig link directory if available (needed for linker to find it) |
| 111 | if(FONTCONFIG_FOUND) |
| 112 | target_link_directories(fortty PRIVATE ${FONTCONFIG_LIBRARY_DIRS}) |
| 113 | endif() |
| 114 | |
| 115 | # For Linux, we need dl for GLAD's dlopen |
| 116 | if(UNIX AND NOT APPLE) |
| 117 | target_link_libraries(fortty PRIVATE dl) |
| 118 | # Note: Cannot use -Wl,-z,noexecstack as gfortran's internal procedures |
| 119 | # used as callbacks (do_render) require executable stack for trampolines |
| 120 | endif() |
| 121 | |
| 122 | # TODO: Link Cocoa framework for blur when CMake framework flag issue is resolved |
| 123 |