PhreeqcUsers Discussion Forum
Click here to donate to keep PhreeqcUsers open

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 

  • Forum Home
  • Login
  • Register

  • PhreeqcUsers Discussion Forum »
  • Beginners »
  • Installation questions »
  • Introducing PhreeqcRM as an external library to CMake
« previous next »
  • Print
Pages: [1]   Go Down

Author Topic: Introducing PhreeqcRM as an external library to CMake  (Read 161 times)

Sara Tabrizi

  • Frequent Contributor
  • Posts: 10
Introducing PhreeqcRM as an external library to CMake
« on: March 09, 2023, 07:40:51 PM »
Hello,
I am trying to compile Phreeqcrm as an external library in a C++ environment which is configured using CMake. Although the process was straightforward by adding the library (-l) and the library path (-L) to the Makefile, it seems to be not clear to me in this environment since the external dependencies are configured using the find_package mechanism. My question is that what are the requirements to introduce phreeqcrm to CMake? I have read about adding an external package to Cmake and I have tried to use the command: -D<Package>_DIR=<path/to/package/config> for the CMake in our make file. For <Package> I used: phreeqcrm and for <path/to/package/config> I used the location of the configuration file of PhreeqcRM. After compilation of make file, for compiling the code, I still receive the error that phreeqcrm is not defined. I really appreciate if you could give me some advice about the way I am introducing phreeqcrm to CMake, that would be a big help.
Best regards,
Sara Tabrizinejadas
Logged

charlton

  • Top Contributor
  • Posts: 26
Re: Introducing PhreeqcRM as an external library to CMake
« Reply #1 on: March 10, 2023, 12:52:57 AM »
Hi Sara,

It's a little complicated to explain, so let me create an example for you.

I'll let you know when it's done.

Scott Charlton
Logged

charlton

  • Top Contributor
  • Posts: 26
Re: Introducing PhreeqcRM as an external library to CMake
« Reply #2 on: March 10, 2023, 01:56:17 AM »
Hi Sara,

Could you please let me know which operating system you are using?

Thanks,
Scott
Logged

Sara Tabrizi

  • Frequent Contributor
  • Posts: 10
Re: Introducing PhreeqcRM as an external library to CMake
« Reply #3 on: March 10, 2023, 07:55:06 AM »
Hi Dear Dr.Charlton,
I am using Linux. Thank you so much for the example.
Best regards,
Sara
Logged

charlton

  • Top Contributor
  • Posts: 26
Re: Introducing PhreeqcRM as an external library to CMake
« Reply #4 on: March 10, 2023, 07:05:53 PM »
Hi Sara,

I have created a github repository to demonstrate using phreeqcrm with cmake here:

https://github.com/usgs-coupled/phreeqcrm_use_cmake

Let us know if you have any questions.

Scott


Update:

I also added Modern CMake (using find_package) Instructions on the modern branch:

https://github.com/usgs-coupled/phreeqcrm_use_cmake/tree/modern

That uses our latest version of phreeqcrm at:

https://github.com/usgs-coupled/phreeqcrm  (commit 8c960d4 or newer)
« Last Edit: March 11, 2023, 03:53:17 AM by charlton »
Logged

Sara Tabrizi

  • Frequent Contributor
  • Posts: 10
Re: Introducing PhreeqcRM as an external library to CMake
« Reply #5 on: March 11, 2023, 03:19:40 PM »
Hi Dear Dr.Charlton,
I really appreciate your example.  I have tried to understand the file CMakelists.txt. For defining the library path and the package there are the variables PhreeqcRM_LIB and PhreeqcRM_INC, respectively. These variables are not defined in the system when I try to compile them. I have difficulty understanding how their location is given to the CMake. I have copy pasted the file phreeqcrm.h and three libraries of Phreeqcrm (.so, .a and .la) to the directory "{CMAKE_CURRENT_LIST_DIR}/../phreeqcrm" that has been used for initializing the CMake, but still they are not introduced to the system. I appreciate the clarification about that.
Best regards,
Sara
Logged

charlton

  • Top Contributor
  • Posts: 26
Re: Introducing PhreeqcRM as an external library to CMake
« Reply #6 on: March 11, 2023, 11:53:46 PM »
The call to find_library fills in the variable PhreeqcRM_LIB if the PhreeqcRM library is found.  It uses locations provided by the CMAKE_PREFIX_PATH variable to find it (along with other variables see https://cmake.org/cmake/help/v3.20/command/find_library.html).  The  PhreeqcRM_INC variable is set similarly using the find_path (https://cmake.org/cmake/help/v3.20/command/find_path.html) method.

You don't need to copy files into ${CMAKE_CURRENT_LIST_DIR}/../phreeqcrm.  Just run the command:

Code: [Select]
cmake -P build_phreeqcrm.cmake
in the phreeqcrm_use_cmake directory.

Hopefully you know how to use git to clone https://github.com/usgs-coupled/phreeqcrm_use_cmake?

Scott
Logged

Sara Tabrizi

  • Frequent Contributor
  • Posts: 10
Re: Introducing PhreeqcRM as an external library to CMake
« Reply #7 on: March 15, 2023, 09:28:47 AM »
Hi Dr.Charlton,
Thank you so much for your replies. I understood your example well. I have been spending some days trying to apply the same approach to my work, but still I have not been successful. What I am trying to do is to use another command which internally invokes cmake. I am using the command dunecontrol to configure the project. As it is explained in the tutorial of linking external libraries to this command, https://www.dune-project.org/doc/installation/external-libraries/
I have to use the find_package command and it explicitly requires three commands linking to configure file, include file and library of Phreeqc. The configure file should be named by <Package>Config.cmake. My question is if this package is provided in PhreeqcRM? because when I rename the file configure to PhreeqcRMConfig.cmake, I receive error and it seems to me that this is not the format of file that I should use.
I deeply appreciate your response.
Best regards,
Sara
Logged

charlton

  • Top Contributor
  • Posts: 26
Re: Introducing PhreeqcRM as an external library to CMake
« Reply #8 on: March 16, 2023, 10:07:36 PM »
Hi Sara,

Try using the commit I tagged for you:

Code: [Select]
git clone https://github.com/usgs-coupled/phreeqcrm.git phreeqcrm-sara
cd phreeqcrm-sara
git checkout sara
cmake -S . -B build/release -DCMAKE_BUILD_TYPE=Release
cmake --build build/release -j4
sudo cmake --install build/release
cmake -S . -B build/debug -DCMAKE_BUILD_TYPE=Debug
cmake --build build/debug -j4
sudo cmake --install build/debug

it creates the PhreeqcRMConfig.cmake files I think you need.  We are currently working a lot on phreeqcrm so it's a moving target right now.  Using the default install location and sudo will install the cmake files in the /usr/local/lib/cmake/PhreeqcRM directory.  Hopefully dune will be able to find them there.

You can increaseor decrease the -j4 if you have more or less cpus.

Scott
Logged

  • Print
Pages: [1]   Go Up
« previous next »
  • PhreeqcUsers Discussion Forum »
  • Beginners »
  • Installation questions »
  • Introducing PhreeqcRM as an external library to CMake
 

  • SMF 2.0.17 | SMF © 2019, Simple Machines | Terms and Policies
  • XHTML
  • RSS
  • WAP2