Skip to content

Commit

Permalink
UGRID-4/UGRID-8/UGRID-12: Docker Linux build (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmad-el-sayed authored Aug 7, 2024
1 parent 05f30e8 commit b18b9ff
Show file tree
Hide file tree
Showing 17 changed files with 473 additions and 146 deletions.
41 changes: 33 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ SET(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/UGrid")

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -O2 -std=c++17")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -O2 -std=c++17 -Werror -Wall -Wextra -pedantic -Wno-unused-function")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -std=c++17")
else()
set(CMAKE_CXX_FLAGS_RELEASE
Expand All @@ -50,8 +50,27 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)

# Note this needs to be done in the main CMakeLists since it calls
# enable_testing, which must be in the main CMakeLists.

include(FetchContent)
set(FETCHCONTENT_QUIET off)

FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.13.0
)
if(WIN32)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif()

FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

include(CTest)

# Docs only available if this is the main app
add_subdirectory(docs)

Expand All @@ -75,17 +94,23 @@ include_directories(${Boost_INCLUDE_DIR})
# Use NetCDF
find_package(netCDF REQUIRED COMPONENTS C)
if (netCDF_FOUND)
message(STATUS "Found NetCDF: in ${netCDF_INSTALL_PREFIX} (found version \"${NetCDFVersion}\")")
message(STATUS "Found NetCDF ${netCDF_VERSION}")
else()
message(FATAL_ERROR "Could not find NetCDF" )
endif()

# Use NetCDF-cxx
find_package(netCDFCxx 4.3.1 REQUIRED)
if (NetCDFCxx_FOUND)
message(STATUS "NetCDFCXX include dirs: ${NetCDFCxx_INCLUDE_DIRS}")
find_package(netCDFCxx REQUIRED)
if (netCDFCxx_FOUND)
message(STATUS "Found NetCDFCxx ${netCDFCxx_VERSION}")
else()
message(FATAL_ERROR "Could not find NetCDFCxx")
endif()

# FetchContent added in CMake 3.11, downloads during the configure step
include(FetchContent)
find_package(hdf5 REQUIRED)
if (hdf5_FOUND)
message(STATUS "Found HDF5 ${hdf5_VERSION}")
endif()

# Run packaging scripts
add_subdirectory(package)
Expand Down
14 changes: 7 additions & 7 deletions include/UGrid/Constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ namespace ugrid
lon
};

const size_t name_length = 40; ///< length of the names
const size_t name_long_length = 80; ///< length of the long names
const int int_invalid_value = std::numeric_limits<int>::max(); ///< integer invalid value
const double double_invalid_value = std::numeric_limits<double>::max(); ///< double invalid value
constexpr size_t name_length = 40; ///< length of the names
constexpr size_t name_long_length = 80; ///< length of the long names
constexpr int int_invalid_value = std::numeric_limits<int>::max(); ///< integer invalid value
constexpr double double_invalid_value = std::numeric_limits<double>::max(); ///< double invalid value

const int int_missing_value = -999; ///< integer missing value
const double double_missing_value = -999.0; ///< double missing value
const int num_face_nodes_max = 6; ///< default maximum number of node per face
constexpr int int_missing_value = -999; ///< integer missing value
constexpr double double_missing_value = -999.0; ///< double missing value
constexpr int num_face_nodes_max = 6; ///< default maximum number of node per face
const std::string two_string("Two"); ///< Name of variable dimension containing two
const std::string name_length_dimension("name_length_dimension"); ///< Name of variable dimension containing two
const std::string name_long_length_dimension("name_long_length_dimension"); ///< Name of variable dimension containing two
Expand Down
3 changes: 2 additions & 1 deletion include/UGrid/Contacts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ namespace ugrid
/// @param attributes [in] The variable attributes
/// @param entity_dimensionality [in] The sought dimensionality
/// @return If The topology variable has a matching functionality
static bool has_matching_dimensionality(std::map<std::string, netCDF::NcVarAtt> const& attributes, int entity_dimensionality)
static bool has_matching_dimensionality([[maybe_unused]] std::map<std::string, netCDF::NcVarAtt> const& attributes,
[[maybe_unused]] int entity_dimensionality)
{
return true;
}
Expand Down
40 changes: 17 additions & 23 deletions include/UGrid/Operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,35 +80,29 @@ namespace ugrid
{
return face;
}
throw std::invalid_argument("from_location_string_to_location: Dimension not found.");
}

static std::string from_location_integer_to_location_string(int location)
{
auto const ug_entity_location = static_cast<UGridEntityLocations>(location);

if (ug_entity_location == node)
switch (ug_entity_location)
{
case node:
return "node";
}
if (ug_entity_location == edge)
{
case edge:
return "edge";
}
if (ug_entity_location == face)
{
case face:
return "face";
}
if (ug_entity_location == layer)
{
case layer:
return "layer";
}
if (ug_entity_location == layer_interface)
{
case layer_interface:
return "layer_interface";
}
if (ug_entity_location == vertical)
{
case vertical:
return "vertical";
default:
throw std::runtime_error("Invalid location.");
}
}

Expand Down Expand Up @@ -202,7 +196,7 @@ namespace ugrid
{
return;
}
for (auto i = 0; i < value.size(); ++i)
for (size_t i = 0; i < value.size(); ++i)
{
char_array[i] = value[i];
}
Expand All @@ -223,14 +217,14 @@ namespace ugrid
}

size_t char_array_position = 0;
for (auto i = 0; i < values.size(); ++i)
for (size_t i = 0; i < values.size(); ++i)
{
for (auto j = 0; j < values[i].size(); ++j)
for (size_t j = 0; j < values[i].size(); ++j)
{
char_array[char_array_position] = values[i][j];
char_array_position++;
}
for (auto j = values[i].size(); j < len; ++j)
for (size_t j = values[i].size(); j < len; ++j)
{
char_array[char_array_position] = ' ';
char_array_position++;
Expand All @@ -250,14 +244,14 @@ namespace ugrid
str.erase(std::find_if(str.rbegin(), str.rend(), isalnum_lambda).base(), str.end());
}

static std::string char_array_to_string(char const* char_array, size_t len)
static std::string char_array_to_string(char const* const char_array, size_t len)
{
std::string result(" ", len);
std::string result(len, ' ');
if (char_array == nullptr)
{
return result;
}
for (auto i = 0; i < len; ++i)
for (size_t i = 0; i < len; ++i)
{
result[i] = char_array[i];
}
Expand Down
6 changes: 4 additions & 2 deletions include/UGrid/UGridEntity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ namespace ugrid
/// @param nc_file [in] A pointer to NcFile, containing the id of an opened file
explicit UGridEntity(const std::shared_ptr<netCDF::NcFile>& nc_file);

virtual ~UGridEntity() = default;

/// @brief Constructor with several parameters as defined below
/// @param nc_file [in] A pointer to NcFile, containing the id of an opened file
/// @param topology_variable [in] The topology variable defining the entity
Expand Down Expand Up @@ -154,7 +156,7 @@ namespace ugrid
int variable_start_index;
varAtt.at(start_index_att_name).getValues(&variable_start_index);
const int offset = start_index - variable_start_index;
for (auto i = 0; i < values_size; ++i)
for (int i = 0; i < values_size; ++i)
{
values[i] += offset;
}
Expand All @@ -168,7 +170,7 @@ namespace ugrid
/// @param long_name [in] The entity long name
/// @param topology_dimension [in] The dimension of the topology
/// @param is_spherical [in] 1 if coordinates are in a spherical system, 0 otherwise
void define(char* entity_name, int start_index, std::string const& long_name, int topology_dimension, int is_spherical);
void define(char const* const entity_name, int start_index, std::string const& long_name, int topology_dimension, int is_spherical);

/// @brief A function to determine if a variable is a topology variable (this function might get overwritten in derived if necessary)
/// @param attributes [in] The variable attributes
Expand Down
22 changes: 22 additions & 0 deletions scripts/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM quay.io/pypa/manylinux_2_28_x86_64:2024-07-01-8dac23b

WORKDIR /workspace

COPY . /workspace/

RUN chmod +x /workspace/dnf_install.sh
RUN /workspace/dnf_install.sh

ARG THIRD_PARTY_WORK_DIR=/app/third_party/work
ARG THIRD_PARTY_INSTALL_DIR=/app/third_party/install
ENV THIRD_PARTY_INSTALL_DIR=${THIRD_PARTY_INSTALL_DIR}

RUN chmod +x /workspace/install_netcdf_cxx4.sh
RUN /workspace/install_netcdf_cxx4.sh \
--work_dir ${THIRD_PARTY_WORK_DIR} \
--install_dir ${THIRD_PARTY_INSTALL_DIR} \
--clean

ENV CLEAN_BUILD=false

ENTRYPOINT ["bash", "/workspace/scripts/docker/main.sh"]
29 changes: 29 additions & 0 deletions scripts/docker/dnf_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

set -e

source error.sh

dnf update -y

dev_toolset="gcc-toolset-12"

packages=(
"git"
"cmake"
"boost-devel"
"m4"
"perl"
"openssl"
"libcurl-devel"
${dev_toolset}
"doxygen"
)

for package in "${packages[@]}"; do
dnf install -y "${package}" || error "[dnf] Failed to install ${package}"
done

scl enable "${dev_toolset}" bash || error "[scl] Failed to enable ${dev_toolset}"

dnf clean all
7 changes: 7 additions & 0 deletions scripts/docker/error.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

error() {
local exit_code="$?"
echo "$(basename "$0")": "$1"
exit $exit_code
}
Loading

0 comments on commit b18b9ff

Please sign in to comment.