| 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 | |
| 17 | # GLAD loader library (C) and helper functions |
| 18 | add_library(glad STATIC |
| 19 | src/gl/glad.c |
| 20 | c_src/gl_loader.c |
| 21 | ) |
| 22 | target_include_directories(glad PUBLIC ${CMAKE_SOURCE_DIR}/include) |
| 23 | target_link_libraries(glad PRIVATE glfw) |
| 24 | |
| 25 | # Fortran module output directory |
| 26 | set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/modules) |
| 27 | |
| 28 | # Fortran sources (order matters for module dependencies) |
| 29 | set(FORTRAN_SOURCES |
| 30 | src/core/types.f90 |
| 31 | src/gl/gl_bindings.f90 |
| 32 | src/window/glfw_bindings.f90 |
| 33 | src/window/window.f90 |
| 34 | src/fortty.f90 |
| 35 | ) |
| 36 | |
| 37 | # Main executable |
| 38 | add_executable(fortty ${FORTRAN_SOURCES}) |
| 39 | target_include_directories(fortty PRIVATE ${CMAKE_BINARY_DIR}/modules) |
| 40 | target_link_libraries(fortty PRIVATE glad glfw OpenGL::GL) |
| 41 | |
| 42 | # For Linux, we need dl for GLAD's dlopen |
| 43 | if(UNIX AND NOT APPLE) |
| 44 | target_link_libraries(fortty PRIVATE dl) |
| 45 | endif() |
| 46 |