Skip to content

Commit 8467d38

Browse files
authored
Merge pull request #56 from sm-rana/dev-smmr
Made changes to enable compilation on Windows
2 parents fef6e01 + f5a606f commit 8467d38

4 files changed

Lines changed: 62 additions & 7 deletions

File tree

owa-epanet/CMakeLists.txt

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
cmake_minimum_required(VERSION 3.8)
22

3+
project(OWA-EPANET)
4+
35
if(SKBUILD)
46
message(STATUS "The project is built using scikit-build")
57
endif()
68

79
find_package(PythonLibs 3 REQUIRED)
810
find_package(PythonInterp ${PYTHONLIBS_VERSION_STRING} REQUIRED)
11+
# If find_package() has difficulty finding the appropriate python
12+
# directories and libraries (especially in Windows with multiple
13+
# versions of python) set them manually as in the next three lines
14+
# below (and comment out the above two find_package() lines):
15+
# set(PYTHON_EXECUTABLE "c:/python/python38/python.exe")
16+
# set(PYTHON_INCLUDE_PATH "c:/python/python38/include")
17+
# set(PYTHON_LIBRARIES "c:/python/python38/libs/python38.lib")
18+
919
find_package(SWIG REQUIRED)
1020
include(${SWIG_USE_FILE})
1121
set(CMAKE_SWIG_FLAGS -py3)
@@ -33,6 +43,7 @@ SWIG_ADD_LIBRARY( toolkit LANGUAGE python SOURCES wrapper/toolkit.i )
3343
set_property(SOURCE toolkit.i PROPERTY USE_LIBRARY_INCLUDE_DIRECTORIES TRUE)
3444
set_property(TARGET epanet2 PROPERTY SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE)
3545
SWIG_LINK_LIBRARIES(toolkit epanet2)
46+
3647
SWIG_LINK_LIBRARIES(toolkit ${PYTHON_LIBRARIES})
3748
set_property(TARGET _toolkit PROPERTY INSTALL_RPATH "$ORIGIN")
3849

@@ -55,11 +66,25 @@ add_custom_command(
5566
${CMAKE_CURRENT_BINARY_DIR}/toolkit.py
5667
${CMAKE_CURRENT_BINARY_DIR}/../../../packages/epanet/toolkit.py)
5768

58-
add_custom_command(
59-
TARGET _toolkit POST_BUILD
60-
COMMAND ${CMAKE_COMMAND} -E copy
61-
${CMAKE_CURRENT_BINARY_DIR}/lib/libepanet2.*
62-
${CMAKE_CURRENT_BINARY_DIR}/../../../packages/epanet/)
69+
IF(WIN32)
70+
add_custom_command(
71+
TARGET _toolkit POST_BUILD
72+
COMMAND ${CMAKE_COMMAND} -E copy
73+
${CMAKE_CURRENT_BINARY_DIR}/lib/Release/_toolkit.pyd
74+
${CMAKE_CURRENT_BINARY_DIR}/../../../packages/epanet/_toolkit.pyd)
75+
add_custom_command(
76+
TARGET _toolkit POST_BUILD
77+
COMMAND ${CMAKE_COMMAND} -E copy
78+
${CMAKE_CURRENT_BINARY_DIR}/bin/Release/epanet2.dll
79+
${CMAKE_CURRENT_BINARY_DIR}/../../../packages/epanet/epanet2.dll)
80+
ELSE(True)
81+
add_custom_command(
82+
TARGET _toolkit POST_BUILD
83+
COMMAND ${CMAKE_COMMAND} -E copy
84+
${CMAKE_CURRENT_BINARY_DIR}/lib/libepanet2.*
85+
${CMAKE_CURRENT_BINARY_DIR}/../../../packages/epanet/)
86+
ENDIF(WIN32)
87+
6388

6489

6590
#add_custom_command(

owa-epanet/EPANET

owa-epanet/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ A slender, auto-generated python wrapper around owa:epanet hydraulic network ana
44

55
Where possible, SWIG has been configured to throw warnings/exceptions instead of using the customary EPANET return integer value for success-checking. Also any output (pointer) parameters from the C API have been re-routed to return values. In these cases, the return tuple from the Python API will contain the values desired.
66

7-
```
87

8+
## Building the libraries
9+
10+
Ensure the EPANET subproject is populated by running `git submodule update --init` (if necessary) and running the following commands (on Windows skip the line `./script/clean.sh`). The following method uses `scikit-build` to invoke `cmake` for compiling and linking the shared libaries, and builds a python wheel.
11+
12+
```
913
./scripts/clean.sh
1014
python3 setup.py sdist bdist_wheel
15+
```
16+
Test your builds using the following commands.
17+
```
1118
cd test && pipenv install ../dist/*.whl && pipenv run python -c 'from epanet import toolkit; print(toolkit.__dict__)'
1219
1320
```

owa-epanet/build_owa-epanet.bat

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cls
2+
3+
rem Bulding the toolkit package for Windows. The preferred way to build the package is by running 'python setup.py sdist bdist_wheel'.
4+
5+
git submodule update --init
6+
7+
SET CMAKE_PATH=cmake.exe
8+
SET Build_PATH=%CD%
9+
SET COMPILE_PATH=%Build_PATH%\_cmake_build\windows\cmake-build
10+
11+
MKDIR "%COMPILE_PATH%"
12+
CD "%COMPILE_PATH%"
13+
rem Building 64-bit toolkit for 64-bit python.
14+
rem If 32-bit toolkit is required ensure 32-bit python is located
15+
rem by cmake (check CmakeList.txt) and replace '%CMAKE_PATH% ../ -A x64'
16+
rem with '%CMAKE_PATH% ../ -A Win32'."
17+
%CMAKE_PATH% ../../../ -A x64
18+
%CMAKE_PATH% --build . --config Release
19+
20+
rem 'After successful compilation "toolkit.py", "_toolkit.pyd", "epanet2.dll" will be created. You can start using the toolkit by importing the module "toolkit.py".
21+
22+
cd ..
23+
pause

0 commit comments

Comments
 (0)