Skip to content

improve cmake build #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
run: brew install gcc@${GCC_V} || brew upgrade gcc@${GCC_V} || true

- name: Configure with CMake
run: cmake -Wdev -S . -B build
run: cmake -Wdev -DCMAKE_BUILD_TYPE=Release -S . -B build

- name: Build and compile
run: cmake --build build || cmake --build build --verbose --parallel 1
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build/

# Prerequisites
*.d

Expand Down
11 changes: 5 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR)

enable_language(Fortran)

project(stdlib)

cmake_minimum_required(VERSION 3.5.0)
project(stdlib Fortran)
enable_testing()

# this avoids stdlib and projects using stdlib from having to introspect stdlib's directory structure
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR})

add_subdirectory(src)
18 changes: 9 additions & 9 deletions src/stdlib_experimental_io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ subroutine sloadtxt(filename, d)
integer :: s
integer :: nrow,ncol,i

open(newunit=s, file=filename, status="old")
open(newunit=s, file=filename, status="old", action="read")

! determine number of columns
ncol = number_of_columns(s)
Expand Down Expand Up @@ -89,7 +89,7 @@ subroutine dloadtxt(filename, d)
integer :: s
integer :: nrow,ncol,i

open(newunit=s, file=filename, status="old")
open(newunit=s, file=filename, status="old", action="read")

! determine number of columns
ncol = number_of_columns(s)
Expand Down Expand Up @@ -132,7 +132,7 @@ subroutine qloadtxt(filename, d)
integer :: s
integer :: nrow,ncol,i

open(newunit=s, file=filename, status="old")
open(newunit=s, file=filename, status="old", action="read")

! determine number of columns
ncol = number_of_columns(s)
Expand Down Expand Up @@ -164,7 +164,7 @@ subroutine ssavetxt(filename, d)
! call savetxt("log.txt", data)

integer :: s, i
open(newunit=s, file=filename, status="replace")
open(newunit=s, file=filename, status="replace", action="write")
do i = 1, size(d, 1)
write(s, *) d(i, :)
end do
Expand All @@ -187,7 +187,7 @@ subroutine dsavetxt(filename, d)
! call savetxt("log.txt", data)

integer :: s, i
open(newunit=s, file=filename, status="replace")
open(newunit=s, file=filename, status="replace", action="write")
do i = 1, size(d, 1)
write(s, *) d(i, :)
end do
Expand All @@ -210,7 +210,7 @@ subroutine qsavetxt(filename, d)
! call savetxt("log.txt", data)

integer :: s, i
open(newunit=s, file=filename, status="replace")
open(newunit=s, file=filename, status="replace", action="write")
do i = 1, size(d, 1)
write(s, *) d(i, :)
end do
Expand Down Expand Up @@ -243,17 +243,17 @@ integer function number_of_rows_numeric(s)
! determine number or rows
integer,intent(in)::s
integer :: ios

real::r

rewind(s)
number_of_rows_numeric = 0
do
read(s, *, iostat=ios) r
if (ios /= 0) exit
number_of_rows_numeric = number_of_rows_numeric + 1
end do

rewind(s)

end function
Expand Down
7 changes: 1 addition & 6 deletions src/tests/ascii/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
include_directories(${PROJECT_BINARY_DIR}/src)

project(ascii)

add_executable(test_ascii test_ascii.f90)
target_link_libraries(test_ascii fortran_stdlib)

add_test(test_ascii ${PROJECT_BINARY_DIR}/test_ascii)

add_test(NAME ASCII COMMAND $<TARGET_FILE:test_ascii>)
13 changes: 4 additions & 9 deletions src/tests/loadtxt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
include_directories(${PROJECT_BINARY_DIR}/src)

project(loadtxt)

add_executable(test_loadtxt test_loadtxt.f90)
target_link_libraries(test_loadtxt fortran_stdlib)

add_executable(test_savetxt test_savetxt.f90)
target_link_libraries(test_savetxt fortran_stdlib)

add_test(test_loadtxt ${PROJECT_BINARY_DIR}/test_loadtxt)
add_test(test_savetxt ${PROJECT_BINARY_DIR}/test_savetxt)

file(COPY array1.dat array2.dat array3.dat array4.dat
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
add_test(NAME load_text COMMAND $<TARGET_FILE:test_loadtxt> ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_test(NAME save_text COMMAND $<TARGET_FILE:test_savetxt> ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
56 changes: 38 additions & 18 deletions src/tests/loadtxt/test_savetxt.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,77 @@ program test_loadtxt
use stdlib_experimental_error, only: assert
implicit none

call test_sp()
call test_dp()
call test_qp()
character(:), allocatable :: outpath

outpath = get_outpath() // "/tmp.dat"

call test_sp(outpath)
call test_dp(outpath)
call test_qp(outpath)

contains

subroutine test_sp()
function get_outpath() result(outpath)
integer :: ierr
character(256) :: argv
character(:), allocatable :: outpath

call get_command_argument(1, argv, status=ierr)
if (ierr==0) then
outpath = trim(argv)
else
outpath = '.'
endif
end function get_outpath

subroutine test_sp(outpath)
character(*), intent(in) :: outpath
real(sp) :: d(3, 2), e(2, 3)
real(sp), allocatable :: d2(:, :)
d = reshape([1, 2, 3, 4, 5, 6], [3, 2])
call savetxt("tmp.dat", d)
call loadtxt("tmp.dat", d2)
call savetxt(outpath, d)
call loadtxt(outpath, d2)
call assert(all(shape(d2) == [3, 2]))
call assert(all(abs(d-d2) < epsilon(1._sp)))

e = reshape([1, 2, 3, 4, 5, 6], [2, 3])
call savetxt("tmp.dat", e)
call loadtxt("tmp.dat", d2)
call savetxt(outpath, e)
call loadtxt(outpath, d2)
call assert(all(shape(d2) == [2, 3]))
call assert(all(abs(e-d2) < epsilon(1._sp)))
end subroutine


subroutine test_dp()
subroutine test_dp(outpath)
character(*), intent(in) :: outpath
real(dp) :: d(3, 2), e(2, 3)
real(dp), allocatable :: d2(:, :)
d = reshape([1, 2, 3, 4, 5, 6], [3, 2])
call savetxt("tmp.dat", d)
call loadtxt("tmp.dat", d2)
call savetxt(outpath, d)
call loadtxt(outpath, d2)
call assert(all(shape(d2) == [3, 2]))
call assert(all(abs(d-d2) < epsilon(1._dp)))

e = reshape([1, 2, 3, 4, 5, 6], [2, 3])
call savetxt("tmp.dat", e)
call loadtxt("tmp.dat", d2)
call savetxt(outpath, e)
call loadtxt(outpath, d2)
call assert(all(shape(d2) == [2, 3]))
call assert(all(abs(e-d2) < epsilon(1._dp)))
end subroutine

subroutine test_qp()
subroutine test_qp(outpath)
character(*), intent(in) :: outpath
real(qp) :: d(3, 2), e(2, 3)
real(qp), allocatable :: d2(:, :)
d = reshape([1, 2, 3, 4, 5, 6], [3, 2])
call savetxt("tmp.dat", d)
call loadtxt("tmp.dat", d2)
call savetxt(outpath, d)
call loadtxt(outpath, d2)
call assert(all(shape(d2) == [3, 2]))
call assert(all(abs(d-d2) < epsilon(1._qp)))

e = reshape([1, 2, 3, 4, 5, 6], [2, 3])
call savetxt("tmp.dat", e)
call loadtxt("tmp.dat", d2)
call savetxt(outpath, e)
call loadtxt(outpath, d2)
call assert(all(shape(d2) == [2, 3]))
call assert(all(abs(e-d2) < epsilon(1._qp)))
end subroutine
Expand Down