From 0d3ca7dcaf34dcaacdbfb759964fa775f11cb314 Mon Sep 17 00:00:00 2001 From: Haohan Yang <37651510+haohanyang@users.noreply.github.com> Date: Thu, 21 Nov 2024 18:48:32 +0100 Subject: [PATCH] Use `ExternalProject_Add` to install iphreeqc (#3) * Build IPhreeqc seperatly * Remove apply_patch * Remove circle ci * add sudo * Use ExternalProject_Add * Add pic * Add option IPHREEQC_VERSION * add publish to test pypi ci --- .circleci/config.yml | 81 ------ .github/workflows/ci.yaml | 12 +- .github/workflows/test-pypi.yaml | 85 ++++++ .gitignore | 5 +- .gitmodules | 3 - CMakeLists.txt | 471 +------------------------------ apply_patch.py | 6 - iphreeqc | 1 - script.py | 30 ++ src/main.cpp | 2 +- src/phreeqc/__init__.py | 2 +- 11 files changed, 144 insertions(+), 554 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/test-pypi.yaml delete mode 100644 apply_patch.py delete mode 160000 iphreeqc create mode 100644 script.py diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 9b44908..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,81 +0,0 @@ -version: 2 - -jobs: - linux-wheels: - working_directory: ~/linux-wheels - docker: - - image: cimg/python:3.12 - steps: - - checkout - - run: - name: Fetch submodules - command: git submodule update --init - - setup_remote_docker - - run: - name: Build sdist - command: | - pipx run build --sdist - pipx run twine check dist/* - - store_artifacts: - path: dist/ - - run: - name: Build the Linux wheels - environment: - CIBW_BUILD: cp312-* - CIBW_ARCHS_LINUX: x86_64 - command: | - python3 -m pip install --user cibuildwheel==2.21.3 - cibuildwheel --output-dir wheelhouse - - store_artifacts: - path: wheelhouse/ - - macos-wheels: - working_directory: ~/macos-wheels - macos: - xcode: 15.4.0 - resource_class: macos.m1.medium.gen1 - steps: - - checkout - - run: - name: Fetch submodules - command: git submodule update --init - - run: - name: Build the macOS wheels - environment: - CIBW_BUILD: cp312-* - CIBW_ARCHS_MACOS: "x86_64 arm64" - command: | - sudo softwareupdate --install-rosetta --agree-to-license # for python<=3.8 or x86_64/universal2 tests - pip3 install cibuildwheel==2.21.3 - cibuildwheel --output-dir wheelhouse - - store_artifacts: - path: wheelhouse/ - - windows-wheels: - machine: - image: "windows-server-2022-gui:current" - shell: "powershell.exe -ExecutionPolicy Bypass" - resource_class: "windows.medium" - steps: - - checkout - - run: - name: Fetch submodules - command: git submodule update --init - - run: - name: Build the Windows wheels - environment: - CIBW_BUILD: cp312-* - CIBW_ARCHS_WINDOWS: "AMD64" - command: | - pip3 install cibuildwheel==2.21.3 - cibuildwheel --output-dir wheelhouse - - store_artifacts: - path: wheelhouse - -workflows: - version: 2 - build-wheels: - jobs: - - linux-wheels - - macos-wheels - - windows-wheels diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a28d7f2..4321d6e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -8,9 +8,13 @@ on: - README.md jobs: - build-and-test: - name: Build and test - runs-on: ubuntu-latest + build-iphreeqc: + name: Build IPhreeqc Python bindings + strategy: + fail-fast: true + matrix: + os: [macos-latest, windows-latest, ubuntu-latest] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 with: @@ -18,7 +22,7 @@ jobs: - uses: actions/setup-python@v5 with: python-version: '3.12' - - name: Build the package using pip + - name: Build Python bindings run: pip install . pytest - name: Test run: pytest tests \ No newline at end of file diff --git a/.github/workflows/test-pypi.yaml b/.github/workflows/test-pypi.yaml new file mode 100644 index 0000000..8970579 --- /dev/null +++ b/.github/workflows/test-pypi.yaml @@ -0,0 +1,85 @@ +name: Build wheels and publish to test pypi + +on: + workflow_dispatch: + inputs: + package_version: + description: "Version of phreeqc package" + type: string + required: true + +jobs: + build-sdist: + name: Build sdist + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - uses: actions/setup-python@v5 + with: + python-version: '3.9' + - name: Update version + run: python script.py version ${{ github.event.inputs.package_version }} + - name: Build sdist + run: pipx run build --sdist + - name: Check metadata + run: pipx run twine check dist/* + - uses: actions/upload-artifact@v4 + with: + name: cibw-sdist + path: dist/*.tar.gz + + build-wheels: + name: Build wheels + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + os: [macos-latest, windows-latest, ubuntu-latest] + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - uses: actions/setup-python@v5 + with: + python-version: '3.9' + - name: Update version + run: python script.py version ${{ github.event.inputs.package_version }} + - name: Build wheels + uses: pypa/cibuildwheel@v2.21.3 + env: + CIBW_ARCHS_MACOS: "x86_64 arm64" + CIBW_ARCHS_WINDOWS: AMD64 + CIBW_ARCHS_LINUX: x86_64 + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: cibw-wheels-${{ matrix.os }} + path: wheelhouse/*.whl + + publish: + name: Publish wheels to pypi + runs-on: ubuntu-latest + needs: [build-wheels, build-sdist] + permissions: + id-token: write + attestations: write + steps: + - name: Download all dists + uses: actions/download-artifact@v4 + with: + path: dist + pattern: cibw-* + merge-multiple: true + - name: Generate artifact attestation for sdist and wheels + uses: actions/attest-build-provenance@v1 + with: + subject-path: "dist/*" + - name: Publish package to test pypi + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.TEST_PYPI_API_TOKEN }} + verbose: true + attestations: true + repository-url: https://test.pypi.org/legacy/ \ No newline at end of file diff --git a/.gitignore b/.gitignore index 763ce87..d9306e0 100644 --- a/.gitignore +++ b/.gitignore @@ -188,4 +188,7 @@ dmypy.json .pytype/ # Cython debug symbols -cython_debug/ \ No newline at end of file +cython_debug/ + +iphreeqc-build/ +iphreeqc-install/ \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index 5ed2c84..a90eb86 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "pybind11"] path = pybind11 url = https://github.com/pybind/pybind11.git -[submodule "iphreeqc"] - path = iphreeqc - url = https://github.com/usgs-coupled/iphreeqc.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 8cf9f2f..f7bbfbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,470 +1,29 @@ -# CMAKE_MSVC_RUNTIME_LIBRARY requires 3.15 -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.20) -project ( - phreeqc - VERSION 3.8.3 - LANGUAGES CXX C - ) +project(phreeqc) -set(STANDALONE_BUILD 0) - -if (STANDALONE_BUILD) - # Set a default build type if none was specified - set(default_build_type "Release") - if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE - STRING "Choose the type of build." FORCE) - # Set the possible values of build type for cmake-gui - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS - "Debug" "Release" "MinSizeRel" "RelWithDebInfo") - endif() -endif() - -# overide docdir on windows -if (WIN32 AND NOT CMAKE_INSTALL_DOCDIR) - set(CMAKE_INSTALL_DOCDIR "" CACHE PATH "documentation root (doc)") - set(CMAKE_INSTALL_DOCDIR "doc") -endif() - -# set standard directory locations -include(GNUInstallDirs) - -if (STANDALONE_BUILD AND MSVC) - option (IPHREEQC_STATIC_RUNTIME "Build with a static runtime" OFF) - if (IPHREEQC_STATIC_RUNTIME) - # compile with static runtime - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") - endif() -endif() - -# Fortran -option (IPHREEQC_ENABLE_MODULE "Enable Fortran module" ON) -if (STANDALONE_BUILD) - if (IPHREEQC_FORTRAN_TESTING) - enable_language(Fortran) - else() - if (CMAKE_Fortran_COMPILER) - option (IPHREEQC_FORTRAN_TESTING "Build Fortran test" ON) - else() - option (IPHREEQC_FORTRAN_TESTING "Build Fortran test" OFF) - endif() - endif() -endif() - -# compile Var.c as c++ -set_source_files_properties(iphreeqc/src/Var.c PROPERTIES LANGUAGE CXX) - -if (STANDALONE_BUILD) - option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) - set(LIB_TYPE STATIC) -endif() - -if (STANDALONE_BUILD) - if (MSVC) - option(BUILD_CLR_LIBS "Build CLR Libraries" OFF) - endif() -endif() - -if (BUILD_SHARED_LIBS) - set(LIB_TYPE SHARED) -endif() +include(ExternalProject) add_subdirectory(pybind11) -pybind11_add_module(IPhreeqc ${LIB_TYPE} src/main.cpp) +option(IPHREEQC_VERSION "IPhreeqc version or tag name of the IPhreeqc repository" "v3.8.3") -target_sources(IPhreeqc - PRIVATE - iphreeqc/src/IPhreeqc.cpp - iphreeqc/src/CSelectedOutput.cpp - iphreeqc/src/CSelectedOutput.hxx - iphreeqc/src/CVar.hxx - iphreeqc/src/Debug.h - iphreeqc/src/ErrorReporter.hxx - iphreeqc/src/IPhreeqc.h - iphreeqc/src/IPhreeqc.hpp - iphreeqc/src/IPhreeqc_interface_F.cpp - iphreeqc/src/IPhreeqcCallbacks.h - iphreeqc/src/IPhreeqcLib.cpp - iphreeqc/src/phreeqcpp/advection.cpp - iphreeqc/src/phreeqcpp/basicsubs.cpp - iphreeqc/src/phreeqcpp/cl1.cpp - iphreeqc/src/phreeqcpp/common/Parser.cxx - iphreeqc/src/phreeqcpp/common/Parser.h - iphreeqc/src/phreeqcpp/common/PHRQ_base.cxx - iphreeqc/src/phreeqcpp/common/PHRQ_base.h - iphreeqc/src/phreeqcpp/common/PHRQ_exports.h - iphreeqc/src/phreeqcpp/common/PHRQ_io.cpp - iphreeqc/src/phreeqcpp/common/PHRQ_io.h - iphreeqc/src/phreeqcpp/common/phrqtype.h - iphreeqc/src/phreeqcpp/common/Utils.cxx - iphreeqc/src/phreeqcpp/common/Utils.h - iphreeqc/src/phreeqcpp/cvdense.cpp - iphreeqc/src/phreeqcpp/cvdense.h - iphreeqc/src/phreeqcpp/cvode.cpp - iphreeqc/src/phreeqcpp/cvode.h - iphreeqc/src/phreeqcpp/cxxKinetics.cxx - iphreeqc/src/phreeqcpp/cxxKinetics.h - iphreeqc/src/phreeqcpp/cxxMix.cxx - iphreeqc/src/phreeqcpp/cxxMix.h - iphreeqc/src/phreeqcpp/dense.cpp - iphreeqc/src/phreeqcpp/dense.h - iphreeqc/src/phreeqcpp/Dictionary.cpp - iphreeqc/src/phreeqcpp/Dictionary.h - iphreeqc/src/phreeqcpp/dumper.cpp - iphreeqc/src/phreeqcpp/dumper.h - iphreeqc/src/phreeqcpp/Exchange.cxx - iphreeqc/src/phreeqcpp/Exchange.h - iphreeqc/src/phreeqcpp/ExchComp.cxx - iphreeqc/src/phreeqcpp/ExchComp.h - iphreeqc/src/phreeqcpp/GasComp.cxx - iphreeqc/src/phreeqcpp/GasComp.h - iphreeqc/src/phreeqcpp/gases.cpp - iphreeqc/src/phreeqcpp/GasPhase.cxx - iphreeqc/src/phreeqcpp/GasPhase.h - iphreeqc/src/phreeqcpp/global_structures.h - iphreeqc/src/phreeqcpp/input.cpp - iphreeqc/src/phreeqcpp/integrate.cpp - iphreeqc/src/phreeqcpp/inverse.cpp - iphreeqc/src/phreeqcpp/ISolution.cxx - iphreeqc/src/phreeqcpp/ISolution.h - iphreeqc/src/phreeqcpp/ISolutionComp.cxx - iphreeqc/src/phreeqcpp/ISolutionComp.h - iphreeqc/src/phreeqcpp/isotopes.cpp - iphreeqc/src/phreeqcpp/kinetics.cpp - iphreeqc/src/phreeqcpp/KineticsComp.cxx - iphreeqc/src/phreeqcpp/KineticsComp.h - iphreeqc/src/phreeqcpp/mainsubs.cpp - iphreeqc/src/phreeqcpp/model.cpp - iphreeqc/src/phreeqcpp/NA.h - iphreeqc/src/phreeqcpp/NameDouble.cxx - iphreeqc/src/phreeqcpp/NameDouble.h - iphreeqc/src/phreeqcpp/NumKeyword.cxx - iphreeqc/src/phreeqcpp/NumKeyword.h - iphreeqc/src/phreeqcpp/nvector.cpp - iphreeqc/src/phreeqcpp/nvector.h - iphreeqc/src/phreeqcpp/nvector_serial.cpp - iphreeqc/src/phreeqcpp/nvector_serial.h - iphreeqc/src/phreeqcpp/parse.cpp - iphreeqc/src/phreeqcpp/PBasic.cpp - iphreeqc/src/phreeqcpp/PBasic.h - iphreeqc/src/phreeqcpp/phqalloc.cpp - iphreeqc/src/phreeqcpp/phqalloc.h - iphreeqc/src/phreeqcpp/Phreeqc.cpp - iphreeqc/src/phreeqcpp/Phreeqc.h - iphreeqc/src/phreeqcpp/PhreeqcKeywords/Keywords.cpp - iphreeqc/src/phreeqcpp/PhreeqcKeywords/Keywords.h - iphreeqc/src/phreeqcpp/PHRQ_io_output.cpp - iphreeqc/src/phreeqcpp/pitzer.cpp - iphreeqc/src/phreeqcpp/pitzer_structures.cpp - iphreeqc/src/phreeqcpp/PPassemblage.cxx - iphreeqc/src/phreeqcpp/PPassemblage.h - iphreeqc/src/phreeqcpp/PPassemblageComp.cxx - iphreeqc/src/phreeqcpp/PPassemblageComp.h - iphreeqc/src/phreeqcpp/prep.cpp - iphreeqc/src/phreeqcpp/Pressure.cxx - iphreeqc/src/phreeqcpp/Pressure.h - iphreeqc/src/phreeqcpp/print.cpp - iphreeqc/src/phreeqcpp/Reaction.cxx - iphreeqc/src/phreeqcpp/Reaction.h - iphreeqc/src/phreeqcpp/read.cpp - iphreeqc/src/phreeqcpp/ReadClass.cxx - iphreeqc/src/phreeqcpp/readtr.cpp - iphreeqc/src/phreeqcpp/runner.cpp - iphreeqc/src/phreeqcpp/runner.h - iphreeqc/src/phreeqcpp/SelectedOutput.cpp - iphreeqc/src/phreeqcpp/SelectedOutput.h - iphreeqc/src/phreeqcpp/Serializer.cxx - iphreeqc/src/phreeqcpp/Serializer.h - iphreeqc/src/phreeqcpp/sit.cpp - iphreeqc/src/phreeqcpp/smalldense.cpp - iphreeqc/src/phreeqcpp/smalldense.h - iphreeqc/src/phreeqcpp/Solution.cxx - iphreeqc/src/phreeqcpp/Solution.h - iphreeqc/src/phreeqcpp/SolutionIsotope.cxx - iphreeqc/src/phreeqcpp/SolutionIsotope.h - iphreeqc/src/phreeqcpp/spread.cpp - iphreeqc/src/phreeqcpp/SS.cxx - iphreeqc/src/phreeqcpp/SS.h - iphreeqc/src/phreeqcpp/SSassemblage.cxx - iphreeqc/src/phreeqcpp/SSassemblage.h - iphreeqc/src/phreeqcpp/SScomp.cxx - iphreeqc/src/phreeqcpp/SScomp.h - iphreeqc/src/phreeqcpp/step.cpp - iphreeqc/src/phreeqcpp/StorageBin.cxx - iphreeqc/src/phreeqcpp/StorageBin.h - iphreeqc/src/phreeqcpp/StorageBinList.cpp - iphreeqc/src/phreeqcpp/StorageBinList.h - iphreeqc/src/phreeqcpp/structures.cpp - iphreeqc/src/phreeqcpp/sundialsmath.cpp - iphreeqc/src/phreeqcpp/sundialsmath.h - iphreeqc/src/phreeqcpp/sundialstypes.h - iphreeqc/src/phreeqcpp/Surface.cxx - iphreeqc/src/phreeqcpp/Surface.h - iphreeqc/src/phreeqcpp/SurfaceCharge.cxx - iphreeqc/src/phreeqcpp/SurfaceCharge.h - iphreeqc/src/phreeqcpp/SurfaceComp.cxx - iphreeqc/src/phreeqcpp/SurfaceComp.h - iphreeqc/src/phreeqcpp/System.cxx - iphreeqc/src/phreeqcpp/System.h - iphreeqc/src/phreeqcpp/tally.cpp - iphreeqc/src/phreeqcpp/Temperature.cxx - iphreeqc/src/phreeqcpp/Temperature.h - iphreeqc/src/phreeqcpp/tidy.cpp - iphreeqc/src/phreeqcpp/transport.cpp - iphreeqc/src/phreeqcpp/Use.cpp - iphreeqc/src/phreeqcpp/Use.h - iphreeqc/src/phreeqcpp/UserPunch.cpp - iphreeqc/src/phreeqcpp/UserPunch.h - iphreeqc/src/phreeqcpp/utilities.cpp - iphreeqc/src/thread.h - iphreeqc/src/Var.c - iphreeqc/src/Var.h - iphreeqc/src/Version.h +ExternalProject_Add(IPhreeqcBuild + GIT_REPOSITORY https://github.com/usgs-coupled/iphreeqc.git + GIT_TAG ${IPHREEQC_VERSION} + CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${CMAKE_SOURCE_DIR}/iphreeqc-install" "-DBUILD_TESTING=OFF" "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_POSITION_INDEPENDENT_CODE=ON" + INSTALL_DIR "${CMAKE_SOURCE_DIR}/iphreeqc-install" ) -target_include_directories(IPhreeqc - PUBLIC - iphreeqc/src - iphreeqc/src/phreeqcpp - iphreeqc/src/phreeqcpp/common - iphreeqc/src/phreeqcpp/PhreeqcKeywords - ) - -target_compile_definitions(IPhreeqc PRIVATE SWIG_SHARED_OBJ) -target_compile_definitions(IPhreeqc PRIVATE USE_PHRQ_ALLOC) - -if (NOT IPHREEQC_ENABLE_MODULE) - target_compile_definitions(IPhreeqc - PUBLIC - IPHREEQC_NO_FORTRAN_MODULE - ) - - target_sources(IPhreeqc - PRIVATE - iphreeqc/src/fimpl.h - iphreeqc/src/fwrap.cpp - iphreeqc/src/fwrap1.cpp - iphreeqc/src/fwrap2.cpp - iphreeqc/src/fwrap3.cpp - iphreeqc/src/fwrap4.cpp - iphreeqc/src/fwrap5.cpp - iphreeqc/src/fwrap6.cpp - iphreeqc/src/fwrap7.cpp - iphreeqc/src/fwrap8.cpp - ) -endif() - -if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC) - target_compile_options(IPhreeqc PRIVATE /wd4251 /wd4275 /wd4793) -endif() - -# Disable deprecation warnings for standard C and STL functions in VS2005 -# and later -if (MSVC_VERSION EQUAL 1400 OR MSVC_VERSION GREATER 1400) - target_compile_definitions(IPhreeqc PUBLIC _CRT_SECURE_NO_DEPRECATE) - target_compile_definitions(IPhreeqc PUBLIC _SCL_SECURE_NO_WARNINGS) -endif() - -if (WIN32 AND BUILD_SHARED_LIBS) - # Required to build IMPLIB - # (Seems to be automatically set when using Visual Studio as the generator) - target_compile_definitions(IPhreeqc PRIVATE _WINDLL) -endif() - -# Allow user to override POSTFIX properties (but mandate them so that -# all builds can be installed to the same directory) -if (NOT CMAKE_DEBUG_POSTFIX) - set_target_properties(IPhreeqc PROPERTIES DEBUG_POSTFIX "d") -endif() - -if (NOT CMAKE_MINSIZEREL_POSTFIX) - set_target_properties(IPhreeqc PROPERTIES MINSIZEREL_POSTFIX "msr") -endif() - -if (NOT CMAKE_RELWITHDEBINFO_POSTFIX) - set_target_properties(IPhreeqc PROPERTIES RELWITHDEBINFO_POSTFIX "rwd") -endif() - -set(IPhreeqc_Headers - ${PROJECT_SOURCE_DIR}/iphreeqc/src/IPhreeqc.h - ${PROJECT_SOURCE_DIR}/iphreeqc/src/IPhreeqc.hpp - ${PROJECT_SOURCE_DIR}/iphreeqc/src/IPhreeqcCallbacks.h - ${PROJECT_SOURCE_DIR}/iphreeqc/src/phreeqcpp/PhreeqcKeywords/Keywords.h - ${PROJECT_SOURCE_DIR}/iphreeqc/src/phreeqcpp/common/PHRQ_exports.h - ${PROJECT_SOURCE_DIR}/iphreeqc/src/phreeqcpp/common/PHRQ_io.h - ${PROJECT_SOURCE_DIR}/iphreeqc/src/Var.h - ) - -if (IPHREEQC_ENABLE_MODULE) - set(IPhreeqc_SRC - ${PROJECT_SOURCE_DIR}/iphreeqc/src/IPhreeqc_interface.F90 - ${PROJECT_SOURCE_DIR}/iphreeqc/src/README.Fortran - ) -else() - # always install README.Fortran - set(IPhreeqc_SRC - ${PROJECT_SOURCE_DIR}/iphreeqc/src/README.Fortran - ) - # install old fortran include files - set(IPhreeqc_Headers - ${IPhreeqc_Headers} - ${PROJECT_SOURCE_DIR}/iphreeqc/src/IPhreeqc.f.inc - ${PROJECT_SOURCE_DIR}/iphreeqc/src/IPhreeqc.f90.inc - ) -endif() - -# Setup references for /CLR -if (MSVC AND BUILD_SHARED_LIBS AND BUILD_CLR_LIBS) - if (MSVC_VERSION LESS 1600) - message(FATAL_ERROR "CLR options must be set manually for versions prior to Visual Studio 2010") - endif() - set_target_properties(IPhreeqc PROPERTIES VS_DOTNET_REFERENCES "System;System.Drawing;System.Windows.Forms;${CMAKE_CURRENT_SOURCE_DIR}/iphreeqc/src/phreeqcpp/ZedGraph.dll") - set_target_properties(IPhreeqc PROPERTIES COMMON_LANGUAGE_RUNTIME "") - target_compile_definitions(IPhreeqc PRIVATE "MULTICHART") -endif() - -set_target_properties(IPhreeqc PROPERTIES - VERSION "${IPhreeqc_VERSION}" - SOVERSION "${IPhreeqc_VERSION_MAJOR}" - ) - -# install -if (STANDALONE_BUILD) - - include(CMakePackageConfigHelpers) - - configure_package_config_file(IPhreeqcConfig.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/IPhreeqcConfig.cmake - INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/IPhreeqc - ) - - write_basic_package_version_file("IPhreeqcConfigVersion.cmake" - VERSION ${IPhreeqc_VERSION} - COMPATIBILITY SameMajorVersion - ) - - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/IPhreeqcConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/IPhreeqcConfigVersion.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/IPhreeqc - ) - - install(TARGETS IPhreeqc - EXPORT IPhreeqcTargets - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - ) - install(EXPORT IPhreeqcTargets - FILE IPhreeqcTargets.cmake - NAMESPACE IPhreeqc:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/IPhreeqc - ) - - install(FILES ${IPhreeqc_Headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) - if (WIN32) - install(FILES ${IPhreeqc_SRC} DESTINATION src) - else() - install(FILES ${IPhreeqc_SRC} DESTINATION ${CMAKE_INSTALL_DOCDIR}/src) - endif() - if (BUILD_CLR_LIBS) - install(FILES "${PROJECT_SOURCE_DIR}/iphreeqc/src/phreeqcpp/ZedGraph.dll" DESTINATION ${CMAKE_INSTALL_BINDIR}) - endif() -endif() - -if (BUILD_CLR_LIBS) - if (NOT BUILD_SHARED_LIBS) - message(FATAL_ERROR "BUILD_CLR_LIBS requires that BUILD_SHARED_LIBS be set") - endif() - - if (IPHREEQC_STATIC_RUNTIME) - message(FATAL_ERROR "BUILD_CLR_LIBS and IPHREEQC_STATIC_RUNTIME are mutually exclusive") - endif() - - # CLR files - target_sources(IPhreeqc - PRIVATE - iphreeqc/src/phreeqcpp/ChartHandler.cpp - iphreeqc/src/phreeqcpp/ChartHandler.h - iphreeqc/src/phreeqcpp/ChartObject.cpp - iphreeqc/src/phreeqcpp/ChartObject.h - iphreeqc/src/phreeqcpp/CurveObject.cpp - iphreeqc/src/phreeqcpp/CurveObject.h - ) - -endif() - -include (CTest) - -if (STANDALONE_BUILD) - - add_subdirectory(database) - add_subdirectory(doc) - add_subdirectory(examples) - - if (BUILD_TESTING) - add_subdirectory(tests) - endif() - - - if (BUILD_TESTING) # may need to add MSVC version check - include(FetchContent) - - # Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24: - if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") - cmake_policy(SET CMP0135 NEW) - endif() - - FetchContent_Declare( - googletest - URL https://github.com/google/googletest/archive/release-1.12.1.tar.gz - ) - - mark_as_advanced( - FETCHCONTENT_BASE_DIR - FETCHCONTENT_FULLY_DISCONNECTED - FETCHCONTENT_QUIET - FETCHCONTENT_SOURCE_DIR_GOOGLETEST - FETCHCONTENT_UPDATES_DISCONNECTED - FETCHCONTENT_UPDATES_DISCONNECTED_GOOGLETEST - ) - - # Prevent GoogleTest from overriding our compiler/linker options - # when building with Visual Studio - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - - set(BUILD_GTEST ON CACHE BOOL "" FORCE) - set(BUILD_GMOCK ON CACHE BOOL "" FORCE) - set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) - set(INSTALL_GMOCK OFF CACHE BOOL "" FORCE) +pybind11_add_module(_iphreeqc MODULE "${CMAKE_SOURCE_DIR}/src/main.cpp") - mark_as_advanced( - BUILD_GTEST - BUILD_GMOCK - INSTALL_GTEST - INSTALL_GMOCK - gmock_build_tests - gtest_build_tests - gtest_build_samples - gtest_disable_pthreads - gtest_force_shared_crt - gtest_hide_internal_symbols - ) +add_dependencies(_iphreeqc IPhreeqcBuild) - FetchContent_GetProperties(googletest) - if (NOT googletest_POPULATED) - # Always build googletest static - set(SAVE_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) - set(BUILD_SHARED_LIBS OFF) - FetchContent_MakeAvailable(googletest) - set(BUILD_SHARED_LIBS ${SAVE_BUILD_SHARED_LIBS}) - endif() +target_link_directories(_iphreeqc PRIVATE "${CMAKE_SOURCE_DIR}/iphreeqc-install/lib") - add_subdirectory(gtest) - endif() -endif() +target_include_directories(_iphreeqc PRIVATE "${CMAKE_SOURCE_DIR}/iphreeqc-install/include") +target_link_libraries(_iphreeqc PRIVATE IPhreeqc) -install(TARGETS IPhreeqc DESTINATION phreeqc) \ No newline at end of file +install(TARGETS _iphreeqc DESTINATION phreeqc) \ No newline at end of file diff --git a/apply_patch.py b/apply_patch.py deleted file mode 100644 index df64208..0000000 --- a/apply_patch.py +++ /dev/null @@ -1,6 +0,0 @@ -import os.path -import subprocess - -patch_path = os.path.abspath("cmake.patch") - -subprocess.run(["git", "apply", patch_path], cwd="iphreeqc") diff --git a/iphreeqc b/iphreeqc deleted file mode 160000 index 734c4b2..0000000 --- a/iphreeqc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 734c4b2cb899a16325687df43f0b6c8424721773 diff --git a/script.py b/script.py new file mode 100644 index 0000000..293a765 --- /dev/null +++ b/script.py @@ -0,0 +1,30 @@ +import re +import sys + + +def replace_version(filepath, new_version): + """Replaces the version number in a file. + + Args: + filepath: The path to the file. + new_version: The new version string. + """ + with open(filepath, "r") as f: + content = f.read() + + # Use a regular expression to find and replace the version string + new_content = re.sub( + r'version\s*=\s*"(.*?)"', f'version = "{new_version}"', content + ) + + with open(filepath, "w") as f: + f.write(new_content) + + +if __name__ == "__main__": + if len(sys.argv) >= 3 and sys.argv[1] == "version": + file_path = "pyproject.toml" + new_version_number = sys.argv[2] + replace_version(file_path, new_version_number) + else: + raise ValueError("Invalid input") diff --git a/src/main.cpp b/src/main.cpp index 956df8b..437bc49 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -98,7 +98,7 @@ namespace Bindings }; } -PYBIND11_MODULE(IPhreeqc, m) +PYBIND11_MODULE(_iphreeqc, m) { m.doc() = "Python bindings for PHREEQC Version 3"; py::class_(m, "Phreeqc") diff --git a/src/phreeqc/__init__.py b/src/phreeqc/__init__.py index b718ded..c132053 100644 --- a/src/phreeqc/__init__.py +++ b/src/phreeqc/__init__.py @@ -1,5 +1,5 @@ from __future__ import annotations -from .IPhreeqc import Phreeqc +from ._iphreeqc import Phreeqc __all__ = ["__doc__", "Phreeqc", "__version__"]