Add fortran wrapper test system

This commit is contained in:
Atsushi Togo 2023-01-30 18:33:48 +09:00
parent 306f4505d3
commit 3d1e89c9fe
6 changed files with 61 additions and 21 deletions

View File

@ -8,8 +8,13 @@ option(WITH_Fortran "enable fortran interface" OFF)
option(USE_OpenMP "Option to search OpenMP library" ON) option(USE_OpenMP "Option to search OpenMP library" ON)
option(WITH_TESTS "build unit tests" OFF) option(WITH_TESTS "build unit tests" OFF)
option(BUILD_SHARED_LIBRARIES "Option to build shared library" OFF) option(BUILD_SHARED_LIBRARIES "Option to build shared library" OFF)
if(WITH_Fortran)
enable_language(Fortran)
set(GRIDSYS ON)
endif()
if(WITH_TESTS) if(WITH_TESTS)
set(BUILD_SHARED_LIBRARIES ON) set(BUILD_SHARED_LIBRARIES ON)
set(GRIDSYS ON)
endif() endif()
set(CMAKE_MACOSX_RPATH 1) set(CMAKE_MACOSX_RPATH 1)
@ -258,11 +263,13 @@ if(GRIDSYS)
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif() endif()
if(WITH_TESTS)
add_subdirectory(ctest)
endif()
if(WITH_Fortran) if(WITH_Fortran)
enable_language(Fortran)
add_subdirectory(fortran) add_subdirectory(fortran)
endif() endif()
if(WITH_TESTS)
if(WITH_Fortran)
set(LIB_MOD_DIR ${CMAKE_CURRENT_BINARY_DIR}/fortran)
endif()
add_subdirectory(ctest)
endif()

View File

@ -36,3 +36,7 @@ foreach(testcase IN ITEMS test_gridsys test_niggli)
${CMAKE_CURRENT_SOURCE_DIR}) ${CMAKE_CURRENT_SOURCE_DIR})
gtest_discover_tests(${testcase}) gtest_discover_tests(${testcase})
endforeach() endforeach()
if(WITH_Fortran)
add_subdirectory(fortran)
endif()

View File

@ -0,0 +1 @@
add_subdirectory(gridsysf)

View File

@ -0,0 +1,11 @@
set(NAME gridsysf)
add_executable(test_${NAME} test_${NAME}.f90)
target_link_libraries(test_${NAME} PRIVATE gridsysf)
set_target_properties(test_${NAME} PROPERTIES Fortran_MODULE_DIRECTORY
${LIB_MOD_DIR})
add_test(
NAME ${NAME}
COMMAND $<TARGET_FILE:test_${NAME}> ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

View File

@ -0,0 +1,27 @@
program test_gridsysf
use, intrinsic :: iso_c_binding
use gridsysf, only : gridsys_get_bz_grid_addresses
implicit none
call test_gridsys_get_bz_grid_addresses()
contains
subroutine test_gridsys_get_bz_grid_addresses() bind(C)
integer(c_long) :: bz_size
integer(c_long) :: PS(3), D_diag(3), Q(3, 3), bz_grid_addresses(144, 3)
integer(c_long) :: bz_map(76), bzg2grg(144)
real(c_double) :: rec_lattice(3, 3)
PS(:) = [0, 0, 0]
D_diag(:) = [5, 5, 3]
Q(:, :) = reshape([1, 0, 0, 0, 1, 0, 0, 0, 1], [3, 3])
rec_lattice(:, :) = reshape([0.3214400514304082, 0.0, 0.0, &
0.1855835002216734, 0.3711670004433468, 0.0, &
0.0, 0.0, 0.20088388911209323], [3, 3])
bz_size = gridsys_get_bz_grid_addresses(bz_grid_addresses, bz_map, bzg2grg, &
D_diag, Q, PS, rec_lattice, int(2, c_long))
if (.false.) error stop
end subroutine test_gridsys_get_bz_grid_addresses
end program test_gridsysf

View File

@ -6,28 +6,18 @@ if(USE_OpenMP)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}") set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}")
endif() endif()
add_library(gridsysf_static STATIC ${PROJECT_SOURCE_DIR}/fortran/gridsysf.f90) add_library(gridsysf_static STATIC gridsysf.f90)
set_property(TARGET gridsysf_static PROPERTY VERSION ${PROJECT_VERSION}) set_property(TARGET gridsysf_static PROPERTY VERSION ${PROJECT_VERSION})
set_property(TARGET gridsysf_static PROPERTY OUTPUT_NAME gridsysf) set_property(TARGET gridsysf_static PROPERTY OUTPUT_NAME gridsysf)
target_link_libraries(gridsysf_static PRIVATE gridsys_static) target_link_libraries(gridsysf_static PRIVATE gridsys_static)
if(BUILD_SHARED_LIBRARIES)
add_library(gridsysf SHARED ${PROJECT_SOURCE_DIR}/fortran/gridsysf.f90)
set_property(TARGET gridsysf PROPERTY VERSION ${PROJECT_VERSION})
set_property(TARGET gridsysf PROPERTY SOVERSION ${soserial})
target_link_libraries(gridsysf PUBLIC gridsys)
target_include_directories(
gridsysf PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_LIBDIR}>")
endif()
install(TARGETS gridsysf_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(TARGETS gridsysf_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
if(BUILD_SHARED_LIBRARIES) if(BUILD_SHARED_LIBRARIES)
install( add_library(gridsysf SHARED gridsysf.f90)
TARGETS gridsysf set_property(TARGET gridsysf PROPERTY VERSION ${PROJECT_VERSION})
EXPORT gridsysTargets set_property(TARGET gridsysf PROPERTY SOVERSION ${soserial})
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) target_link_libraries(gridsysf PUBLIC gridsys)
install(TARGETS gridsysf LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif() endif()
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gridsysf.mod install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gridsysf.mod