Commit d7493f05 authored by Robert Schweppe's avatar Robert Schweppe
Browse files

Merge remote-tracking branch 'remotes/upstream/mpr_compat' into mpr_compat

parents ef1514c9 6b62e1a8
......@@ -123,8 +123,66 @@ macro (NetCDF_check_interface lang header libs)
list (APPEND NetCDF_libs ${NETCDF_${lang}_LIBRARY})
list (APPEND NetCDF_includes ${NETCDF_${lang}_INCLUDE_DIR})
else ()
set (NETCDF_HAS_INTERFACES "NO")
message (STATUS "Failed to find NetCDF interface for ${lang}")
if ( ${lang} STREQUAL "F90")
find_program(NETCDFF_CONFIG nf-config
HINTS ${CMAKE_NETCDF_DIR})
message(STATUS "found ${NETCDFF_CONFIG}")
execute_process(COMMAND ${NETCDFF_CONFIG} --includedir OUTPUT_VARIABLE NETCDF_${lang}_INCLUDE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "netcdff includes ${NETCDF_INCLUDES}")
execute_process(COMMAND ${NETCDFF_CONFIG} --fflags OUTPUT_VARIABLE NETCDF_CFLAGS_OTHER OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "netcdff netcdf link flags ${NETCDF_CFLAGS_OTHER}")
execute_process(COMMAND ${NETCDFF_CONFIG} --flibs OUTPUT_VARIABLE NETCDF_LDFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "netcdff netcdf library link flags ${NETCDF_LDFLAGS}")
if (CMAKE_BUILD_MODULE_SYSTEM_INDEPENDENT)
find_program(NETCDF_CONFIG nc-config
HINTS ${CMAKE_NETCDF_DIR})
execute_process(COMMAND ${NETCDF_CONFIG} --libs OUTPUT_VARIABLE NETCDF_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "netcdf library link flags ${NETCDF_LIBS}")
endif()
# In a clean cmake setup the libraries are included via the target_link_libraries and not
# via flags. Cmake creates system dependend flags and rpaths using the libraries itself.
# nf-config on the other hand gives us a list of flags, linking with -l and -L.
# we cut the flag string into seperated flags and create libraries and other flags from it
string(REPLACE " " ";" NETCDF_LDFLAGS_LIST "${NETCDF_LDFLAGS} ${NETCDF_LIBS}")
foreach(flag ${NETCDF_LDFLAGS_LIST})
# message(STATUS "${flag}")
if (flag MATCHES "^-L(.*)")
list(APPEND _search_paths ${CMAKE_MATCH_1})
continue()
endif()
if (flag MATCHES "^-l(.*)")
set(_pkg_search "${CMAKE_MATCH_1}")
else()
string(CONCAT _link_flags "${_link_flags}" " " "${flag}")
continue()
endif()
if(_search_paths)
# Firstly search in -L paths
find_library(pkgcfg_lib_NETCDF_${_pkg_search}
NAMES ${_pkg_search}
HINTS ${_search_paths} NO_DEFAULT_PATH)
endif()
find_library(pkgcfg_lib_NETCDF_${_pkg_search}
NAMES ${_pkg_search}
HINTS ENV LD_LIBRARY_PATH)
message(STATUS "found ${pkgcfg_lib_NETCDF_${_pkg_search}}")
list(APPEND _libs "${pkgcfg_lib_NETCDF_${_pkg_search}}")
endforeach()
# those are set one level up
set(NETCDF_LDFLAGS_OTHER "${_link_flags}")
message(STATUS "found netcdf other flags ${NETCDF_LDFLAGS_OTHER}")
list (APPEND NETCDF_LINK_LIBRARIES "${_libs}")
message(STATUS "found netcdf libraries ${NETCDF_LINK_LIBRARIES}")
list (APPEND NetCDF_includes ${NETCDF_${lang}_INCLUDE_DIR})
else ()
set (NETCDF_HAS_INTERFACES "NO")
message (STATUS "Failed to find NetCDF interface for ${lang}")
endif ()
endif ()
endif ()
endmacro ()
......
......@@ -36,6 +36,9 @@ set (NETCDF_F90 "YES")
find_package (NetCDF REQUIRED)
target_link_libraries(${LIB_NAME} ${NETCDF_F90_LIBRARIES})
target_include_directories(${LIB_NAME} PUBLIC ${NETCDF_F90_INCLUDE_DIRS})
# all compile and link options are PUBLIC in order to be forwared to 'mhm' exe
# target_link_options only available in cmake 3.13 (but NETCDF_LDFLAGS_OTHER not working)
set_property(TARGET ${LIB_NAME} PROPERTY LINK_FLAGS "${NETCDF_LDFLAGS_OTHER}")
set(CMAKE_WITH_MPI OFF CACHE STRING "build the module with MPI, so it can be executed using mpirun")
# if cmake provides a findLIBRARY module, this gets invoked via find_package(LIBRARY)
......
enable_testing()
find_package(PFUNIT)
set (LIB_NAME lightweight_fortran_lib)
file ( COPY ./files
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
if(PFUNIT_FOUND)
# find if there is an OpenMP setup on the system and if so, set corresponding variables
......@@ -9,10 +14,18 @@ if(PFUNIT_FOUND)
message(FATAL_ERROR "OpenMP required but not found")
endif()
add_pfunit_ctest (test_mo_os
TEST_SOURCES test_mo_os.pf
LINK_LIBRARIES lightweight_fortran_lib
)
set (pfunit_suffix ".pf")
file( GLOB testsourcefiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *${pfunit_suffix} )
foreach( testsourcefile ${testsourcefiles} )
# I used a simple string replace, to cut off .pf
string( REPLACE ${pfunit_suffix} "" testname ${testsourcefile} )
add_pfunit_ctest (${testname}
TEST_SOURCES ${testsourcefile}
LINK_LIBRARIES ${LIB_NAME}
)
list(APPEND testnames ${testname})
endforeach()
else()
message(STATUS "No test program found, install PFUNIT")
endif()
......
......@@ -15,12 +15,12 @@ contains
logical :: r1, r2, r3, r4, r5, r6
call path_exists('../tests/files/namelist.txt', result_=r1)
call path_exists('../tests', result_=r2)
call path_exists('../tests/.', result_=r3)
call path_exists('./files/empty.txt', result_=r1)
call path_exists('./files', result_=r2)
call path_exists('./files/.', result_=r3)
call path_exists('xxx', quiet_=.true., result_=r4)
call path_exists('./files/.', quiet_=.true., result_=r5)
call path_exists('./namelist.txt', quiet_=.true., result_=r6)
call path_exists('./files_withtypo/.', quiet_=.true., result_=r5)
call path_exists('./empty_withtypo.txt', quiet_=.true., result_=r6)
@assertTrue(r1)
@assertTrue(r2)
......@@ -34,17 +34,17 @@ contains
@test
subroutine test_isfile()
logical :: r1, r2, r3, r4, r5, r6
logical :: r1, r3, r4, r5, r6
call path_isfile('../tests/files/namelist.txt', result_=r1)
call path_isfile('../Makefile', result_=r2)
call path_isfile('../tests', quiet_=.true., result_=r3)
call path_isfile('../tests/', quiet_=.true., result_=r4)
call path_isfile('./files/empty.txt', result_=r1)
!call path_isfile('../Makefile', result_=r2)
call path_isfile('../pf_tests', quiet_=.true., result_=r3)
call path_isfile('../pf_tests/', quiet_=.true., result_=r4)
call path_isfile('../files/.', quiet_=.true., result_=r5)
call path_isfile('./namelist.txt', quiet_=.true., result_=r6)
call path_isfile('./empty.txt', quiet_=.true., result_=r6)
@assertTrue(r1)
@assertTrue(r2)
!@assertTrue(r2)
@assertFalse(r3)
@assertFalse(r4)
@assertFalse(r5)
......@@ -57,12 +57,12 @@ contains
logical :: r1, r2, r3, r4, r5, r6
call path_isdir('../tests/.', result_=r1)
call path_isdir('../tests/', result_=r2)
call path_isdir('../tests/files', result_=r3)
call path_isdir('./files/.', result_=r1)
call path_isdir('./files/', result_=r2)
call path_isdir('./files', result_=r3)
call path_isdir('../../README', quiet_=.true., result_=r4)
call path_isdir('../tests/files/namelist.txt', quiet_=.true., result_=r5)
call path_isdir('./tests', quiet_=.true., result_=r6)
call path_isdir('./files/empty.txt', quiet_=.true., result_=r5)
call path_isdir('./pf_tests', quiet_=.true., result_=r6)
@assertTrue(r1)
@assertTrue(r2)
......@@ -89,7 +89,7 @@ contains
@assertEqual(trim(ext2), '')
@assertEqual(trim(root3), '../../README')
@assertEqual(trim(ext3), '')
end subroutine test_splitext
@test
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment