Skip to content

Commit

Permalink
v0.4.3 (#62)
Browse files Browse the repository at this point in the history
* GEMS-221: Fixed  build spdlog in header-only mode or as lib for thermofun project

* GEMS-221: Set spdlog in header-only mode for thermofun project, checked build&install

* Restore fixed

* Fixed local install python code

* GEMS-217: Fixed memory leaks which were definitely lost t in ThermoFun project.

* Fixed python install for win64

* Fixed version in install dependent

* Fixed

* v0.4.3

* removed setuptools and version of chemicalfun

---------

Co-authored-by: svetad <sv.dmytr@gmail.com>
Co-authored-by: G. Dan Miron <dan.miron@psi.com>
Co-authored-by: Allan Leal <allanmulin@gmail.com>
  • Loading branch information
4 people committed Mar 2, 2023
1 parent 0fc47c0 commit c47e45c
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 85 deletions.
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Require a certain version of cmake
cmake_minimum_required(VERSION 3.9)

# Set the name of the project
project(ThermoFun VERSION 0.4.3 LANGUAGES CXX)

# Set the cmake module path of the project
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")

# Use ccache to speed up repeated compilations
include(CCache)

# Set the name of the project
project(ThermoFun VERSION 0.4.2 LANGUAGES CXX)

# Define variables with the GNU standard installation directories
include(GNUInstallDirs)

Expand Down Expand Up @@ -43,6 +43,13 @@ else()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

# Used into conda only
if(DEFINED ENV{CONDA_PREFIX})
option(USE_SPDLOG_PRECOMPILED "Use spdlog in compiled version" ON)
else()
option(USE_SPDLOG_PRECOMPILED "Use spdlog in compiled version" OFF)
endif()

# Set the default build type to Release
if(NOT CMAKE_BUILD_TYPE)
# The build type selection for the project
Expand Down
3 changes: 1 addition & 2 deletions ThermoFun/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Recursively collect all header files from the current directory
file(GLOB_RECURSE HEADER_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.hpp *.h)

Expand All @@ -24,8 +25,6 @@ add_library(ThermoFun::ThermoFun ALIAS ThermoFun)
# Link ThermoFun against all required dependencies
target_link_libraries(ThermoFun
PUBLIC ChemicalFun::ChemicalFun
# PUBLIC spdlog::spdlog
PRIVATE nlohmann_json::nlohmann_json
)

# Specify the include directories of the library target
Expand Down
4 changes: 4 additions & 0 deletions ThermoFun/Common/Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ void update_loggers( bool use_cout, const std::string& logfile_name, size_t log_
{
auto thermofun_logger = spdlog::get("thermofun");
auto chemicalfun_logger = spdlog::get("chemicalfun");
if(!thermofun_logger || !chemicalfun_logger)
return;

// change level
spdlog::level::level_enum log_lev = spdlog::level::info;
Expand Down Expand Up @@ -49,6 +51,8 @@ void clear_loggers( const std::string& logfile_name)
{
auto thermofun_logger = spdlog::get("thermofun");
auto chemicalfun_logger = spdlog::get("chemicalfun");
if(!thermofun_logger || !chemicalfun_logger)
return;

thermofun_logger->sinks().clear();
chemicalfun_logger->sinks().clear();
Expand Down
11 changes: 10 additions & 1 deletion ThermoFun/ThermoEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,18 @@ struct ThermoEngine::Impl

Impl()
{
set_fn() ;
}

Impl(const Database &database)
: database(database)
{
set_fn();
}

void set_fn()
{

thermo_properties_substance_fn = [=](double T, double P_, double &P, std::string symbol) {
auto x = P_;
return thermoPropertiesSubstance(T, P, symbol);
Expand Down Expand Up @@ -748,8 +755,10 @@ struct ThermoEngine::Impl
};

ThermoEngine::ThermoEngine(const std::string filename)
: pimpl(new Impl(*(new const Database(filename))))
: pimpl()
{
Database db(filename);
pimpl.reset(new Impl(db));
}

ThermoEngine::ThermoEngine(const Database &database)
Expand Down
22 changes: 11 additions & 11 deletions cmake/modules/ThermoFunFindDeps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ if(TFUN_BUILD_PYTHON)
endif()
endif()

find_package(nlohmann_json REQUIRED)
if(NOT nlohmann_json_FOUND)
message(FATAL_ERROR "nlohmann_json library not found")
endif()
#find_package(nlohmann_json REQUIRED)
#if(NOT nlohmann_json_FOUND)
# message(FATAL_ERROR "nlohmann_json library not found")
#endif()

find_package(ChemicalFun REQUIRED)
if(NOT ChemicalFun_FOUND)
message(FATAL_ERROR "ChemicalFun library not found")
endif()

find_package(spdlog REQUIRED)
if(NOT spdlog_FOUND)
message(FATAL_ERROR "spdlog not found")
if(USE_SPDLOG_PRECOMPILED)
if(NOT TARGET spdlog::spdlog)
find_package(spdlog CONFIG REQUIRED)
if(NOT spdlog_FOUND)
message(FATAL_ERROR "spdlog not found")
endif()
endif()
endif()

find_package(fmt REQUIRED)
if(NOT fmt_FOUND)
message(FATAL_ERROR "fmt not found")
endif()
5 changes: 1 addition & 4 deletions environment.devenv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ channels:
- conda-forge

dependencies:
- setuptools=59.7.0
- pip
- gxx_linux-64 # [linux]
- cmake
Expand All @@ -16,9 +15,7 @@ dependencies:
- clangxx_osx-64 # [osx]
- pybind11
- nlohmann_json
# - spdlog=1.11.0
# - fmt=9.1.0
- chemicalfun=0.1.6
- chemicalfun
- python={{ python_version }}
- pytest
- vs2019_win-64 # [win]
Expand Down
96 changes: 35 additions & 61 deletions install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
#!/bin/bash
# Installing dependencies needed to build ThermoFun on (k)ubuntu linux 16.04 or 18.04
# Installing dependencies needed to build ThermoFun on (k)ubuntu linux 20.04

EXTN=so

#sudo rm -f /usr/local/include/nlohmann/json.hpp
#sudo rm -rf /usr/local/include/eigen3/Eigen
#sudo rm -rf /usr/local/include/nlohmann
#sudo rm -rf /usr/local/include/eigen3/Eigen/Eigen
#sudo rm -rf /usr/local/include/pybind11
#sudo rm -rf /usr/local/include/spdlog
#sudo rm -rf /usr/local/include/fmt
#sudo rm -f /usr/local/lib/libChemicalFun.$EXTN

workfolder=${PWD}
BRANCH_TFUN=master
BUILD_TYPE=Release

# nlohmann/json
# nlohmann/json library v. 3.6.1 or up
# if not installed in /usr/local/include/nlohmann)
test -f /usr/local/include/nlohmann/json.hpp || {

# Building json library
# Getting nlohmann/json library
mkdir -p ~/code && \
cd ~/code && \
cd ~/code && \
git clone https://github.com/nlohmann/json.git && \
cd json && \
mkdir -p build && \
cd build && \
cmake .. -DJSON_BuildTests=OFF && \
make && \
cmake .. -DCMAKE_BUILD_TYPE=Release -DJSON_BuildTests=OFF -DJSON_MultipleHeaders=ON && \
sudo make install

# Removing generated build files
cd ~ && \
rm -rf ~/code
}

# spdlog
# if no spdlog installed in /usr/local/lib/ (/usr/local/include/spdlog)
test -d /usr/local/include/spdlog || {
# Eigen3 math library (added for building and installing xGEMS)
# if not installed in /usr/local/include/eigen3)
test -d /usr/local/include/eigen3/Eigen || {

# Building thermofun library
# Building eigen library
mkdir -p ~/code && \
cd ~/code && \
git clone https://github.com/gabime/spdlog -b v1.11.0 && \
cd spdlog && \
git clone https://gitlab.com/libeigen/eigen.git -b 3.4.0 && \
cd eigen && \
mkdir -p build && \
cd build && \
cmake .. -DCMAKE_BUILD_TYPE=Release -DSPDLOG_BUILD_TESTS=OFF -DCMAKE_INSTALL_LIBDIR=lib -DSPDLOG_BUILD_SHARED=ON -DSPDLOG_FMT_EXTERNAL=ON \
cmake .. \
make && \
sudo make install

Expand All @@ -53,20 +52,16 @@ test -d /usr/local/include/spdlog || {
rm -rf ~/code
}

# fmt
# if no spdlog installed in /usr/local/lib/ (/usr/local/include/fmt)
test -d /usr/local/include/fmt || {
# spdlog
# if no spdlog installed in /usr/local/include/spdlog (copy only headers)
test -d /usr/local/include/spdlog || {

# Building thermofun library
# Building spdlog library
mkdir -p ~/code && \
cd ~/code && \
git clone hhttps://github.com/fmtlib/fmt.git -b v9.1.0 && \
cd fmt && \
mkdir -p build && \
cd build && \
cmake .. \
make && \
sudo make install
git clone https://github.com/gabime/spdlog -b v1.11.0 && \
cd spdlog/include && \
sudo cp -r spdlog /usr/local/include

# Removing generated build files
cd ~ && \
Expand All @@ -77,40 +72,19 @@ test -d /usr/local/include/fmt || {
test -d /usr/local/include/pybind11 || {

# Building pybind11 library
mkdir -p ~/code && \
cd ~/code && \
git clone https://github.com/pybind/pybind11.git && \
cd pybind11 && \
mkdir -p build && \
cd build && \
cmake .. -DPYBIND11_TEST=OFF && \
make && \
sudo make install

# Removing generated build files
cd ~ && \
rm -rf ~/code
}

# Eigen
# Eigen3 math library (added for building and installing xGEMS)
# if not installed in /usr/local/include/eigen3)
test -d /usr/local/include/eigen3/Eigen || {

# Building eigen library
mkdir -p ~/code && \
cd ~/code && \
git clone https://gitlab.com/libeigen/eigen.git -b 3.4.0 && \
cd eigen && \
mkdir -p build && \
cd build && \
cmake .. \
make && \
sudo make install
mkdir -p ~/code && \
cd ~/code && \
git clone https://github.com/pybind/pybind11.git && \
cd pybind11 && \
mkdir -p build && \
cd build && \
cmake .. -DPYBIND11_TEST=OFF && \
make && \
sudo make install

# Removing generated build files
cd ~ && \
rm -rf ~/code
# Removing generated build files
cd ~ && \
rm -rf ~/code
}


Expand All @@ -126,7 +100,7 @@ test -f /usr/local/lib/libChemicalFun.$EXTN || {
cd chemicalfun && \
mkdir -p build && \
cd build && \
cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DTFUN_BUILD_PYTHON=OFF && \
cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DCMAKE_BUILD_TYPE=$BUILD_TYPE && \
make -j $threads && \
sudo make install

Expand Down
2 changes: 1 addition & 1 deletion python/pyThermoFun/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ include_directories(${PROJECT_SOURCE_DIR}/python)
pybind11_add_module(PyThermoFun ${SOURCE_FILES} NO_EXTRAS) # NO_EXTRAS used to decrease linking time, but causes larger module file size

# Link PyThermoFun against ThermoFun library
target_link_libraries(PyThermoFun LINK_PRIVATE ThermoFun::ThermoFun)
target_link_libraries(PyThermoFun PUBLIC ThermoFun::ThermoFun)
15 changes: 13 additions & 2 deletions python/thermofun/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,22 @@ set(SETUP_PY ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
# Configure the setup.py script with the provided CMake variables
configure_file(${SETUP_PY_IN} ${SETUP_PY})

# https://www.scivision.dev/cmake-install-python-package/
# https://pip.pypa.io/en/stable/topics/local-project-installs/#editable-installs
# detect virtualenv and set Pip args accordingly
if(DEFINED ENV{VIRTUAL_ENV} OR DEFINED ENV{CONDA_PREFIX})
set(_PIP_ARG)
else()
set(_PIP_ARG "--user")
endif()
#message(STATUS "_PIP_ARG: ${_PIP_ARG}")

# Create a custom target to build thermofun python package during build stage
add_custom_target(thermofun ALL
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:PyThermoFun>
${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:PyThermoFun>
COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} --quiet install --prefix=${CMAKE_BINARY_DIR}
#COMMAND ${PYTHON_EXECUTABLE} -m pip install ${_PIP_ARG} -e ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${PYTHON_EXECUTABLE} -m pip install --prefix ${CMAKE_BINARY_DIR} --ignore-installed .
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

# Set dependencies of thermofun target
Expand Down Expand Up @@ -43,7 +54,7 @@ install(CODE
endif()
execute_process(
COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} install --prefix=\${THERMOFUN_PYTHON_INSTALL_PREFIX_NATIVE}
COMMAND ${PYTHON_EXECUTABLE} -m pip install --prefix \${THERMOFUN_PYTHON_INSTALL_PREFIX_NATIVE} ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
"
)

0 comments on commit c47e45c

Please sign in to comment.