diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..9b7f055 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,53 @@ +name: Build and Test +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-20.04 + env: + FC: gfortran-9 + CC: gcc-9 + + steps: + + - name: checkout-pfunit + uses: actions/checkout@v2 + with: + repository: Goddard-Fortran-Ecosystem/pFUnit + path: pfunit + + - name: cache-pfunit + id: cache-pfunit + uses: actions/cache@v2 + with: + path: ~/pfunit + key: pfunit-${{ runner.os }}-${{ hashFiles('pfunit/VERSION') }} + + - name: build-pfunit + if: steps.cache-pfunit.outputs.cache-hit != 'true' + run: | + cd pfunit + mkdir build + cd build + cmake .. -DSKIP_MPI=YES -DSKIP_ESMF=YES -DSKIP_FHAMCREST=YES -DCMAKE_INSTALL_PREFIX=~/pfunit + make -j2 + make install + + - name: checkout + uses: actions/checkout@v2 + with: + path: landsfcutil + submodules: true + + - name: build + run: | + cd landsfcutil + mkdir build + cd build + cmake .. -DENABLE_TESTS=ON -DCMAKE_PREFIX_PATH="~/pfunit;~/" + make -j2 + + - name: test + run: | + cd $GITHUB_WORKSPACE/landsfcutil/build + make test \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f50dddf --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +build/ +install/ + +*.[ao] +*.mod +*.so + +*.swp diff --git a/4byte/CMakeLists.txt b/4byte/CMakeLists.txt deleted file mode 100644 index 7b4abb8..0000000 --- a/4byte/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -cmake_minimum_required(VERSION 2.6) -set(LIBNAME ${CMAKE_PROJECT_NAME}_${VERSION}_4) -file(GLOB LIB_4_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../src/*.f ${CMAKE_CURRENT_SOURCE_DIR}/../src/*.F) -add_definitions( ${CMAKE_Fortran_4_FLAGS} ) -add_library(${LIBNAME} STATIC ${LIB_4_SRC} ) - -set(CMAKE_INCLUDE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include_4") -set_target_properties(${LIBNAME} PROPERTIES Fortran_MODULE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include_4") -target_include_directories(${LIBNAME} PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/include_4") - -install(TARGETS ${LIBNAME} - RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin - LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib - ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) -install(DIRECTORY ${CMAKE_INCLUDE_OUTPUT_DIRECTORY}/ DESTINATION include_4 ) - diff --git a/CMakeLists.txt b/CMakeLists.txt index e5815fb..be950ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,69 +1,29 @@ cmake_minimum_required(VERSION 3.15) -project(landsfcutil VERSION 2.1.0) -set(${PROJECT_NAME}_VERSION ${PROJECT_VERSION} CACHE INTERNAL "${PROJECT_NAME} version number") -enable_language (Fortran) -if (NOT CMAKE_BUILD_TYPE) - set (CMAKE_BUILD_TYPE RELEASE CACHE STRING - "Choose the type of build, options are: PRODUCTION Debug Release." - FORCE) -endif() +file(STRINGS "VERSION" pVersion) -if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") - set(IntelComp true ) -elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU*" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang*") - set(GNUComp true ) -elseif(CMAKE_CXX_COMPILER_ID MATCHES "pgc*") - set(PGIComp true ) -endif() +project(landsfcutil VERSION ${pVersion} LANGUAGES Fortran) -STRING(COMPARE EQUAL ${CMAKE_BUILD_TYPE} "RelWithDebInfo" BUILD_RELEASE) -if(NOT BUILD_RELEASE ) - STRING(COMPARE EQUAL ${CMAKE_BUILD_TYPE} "RELEASE" BUILD_RELEASE) -endif() -STRING(COMPARE EQUAL ${CMAKE_BUILD_TYPE} "PRODUCTION" BUILD_PRODUCTION) -STRING(COMPARE EQUAL ${CMAKE_BUILD_TYPE} "DEBUG" BUILD_DEBUG) +option(ENABLE_TESTS "Enable tests" OFF) -if( (BUILD_RELEASE) OR (BUILD_PRODUCTION) ) - if(IntelComp) - set(shared_fortran_flags "-O3" "-fp-model strict" "-ip" "-FR") - set(fortran_d_flags "-r8") - set(fortran_4_flags) - elseif(GNUComp) - set(shared_fortran_flags "-O3" "-ffree-form") - set(fortran_d_flags "-fdefault-real-8") - set(fortran_4_flags) - else() - message("unknown compiler!") - exit() - endif() +if(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release|RelWithDebInfo|MinSizeRel)$") + message(STATUS "Setting build type to 'Release' as none was specified.") + set(CMAKE_BUILD_TYPE + "Release" + CACHE STRING "Choose the type of build." FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" + "MinSizeRel" "RelWithDebInfo") endif() -file(GLOB fortran_src ${CMAKE_CURRENT_SOURCE_DIR}/src/*.f ${CMAKE_CURRENT_SOURCE_DIR}/src/*.F) - -set(kinds "4" "d") -foreach(kind ${kinds}) - set(lib_name ${PROJECT_NAME}_${kind}) - set(versioned_lib_name ${PROJECT_NAME}_v${PROJECT_VERSION}_${kind}) - add_library(${lib_name} STATIC ${fortran_src}) - set_target_properties(${lib_name} PROPERTIES OUTPUT_NAME "${versioned_lib_name}") - - target_compile_definitions(${lib_name} PRIVATE "${platform_definition}") - target_compile_options(${lib_name} PRIVATE "${shared_fortran_flags};${fortran_${kind}_flags}") - - set(module_dir "${CMAKE_CURRENT_BINARY_DIR}/include_${kind}") - set_target_properties(${lib_name} PROPERTIES Fortran_MODULE_DIRECTORY "${module_dir}") - - target_include_directories(${lib_name} PUBLIC - $ - $) +if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel|GNU|Clang|AppleClang)$") + message( + WARNING "Compiler not officially supported: ${CMAKE_Fortran_COMPILER_ID}") +endif() - install(TARGETS ${lib_name} - EXPORT ${PROJECT_NAME}-config - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) - install(DIRECTORY ${module_dir} DESTINATION ${CMAKE_INSTALL_PREFIX}) -endforeach() +add_subdirectory(src) -install(EXPORT ${PROJECT_NAME}-config DESTINATION ${CMAKE_INSTALL_PREFIX}) +if (ENABLE_TESTS) + find_package(PFUNIT REQUIRED) + enable_testing() + add_subdirectory(tests) +endif() diff --git a/README.md b/README.md new file mode 100644 index 0000000..2261d72 --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +# Landsfcutil + +Utility routines useful for initializing land-surface states in NCEP models + +Code Manager: George Gayno + +### Prerequisites + +Compilers: GNU | Intel | Clang | AppleClang + + +### Installing + +``` +mkdir build +cd build +cmake -DCMAKE_INSTALL_PREFIX=/path/to/install /path/to/NCEPLIBS-landsfcutil +make -j2 +make install +``` + + +### Version + +2.3.0 + + +### Authors + +* **[NCEP/EMC](mailto:NCEP.List.EMC.nceplibs.Developers@noaa.gov)** diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..276cbf9 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +2.3.0 diff --git a/cmake/PackageConfig.cmake.in b/cmake/PackageConfig.cmake.in new file mode 100644 index 0000000..30f7c50 --- /dev/null +++ b/cmake/PackageConfig.cmake.in @@ -0,0 +1,16 @@ +@PACKAGE_INIT@ + +#@PROJECT_NAME@-config.cmake +# Imported interface targets provided: +# * @PROJECT_NAME@::@PROJECT_NAME@_4 - real32 library target +# * @PROJECT_NAME@::@PROJECT_NAME@_d - mixed library target + +# Include targets file. This will create IMPORTED target @PROJECT_NAME@ +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake") + +get_target_property(@PROJECT_NAME@_BUILD_TYPES @PROJECT_NAME@::@PROJECT_NAME@_4 IMPORTED_CONFIGURATIONS) + +check_required_components("@PROJECT_NAME@") + +get_target_property(location @PROJECT_NAME@::@PROJECT_NAME@_4 LOCATION) +message(STATUS "Found @PROJECT_NAME@: ${location} (found version \"@PROJECT_VERSION@\")") diff --git a/double/CMakeLists.txt b/double/CMakeLists.txt deleted file mode 100644 index f5a21ce..0000000 --- a/double/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -cmake_minimum_required(VERSION 2.6) -set(LIBNAME ${CMAKE_PROJECT_NAME}_${VERSION}_d) -file(GLOB LIB_d_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../src/*.f ${CMAKE_CURRENT_SOURCE_DIR}/../src/*.F) -add_definitions( ${CMAKE_Fortran_d_FLAGS} ) -add_library(${LIBNAME} STATIC ${LIB_d_SRC} ) -set(CMAKE_INCLUDE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include_d") -set_target_properties(${LIBNAME} PROPERTIES Fortran_MODULE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include_d") -target_include_directories(${LIBNAME} PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/include_d") - -install(TARGETS ${LIBNAME} - RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin - LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib - ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) -install(DIRECTORY ${CMAKE_INCLUDE_OUTPUT_DIRECTORY}/ DESTINATION include_d ) - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..3afd675 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,66 @@ + +if(CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel)$") + set(CMAKE_Fortran_FLAGS "-g -ip -FR -fp-model strict") + set(CMAKE_Fortran_FLAGS_RELEASE "-O3") + set(fortran_d_flags "-r8") +elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$") + set(CMAKE_Fortran_FLAGS "-g -ffree-form") + set(CMAKE_Fortran_FLAGS_RELEASE "-O3") + set(CMAKE_Fortran_FLAGS_DEBUG "-ggdb -Wall") + set(fortran_d_flags "-fdefault-real-8") +endif() + +set(fortran_src consts.f interp_utils.f ll2xy_utils.f + read_write_utils.f soil_utils.f) + +set(kinds "4" "d") +foreach(kind ${kinds}) + set(lib_name ${PROJECT_NAME}_${kind}) + set(module_dir ${CMAKE_CURRENT_BINARY_DIR}/include_${kind}) + + add_library(${lib_name} STATIC ${fortran_src}) + add_library(${PROJECT_NAME}::${lib_name} ALIAS ${lib_name}) + + set_target_properties(${lib_name} PROPERTIES COMPILE_FLAGS "${fortran_${kind}_flags}") + set_target_properties(${lib_name} PROPERTIES Fortran_MODULE_DIRECTORY ${module_dir}) + target_include_directories(${lib_name} PUBLIC + $ + $) + + list(APPEND LIB_TARGETS ${lib_name}) + + install(DIRECTORY ${module_dir} DESTINATION ${CMAKE_INSTALL_PREFIX}) +endforeach() + +install( + TARGETS ${LIB_TARGETS} + EXPORT ${PROJECT_NAME}Exports + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) + +### Package config +include(CMakePackageConfigHelpers) +set(CONFIG_INSTALL_DESTINATION lib/cmake/${PROJECT_NAME}) + +export(EXPORT ${PROJECT_NAME}Exports + NAMESPACE ${PROJECT_NAME}:: + FILE ${PROJECT_NAME}-targets.cmake) + +configure_package_config_file( + ${CMAKE_SOURCE_DIR}/cmake/PackageConfig.cmake.in ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-config.cmake + INSTALL_DESTINATION ${CONFIG_INSTALL_DESTINATION}) +install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-config.cmake + DESTINATION ${CONFIG_INSTALL_DESTINATION}) + +write_basic_package_version_file( + ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion) +install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake + DESTINATION ${CONFIG_INSTALL_DESTINATION}) + +install(EXPORT ${PROJECT_NAME}Exports + NAMESPACE ${PROJECT_NAME}:: + FILE ${PROJECT_NAME}-targets.cmake + DESTINATION ${CONFIG_INSTALL_DESTINATION}) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..fb77d8d --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,5 @@ + +add_pfunit_ctest (landsfcutil_test + TEST_SOURCES test_mod.pf + LINK_LIBRARIES landsfcutil::landsfcutil_4 +) diff --git a/tests/test_mod.pf b/tests/test_mod.pf new file mode 100644 index 0000000..6e987fa --- /dev/null +++ b/tests/test_mod.pf @@ -0,0 +1,12 @@ +module test_mod + use funit + use iso_fortran_env, only: real32, real64 + +contains + + @test + subroutine test_sigio() + @assertTrue(.true., "true is true") + end subroutine test_sigio + +end module test_mod