Commit e40dc489 authored by Morales Hernandez, Mario's avatar Morales Hernandez, Mario
Browse files

Add CMake support for SWMM coupling

This commit adds CMake build support for the SWMM coupling feature,
migrating from the v1 Makefile-based build system.

Changes (CMakeLists.txt):
- Add TRITON_ENABLE_SWMM CMake option (default: OFF)
- Search for SWMM headers (swmm5.h) and library (libswmm5/swmm)
- Support multiple SWMM installation locations:
 * SWMM_ROOT_DIR environment variable
 * System paths (/usr/local, /usr)
 * Relative path: ../Stormwater-Management-Model
- Add -DTRITON_SWMM compile flag when enabled
- Link against SWMM library when enabled
- Fatal error if SWMM requested but not found

Usage:
 cmake -DTRITON_ENABLE_SWMM=ON ..
 make

Or with explicit paths:
 cmake -DTRITON_ENABLE_SWMM=ON \
       -DSWMM_INCLUDE_DIR=/path/to/swmm/include \
       -DSWMM_LIBRARY_DIR=/path/to/swmm/lib \
       ..
 make
parent ebc2f005
Loading
Loading
Loading
Loading
+48 −0
Original line number Diff line number Diff line
@@ -22,6 +22,49 @@ if(MACHINE STREQUAL Windows)
  find_package(MPI REQUIRED COMPONENTS CXX)
endif()

# SWMM coupling option
option(TRITON_ENABLE_SWMM "Enable SWMM coupling for urban drainage" OFF)

if(TRITON_ENABLE_SWMM)
  # Find SWMM library
  set(SWMM_ROOT_DIR "$ENV{SWMM_ROOT_DIR}" CACHE PATH "SWMM installation directory")
  set(SWMM_INCLUDE_DIR "${SWMM_ROOT_DIR}/include" CACHE PATH "SWMM include directory")
  set(SWMM_LIBRARY_DIR "${SWMM_ROOT_DIR}/lib" CACHE PATH "SWMM library directory")

  # Try to find SWMM headers
  find_path(SWMM_INCLUDE_PATH
    NAMES swmm5.h
    PATHS
      ${SWMM_INCLUDE_DIR}
      ${CMAKE_SOURCE_DIR}/external/swmm/include
      /usr/local/include/swmm
      /usr/include/swmm
      ${PROJECT_SOURCE_DIR}/../Stormwater-Management-Model/src/solver/include
    DOC "SWMM include directory"
  )

  # Try to find SWMM library
  find_library(SWMM_LIBRARY
    NAMES swmm5 swmm
    PATHS
      ${SWMM_LIBRARY_DIR}
      ${CMAKE_SOURCE_DIR}/external/swmm/lib
      /usr/local/lib
      /usr/lib
      ${PROJECT_SOURCE_DIR}/../Stormwater-Management-Model/build/bin
    DOC "SWMM library"
  )

  if(SWMM_INCLUDE_PATH AND SWMM_LIBRARY)
    message(STATUS "SWMM include directory: ${SWMM_INCLUDE_PATH}")
    message(STATUS "SWMM library: ${SWMM_LIBRARY}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTRITON_SWMM")
  else()
    message(FATAL_ERROR "SWMM coupling requested but SWMM library/headers not found. "
                       "Please set SWMM_ROOT_DIR or SWMM_INCLUDE_DIR and SWMM_LIBRARY_DIR")
  endif()
endif()

# add external packages
add_subdirectory(${TRITON_SOURCE_DIR}/external)

@@ -40,6 +83,11 @@ if (ENABLE_GDAL)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTRITON_GDAL")
endif()

if(TRITON_ENABLE_SWMM)
  target_include_directories(${TRITON_EXECUTABLE} PUBLIC ${SWMM_INCLUDE_PATH})
  target_link_libraries(${TRITON_EXECUTABLE} PUBLIC ${SWMM_LIBRARY})
endif()

add_build_and_run_scripts()

# add tests