Skip to content

Commit

Permalink
Add recipe for squadgen
Browse files Browse the repository at this point in the history
  • Loading branch information
xylar committed May 12, 2024
1 parent b1efc5e commit 7c757ac
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 0 deletions.
44 changes: 44 additions & 0 deletions recipes/squadgen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
cmake_minimum_required(VERSION 3.18)
project(
squadgen
VERSION $ENV{PKG_VERSION}
LANGUAGES C CXX)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

include("${CMAKE_SOURCE_DIR}/cmake_macros/gnu.cmake")

find_package(NETCDF REQUIRED)

message(STATUS "netcdf_c_incdir=${netcdf_c_incdir}")
message(STATUS "netcdf_c_libs=${netcdf_c_libs}")

find_package(PNG REQUIRED)
message(STATUS "PNG_INCLUDE_DIR=${PNG_INCLUDE_DIR}")
message(STATUS "PNG_LIBRARIES=${PNG_LIBRARIES}")

SET(SRC ${CMAKE_SOURCE_DIR}/src)
set(SQUADGEN_SRC ${SRC}/SQuadGen.cpp
${SRC}/GridElements.cpp
${SRC}/CSRefinementMap.cpp
${SRC}/CubedSphereGrid.cpp
${SRC}/IcosahedralFlagGrid.cpp
${SRC}/RefineGrid.cpp
${SRC}/RefinementTemplateCUBIT.cpp
${SRC}/RefinementTemplateLOWCONN.cpp
${SRC}/RefinementTemplateLOWCONNOLD.cpp
${SRC}/SpringDynamics.cpp
${SRC}/MeshUtilities.cpp
${SRC}/Tessellate.cpp
${SRC}/lodepng.cpp
${SRC}/netcdf.cpp
${SRC}/ncvalues.cpp)

include_directories(${PNG_INCLUDE_DIR})
include_directories(${netcdf_c_incdir})

include_directories(${SRC})
add_executable(SQuadGen ${SQUADGEN_SRC})
target_link_libraries(SQuadGen ${netcdf_c_libs} ${PNG_LIBRARIES})

install(TARGETS SQuadGen DESTINATION bin)
17 changes: 17 additions & 0 deletions recipes/squadgen/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -x
set -e

cp -r ${RECIPE_DIR}/cmake ${RECIPE_DIR}/cmake_macros ${RECIPE_DIR}/CMakeLists.txt .

rm -rf build
mkdir build
cd build
cmake \
-D CMAKE_INSTALL_PREFIX="${PREFIX}" \
-D NETCDF_PATH="${PREFIX}" \
-D CMAKE_BUILD_TYPE=Release \
..
cmake --build .
cmake --install .
57 changes: 57 additions & 0 deletions recipes/squadgen/cmake/FindNETCDF.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# - Try to find Netcdf

function(get_netcdf_libs ncpath)

set(ncconfig ${ncpath}/bin/nc-config)

# Get C libs
if (EXISTS ${ncconfig})
execute_process(COMMAND ${ncconfig} --libs OUTPUT_VARIABLE nclibs OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()

# Fall back to find_library
if (NOT nclibs)
find_library(nclibs_temp netcdf REQUIRED HINTS ${ncpath}/lib ${ncpath}/lib64)
set(nclibs ${nclibs_temp})
endif()


set(netcdf_c_libs ${nclibs} PARENT_SCOPE)
endfunction()

function(create_netcdf_target)

# Grab things from env
set(NETCDF_PATH $ENV{NETCDF_PATH})
set(NETCDF_C_PATH $ENV{NETCDF_C_PATH})

if (NETCDF_C_PATH)
# Sanity checks
if (NOT EXISTS ${NETCDF_C_PATH}/lib AND NOT EXISTS ${NETCDF_C_PATH}/lib64)
message(FATAL_ERROR "NETCDF_C_PATH does not contain a lib or lib64 directory")
endif ()

get_netcdf_libs(${NETCDF_C_PATH})
find_path (netcdf_c_incdir netcdf.h REQUIRED HINTS ${NETCDF_C_PATH}/include)

elseif (NETCDF_FORTRAN_PATH)
message(FATAL_ERROR "NETCDF_FORTRAN_PATH specified without NETCDF_C_PATH")

elseif (NETCDF_PATH)
# Sanity checks
if (NOT EXISTS ${NETCDF_PATH}/lib AND NOT EXISTS ${NETCDF_PATH}/lib64)
message(FATAL_ERROR "NETCDF_PATH does not contain a lib or lib64 directory")
endif ()

get_netcdf_libs(${NETCDF_PATH})
find_path(netcdf_c_incdir netcdf.h REQUIRED HINTS ${NETCDF_PATH}/include)

else()
message(FATAL_ERROR "NETCDF not found: Define NETCDF_PATH or NETCDF_C_PATH")
endif()

set(netcdf_c_incdir ${netcdf_c_incdir})
set(netcdf_c_libs ${netcdf_c_libs} PARENT_SCOPE)
endfunction()

create_netcdf_target()
6 changes: 6 additions & 0 deletions recipes/squadgen/cmake_macros/gnu.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
string(APPEND CMAKE_Fortran_FLAGS " -fconvert=big-endian -ffree-line-length-none -ffixed-line-length-none")
if (CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 10)
string(APPEND CMAKE_Fortran_FLAGS " -fallow-argument-mismatch")
endif()
string(APPEND CMAKE_Fortran_FORMAT_FIXED_FLAG " -ffixed-form")
string(APPEND CMAKE_Fortran_FORMAT_FREE_FLAG " -ffree-form")
56 changes: 56 additions & 0 deletions recipes/squadgen/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{% set name = "squadgen" %}
{% set version = "1.2.1" %}

package:
name: {{ name|lower }}
version: {{ version }}

source:
url: https://github.com/ClimateGlobalChange/squadgen/archive/refs/tags/v{{ version }}.tar.gz
sha256: a39f9f467563e796c1b0a53c7bf7d046f50110a030d92350754a60ada4eda053

build:
skip: true # [not linux]
number: 0
ignore_run_exports:
# I don't really understand why these dynamic libraries aren't being linked in...
- libpng
- zlib

requirements:
build:
- {{ compiler('c') }}
- {{ compiler('cxx') }}
- {{ stdlib("c") }}
- cmake
- make
host:
- libnetcdf
- libnetcdf * nompi_*
- libpng
- zlib

test:
files:
- test/grid.png
commands:
- >
SQuadGen --refine_file test/grid.png --refine_level 5
--refine_type LOWCONN --resolution 30 --smooth_type SPRING
--smooth_dist 3 --smooth_iter 20 --output grid.g
- test -f "grid.g"

about:
home: https://github.com/ClimateGlobalChange/squadgen
license: GPL-2.0-or-later and CUSTOM
license_family: GPL
license_file:
- LICENSE.md
- src/netcdf-cxx-4.2.COPYRIGHT
summary: Spherical Quadrilateral Mesh Generator (SQuadGen)
doc_url: https://github.com/ClimateGlobalChange/squadgen/blob/master/README.md
dev_url: https://github.com/ClimateGlobalChange/squadgen

extra:
recipe-maintainers:
- xylar
Binary file added recipes/squadgen/test/grid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7c757ac

Please sign in to comment.