Skip to content

Commit f9888a4

Browse files
Merge pull request #18 from vil02/add_ci
2 parents 520e9c3 + d8c1640 commit f9888a4

File tree

6 files changed

+105
-17
lines changed

6 files changed

+105
-17
lines changed

.github/workflows/ci.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
name: ci
3+
4+
'on':
5+
workflow_dispatch:
6+
push:
7+
branches:
8+
- main
9+
pull_request:
10+
11+
env:
12+
build_path: ${{github.workspace}}/build
13+
14+
jobs:
15+
build_and_test:
16+
runs-on: ${{matrix.os}}
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
os: [ubuntu-22.04, ubuntu-24.04]
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Display versions
27+
run: |
28+
gfortran --version
29+
cmake --version
30+
31+
- name: Create Build Directory
32+
run: cmake -E make_directory ${{env.build_path}}
33+
34+
- name: Configure CMake
35+
working-directory: ${{env.build_path}}
36+
run: cmake ../
37+
38+
- name: Build
39+
working-directory: ${{env.build_path}}
40+
run: cmake --build .
41+
42+
- name: Test
43+
working-directory: ${{env.build_path}}
44+
run: ctest
45+
46+
- name: Run examples
47+
working-directory: ${{env.build_path}}
48+
run: make run_all_examples
49+
...

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@
3333

3434
.idea/
3535

36+
/build/

CMakeLists.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(FortranProject LANGUAGES Fortran)
3+
4+
add_compile_options(-Wall -Wextra -Wpedantic)
5+
6+
function(add_fortran_sources DIR SOURCES)
7+
file(GLOB_RECURSE NEW_SOURCES "${DIR}/*.f90")
8+
list(APPEND ${SOURCES} ${NEW_SOURCES})
9+
set(${SOURCES} ${${SOURCES}} PARENT_SCOPE)
10+
endfunction()
11+
12+
set(MODULE_SOURCES)
13+
add_fortran_sources(${CMAKE_SOURCE_DIR}/modules MODULE_SOURCES)
14+
15+
add_library(modules STATIC ${MODULE_SOURCES})
16+
17+
function(create_unique_name FILE_NAME OUTPUT_NAME)
18+
file(RELATIVE_PATH REL_PATH "${CMAKE_SOURCE_DIR}" "${FILE_NAME}")
19+
get_filename_component(CUR_EXT "${REL_PATH}" LAST_EXT)
20+
string(REPLACE "/" "_" UNIQUE_NAME "${REL_PATH}")
21+
string(REPLACE "${CUR_EXT}" "" UNIQUE_NAME "${UNIQUE_NAME}")
22+
set(${OUTPUT_NAME} ${UNIQUE_NAME} PARENT_SCOPE)
23+
endfunction()
24+
25+
26+
file(GLOB_RECURSE TEST_FILES "${CMAKE_SOURCE_DIR}/tests/*.f90")
27+
28+
foreach(TEST_FILE ${TEST_FILES})
29+
create_unique_name(${TEST_FILE} TEST_NAME)
30+
add_executable(${TEST_NAME} ${TEST_FILE})
31+
target_link_libraries(${TEST_NAME} modules)
32+
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
33+
endforeach()
34+
35+
file(GLOB_RECURSE EXAMPLE_FILES "${CMAKE_SOURCE_DIR}/examples/*.f90")
36+
37+
foreach(EXAMPLE_FILE ${EXAMPLE_FILES})
38+
create_unique_name(${EXAMPLE_FILE} EXAMPLE_NAME)
39+
add_executable(${EXAMPLE_NAME} ${EXAMPLE_FILE})
40+
target_link_libraries(${EXAMPLE_NAME} modules)
41+
list(APPEND EXAMPLE_NAME_LIST run_${EXAMPLE_NAME})
42+
add_custom_target(run_${EXAMPLE_NAME}
43+
COMMAND ${EXAMPLE_NAME}
44+
DEPENDS ${EXAMPLE_NAME}
45+
COMMENT "Running example: ${EXAMPLE_NAME}")
46+
endforeach()
47+
48+
enable_testing()
49+
50+
add_custom_target(run_all_examples DEPENDS ${EXAMPLE_NAME_LIST})

examples/maths/euclid_gcd.f90

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,11 @@ program euclid_gcd_program
44
use gcd_module
55
implicit none
66
integer :: a, b, val
7-
character(len=1024) :: msg
8-
integer :: istat
97

10-
print *, "Enter the two numbers (+ve integers): "
11-
read(*, *, iostat=istat, iomsg=msg) a, b
12-
if (istat /= 0) then
13-
write(*, fmt='(2A)') 'error: ', trim(msg)
14-
stop 1
15-
end if
8+
a = 56
9+
b = 98
1610

1711
val = gcd(a, b)
18-
print *, 'The greatest common divisor is: ', val
12+
print *, 'The greatest common divisor of ', a, ' and ', b, ' is: ', val
1913

2014
end program euclid_gcd_program

examples/maths/fibonacci.f90

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@ program example_fibonacci
66
implicit none
77
integer :: n
88

9-
print *, 'Enter a number: '
10-
read *, n
11-
if (n <= 0) then
12-
print *, 'Number must be a positive integer.'
13-
stop 1
14-
end if
9+
n = 7
1510

16-
print *, 'The Fibonacci number for the specified position is:'
11+
print *, 'The Fibonacci number for the position', n, ' is:'
1712
print *, 'Recursive solution: ', fib_rec(n)
1813
print *, 'Iterative solution: ', fib_itr(n)
1914

examples/sorts/example_usage_heap_sort.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ program test_heap_sort
1111

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

1615
! Print the original array
1716
print *, "Original array:"

0 commit comments

Comments
 (0)