Skip to content

Commit

Permalink
Merge pull request #26335 from xylar/add-squadgen
Browse files Browse the repository at this point in the history
Add recipe for squadgen
  • Loading branch information
ocefpaf committed May 13, 2024
2 parents a671be7 + bc238ba commit 1e9e903
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 0 deletions.
20 changes: 20 additions & 0 deletions recipes/squadgen/0001-remove-png-h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff -ruN squadgen-1.2.1/src/SQuadGen.cpp squadgen-1.2.1-patch/src/SQuadGen.cpp
--- squadgen-1.2.1/src/SQuadGen.cpp 2024-05-11 15:31:02.000000000 -0600
+++ squadgen-1.2.1-patch/src/SQuadGen.cpp 2024-05-12 11:20:44.022644614 -0600
@@ -14,7 +14,6 @@
/// or implied warranty.
/// </remarks>

-#include <png.h>
#include "netcdfcpp.h"

#include <string>
@@ -195,7 +194,7 @@
if ((nRefinementLevel > 0) &&
((strRefineRect != "") || (strRefineFile != "") || (fLoadCSRefinementMap))
) {
- int nCommandLineCount =
+ int nCommandLineCount =
((strRefineRect != "")?(1):(0))
+ ((strRefineFile != "")?(1):(0))
+ (fLoadCSRefinementMap?(1):(0));
39 changes: 39 additions & 0 deletions recipes/squadgen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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}")

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(${netcdf_c_incdir})

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

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

set -x
set -e

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

# remove static libpng and zlib to prevent static linking
rm -rf ${PREFIX}/lib/libpng.a ${PREFIX}/lib/libz.a

rm -rf build
mkdir build
cd build
cmake \
-D CMAKE_INSTALL_PREFIX="${PREFIX}" \
-D NETCDF_PATH="${PREFIX}" \
-D CMAKE_BUILD_TYPE=Release \
-D BUILD_SHARED_LIBS=ON \
..
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")
53 changes: 53 additions & 0 deletions recipes/squadgen/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{% 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
patches:
- 0001-remove-png-h.patch

build:
skip: true # [not linux]
number: 0

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

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 NetCDF and Zlib
license_family: GPL
license_file:
- LICENSE.md
- src/netcdf-cxx-4.2.COPYRIGHT
- src/lodepng.h
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 1e9e903

Please sign in to comment.