Skip to content

Commit

Permalink
Merge pull request #18 from vil02/add_ci
Browse files Browse the repository at this point in the history
  • Loading branch information
SatinWukerORIG authored Sep 24, 2024
2 parents 520e9c3 + d8c1640 commit f9888a4
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 17 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
name: ci

'on':
workflow_dispatch:
push:
branches:
- main
pull_request:

env:
build_path: ${{github.workspace}}/build

jobs:
build_and_test:
runs-on: ${{matrix.os}}
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04, ubuntu-24.04]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Display versions
run: |
gfortran --version
cmake --version
- name: Create Build Directory
run: cmake -E make_directory ${{env.build_path}}

- name: Configure CMake
working-directory: ${{env.build_path}}
run: cmake ../

- name: Build
working-directory: ${{env.build_path}}
run: cmake --build .

- name: Test
working-directory: ${{env.build_path}}
run: ctest

- name: Run examples
working-directory: ${{env.build_path}}
run: make run_all_examples
...
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@

.idea/

/build/
50 changes: 50 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
cmake_minimum_required(VERSION 3.16)
project(FortranProject LANGUAGES Fortran)

add_compile_options(-Wall -Wextra -Wpedantic)

function(add_fortran_sources DIR SOURCES)
file(GLOB_RECURSE NEW_SOURCES "${DIR}/*.f90")
list(APPEND ${SOURCES} ${NEW_SOURCES})
set(${SOURCES} ${${SOURCES}} PARENT_SCOPE)
endfunction()

set(MODULE_SOURCES)
add_fortran_sources(${CMAKE_SOURCE_DIR}/modules MODULE_SOURCES)

add_library(modules STATIC ${MODULE_SOURCES})

function(create_unique_name FILE_NAME OUTPUT_NAME)
file(RELATIVE_PATH REL_PATH "${CMAKE_SOURCE_DIR}" "${FILE_NAME}")
get_filename_component(CUR_EXT "${REL_PATH}" LAST_EXT)
string(REPLACE "/" "_" UNIQUE_NAME "${REL_PATH}")
string(REPLACE "${CUR_EXT}" "" UNIQUE_NAME "${UNIQUE_NAME}")
set(${OUTPUT_NAME} ${UNIQUE_NAME} PARENT_SCOPE)
endfunction()


file(GLOB_RECURSE TEST_FILES "${CMAKE_SOURCE_DIR}/tests/*.f90")

foreach(TEST_FILE ${TEST_FILES})
create_unique_name(${TEST_FILE} TEST_NAME)
add_executable(${TEST_NAME} ${TEST_FILE})
target_link_libraries(${TEST_NAME} modules)
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
endforeach()

file(GLOB_RECURSE EXAMPLE_FILES "${CMAKE_SOURCE_DIR}/examples/*.f90")

foreach(EXAMPLE_FILE ${EXAMPLE_FILES})
create_unique_name(${EXAMPLE_FILE} EXAMPLE_NAME)
add_executable(${EXAMPLE_NAME} ${EXAMPLE_FILE})
target_link_libraries(${EXAMPLE_NAME} modules)
list(APPEND EXAMPLE_NAME_LIST run_${EXAMPLE_NAME})
add_custom_target(run_${EXAMPLE_NAME}
COMMAND ${EXAMPLE_NAME}
DEPENDS ${EXAMPLE_NAME}
COMMENT "Running example: ${EXAMPLE_NAME}")
endforeach()

enable_testing()

add_custom_target(run_all_examples DEPENDS ${EXAMPLE_NAME_LIST})
12 changes: 3 additions & 9 deletions examples/maths/euclid_gcd.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,11 @@ program euclid_gcd_program
use gcd_module
implicit none
integer :: a, b, val
character(len=1024) :: msg
integer :: istat

print *, "Enter the two numbers (+ve integers): "
read(*, *, iostat=istat, iomsg=msg) a, b
if (istat /= 0) then
write(*, fmt='(2A)') 'error: ', trim(msg)
stop 1
end if
a = 56
b = 98

val = gcd(a, b)
print *, 'The greatest common divisor is: ', val
print *, 'The greatest common divisor of ', a, ' and ', b, ' is: ', val

end program euclid_gcd_program
9 changes: 2 additions & 7 deletions examples/maths/fibonacci.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ program example_fibonacci
implicit none
integer :: n

print *, 'Enter a number: '
read *, n
if (n <= 0) then
print *, 'Number must be a positive integer.'
stop 1
end if
n = 7

print *, 'The Fibonacci number for the specified position is:'
print *, 'The Fibonacci number for the position', n, ' is:'
print *, 'Recursive solution: ', fib_rec(n)
print *, 'Iterative solution: ', fib_itr(n)

Expand Down
1 change: 0 additions & 1 deletion examples/sorts/example_usage_heap_sort.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ program test_heap_sort

! Initialize the test array
array = (/ 12, 11, 13, 5, 6, 7, 3, 9, -1, 2, -12, 1 /)
n = size(array)

! Print the original array
print *, "Original array:"
Expand Down

0 comments on commit f9888a4

Please sign in to comment.