Skip to content

Commit

Permalink
Merge pull request #60 from USEPA/triplet_build
Browse files Browse the repository at this point in the history
EPANET 2.2  Triplet build
  • Loading branch information
cbuahin committed Oct 13, 2023
2 parents 02473a0 + bf1e6a7 commit f5c766f
Show file tree
Hide file tree
Showing 42 changed files with 382 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml
name: Build and Test EPANET 2.2
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
name: Build, Unit Testing, and Regression Testing
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
include:
- os: windows-latest
cmake_generator: -G "Visual Studio 17 2022" -A "x64"
continue-on-error: false
- os: ubuntu-latest
cmake_generator: -G "Unix Makefiles"
continue-on-error: false
- os: macos-latest
cmake_generator: -G "Xcode"
continue-on-error: false
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.continue-on-error }}

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Build
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: |
cd SRC_engines
cmake -B .\build ${{ matrix.cmake_generator }} .
cmake --build .\build --config Release --target package
- name: Upload artifacts
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: build-test-artifacts
path: |
build/*.zip
build/*.tar.gz
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

![image37](https://user-images.githubusercontent.com/2470152/154551849-57d48b9d-2ea6-4a0f-90fd-3132c8c2aa8d.png)

## Build Status
[![Build and Test](../../actions/workflows/build-and-test.yml/badge.svg)](../../actions/workflows/build-and-test.yml)

# Introduction
EPANET is used to perform extended-period simulation of the hydraulic and water quality behavior within drinking water distribution systems (e.g., pressurized pipe networks), which consist of pipes, nodes (junctions), pumps, valves, storage tanks, and reservoirs. It can be used to track the flow of water in each pipe, the pressure at each node, the height of the water in each tank, a chemical concentration, the age of the water, and source tracing throughout the network during a simulation period.
Expand Down
55 changes: 55 additions & 0 deletions SRC_engines/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
cmake_minimum_required(VERSION 3.9)

if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
message(FATAL_ERROR "In-source builds are disabled.")
endif()

project(
"EPANET"
VERSION 2.2.0
DESCRIPTION "The EPANET Program for Water Distribution System Analysis"
)

# Append local dir to module search path
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

# Sets the position independent code property for all targets
set(CMAKE_POSITION_INDEPENDENT_CODE ON)


# Sets default install prefix when cmakecache is initialized for first time
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "..." FORCE)
endif()

# Sets the output directory for executables and libraries.
set(TOOL_DIST "bin")
set(INCLUDE_DIST "include")
set(LIBRARY_DIST "lib")
set(CONFIG_DIST "cmake")

# option(BUILD_TESTS "Build component tests (requires Boost)" OFF)
option(BUILD_DEF "Builds library with def file interface" OFF)

# Added option to statically link libraries to address GitHub Ubuntu 20.04 symbol errors (issue #340)
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)

add_subdirectory(src/solver)
add_subdirectory(src/run)

# Create install rules for vcruntime.dll, msvcp.dll, vcomp.dll etc.
include(InstallRequiredSystemLibraries)

install(
FILES
"CONTRIBUTORS"
DESTINATION
"."
)

# Configure CPack driven installer package
set(CPACK_GENERATOR "ZIP;TGZ")
set(CPACK_PACKAGE_VENDOR "US_EPA")
set(CPACK_ARCHIVE_FILE_NAME "epanet-${PROJECT_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")

include(CPack)
1 change: 1 addition & 0 deletions SRC_engines/AUTHORS → SRC_engines/CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Authors with Contributions in the Public Domain:

Lewis Rossman <LRossman@cinci.rr.com>
Michael Tryby <tryby.michael@epa.gov>
Caleb Buahin <buahin.caleb@epa.gov>

Authors with Contributions Subject to Copyright (see LICENSE):

Expand Down
43 changes: 43 additions & 0 deletions SRC_engines/extern/version.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# version.cmake - generate EPANET version information header
#
# Created: Sep 12, 2023
# Updated:
#
# Author: see CONTRIBUTORS
#
# Usage:
# GEN_VER_HEADER=ON -- overwrites version.h file with current info
#


option(GEN_VER_HEADER "Automatically update version header" ON)

if(GEN_VER_HEADER)

# Get the latest commit hash for the working branch
execute_process(
COMMAND
git rev-parse HEAD
WORKING_DIRECTORY
${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE
GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Generate a build id
string(
TIMESTAMP BUILD_ID UTC
)

# Configure the version header
configure_file(
../../extern/version.h.in version.h
)

file(COPY ${CMAKE_CURRENT_BINARY_DIR}/version.h
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/
)

endif()
39 changes: 39 additions & 0 deletions SRC_engines/extern/version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* version.h - EPANET version header file
*
* Created on: Sep 2, 2023
*
* Author: see CONTRIBUTORS
*
* Note:
* The cmake build process automatically generates this file. Do not edit.
*/


#ifndef VERSION_H_
#define VERSION_H_



#define PROJECT "EPANET"
#define ORGANIZATION "US EPA ORD"

#define VERSION "@EPANET_VERSION@"
#define VERSION_MAJOR @EPANET_VERSION_MAJOR@
#define VERSION_MINOR @EPANET_VERSION_MINOR@
#define VERSION_PATCH @EPANET_VERSION_PATCH@
#define GIT_HASH "@GIT_HASH@"

#define PLATFORM "@CMAKE_SYSTEM_NAME@"
#define COMPILER "@CMAKE_C_COMPILER_ID@"
#define COMPILER_VERSION "@CMAKE_C_COMPILER_VERSION@"
#define BUILD_ID "@BUILD_ID@"


static inline int get_version_legacy() { \
return VERSION_MAJOR * 10000 + VERSION_MINOR * 1000 + VERSION_PATCH; \
}



#endif /* VERSION_H_ */
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
45 changes: 45 additions & 0 deletions SRC_engines/src/run/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
if(APPLE)
set(RPATH_ROOT "@loader_path")
else()
set(RPATH_ROOT "$ORIGIN")
endif()

set(PACKAGE_RPATH "${RPATH_ROOT}/../lib;${RPATH_ROOT}/../extern")


# Creates the EPANET command line executable
add_executable(runepanet
main.c
)

target_include_directories(runepanet
PUBLIC
${PROJECT_SOURCE_DIR}/include
)

target_link_libraries(runepanet
LINK_PUBLIC
epanet2
)

# Set up rpath for runswmm inside install package
set_target_properties(runepanet
PROPERTIES
MACOSX_RPATH TRUE
SKIP_BUILD_RPATH FALSE
BUILD_WITH_INSTALL_RPATH FALSE
INSTALL_RPATH "${PACKAGE_RPATH}"
INSTALL_RPATH_USE_LINK_PATH TRUE
)

install(TARGETS runepanet
DESTINATION "${TOOL_DIST}"
)


# # copy runswmm to build tree for testing
# add_custom_command(TARGET runepanet POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy
# $<TARGET_FILE:runepanet>
# ${CMAKE_BINARY_DIR}/bin/$<CONFIGURATION>/$<TARGET_FILE_NAME:runepanet>
# )
File renamed without changes.
109 changes: 109 additions & 0 deletions SRC_engines/src/solver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
include(../../extern/version.cmake)

set(EPANET_PUBLIC_HEADERS
${PROJECT_SOURCE_DIR}/include/epanet2_2.h
${PROJECT_SOURCE_DIR}/include/epanet2.h
)

file(GLOB
EPANET_SOURCES
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.c *.h *.dat
)

if(BUILD_DEF)
# Builds library with def file interface for backward compatibility
set_source_files_properties(${PROJECT_SOURCE_DIR}/include/epanet2.def
PROPERTIES_HEADER_FILE_ONLY TRUE
)

add_library(epanet2
${EPANET_SOURCES}
${PROJECT_SOURCE_DIR}/include/epanet2.def
)

else()
# Performs standard library build
add_library(epanet2
${EPANET_SOURCES}
)

endif()

# Sets MSVC compiler flags
target_compile_options(epanet2
PUBLIC
"$<$<C_COMPILER_ID:MSVC>:"
"$<$<CONFIG:Release>:/GL>"
"$<$<CONFIG:Release>:/fp:fast>"
"$<$<CONFIG:Release>:/Zi>"
">"
$<$<C_COMPILER_ID:AppleClang>:
$<$<STREQUAL:"${CMAKE_GENERATOR}","Ninja">:-O3>
>
)

target_link_options(epanet2
PUBLIC
"$<$<C_COMPILER_ID:MSVC>:"
"$<$<CONFIG:Release>:/LTCG:incremental>"
">"
)

if(UNIX)
target_link_libraries(epanet2
PRIVATE
m
)
endif()

target_include_directories(epanet2
PUBLIC
$<INSTALL_INTERFACE:${INCLUDE_DIST}>
PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
)

include(GenerateExportHeader)
generate_export_header(epanet2
STATIC_DEFINE SHARED_EXPORTS_BUILT_AS_STATIC
)

if(APPLE)
set(LIB_ROOT "@loader_path")
else()
set(LIB_ROOT "$ORIGIN")
endif()

set_target_properties(epanet2
PROPERTIES
MACOSX_RPATH TRUE
SKIP_BUILD_RPATH FALSE
BUILD_WITH_INSTALL_RPATH FALSE
INSTALL_RPATH "${LIB_ROOT};${PACKAGE_RPATH};"
INSTALL_RPATH_USE_LINK_PATH TRUE
)


install(TARGETS epanet2 EXPORT epanetTargets
RUNTIME DESTINATION "${TOOL_DIST}"
LIBRARY DESTINATION "${LIBRARY_DIST}"
ARCHIVE DESTINATION "${LIBRARY_DIST}"
FRAMEWORK DESTINATION "${TOOL_DIST}"
)

# Create target import scripts so other cmake projects can use swmm libraries
install(
EXPORT
epanetTargets
DESTINATION
"${CONFIG_DIST}"
FILE
epanet-config.cmake
)

install(
FILES
${EPANET_PUBLIC_HEADERS}
DESTINATION
"${INCLUDE_DIST}"
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit f5c766f

Please sign in to comment.