Skip to content

Commit

Permalink
Add [email protected] as submodule, and modify cppExamples to leverage f…
Browse files Browse the repository at this point in the history
…ind_package.

Also add some status messages in thermopack-config.cmake. The build on windows will probably need some testing/tuning.
  • Loading branch information
vegardjervell committed Aug 9, 2024
1 parent be35a65 commit 20940ce
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "external/pFUnit"]
path = external/pFUnit
url = https://github.com/thermotools/pFUnit.git
[submodule "external/lapack"]
path = external/lapack
url = https://github.com/Reference-LAPACK/lapack.git
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ endif()
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(tp_fortran_flags ${tp_debug_flags})
else()
set(CMAKE_BUILD_TYPE "Release")
message(STATUS "CMAKE_BUILD_TYPE not specified, defaulting to Release.")
set(tp_fortran_flags ${tp_optim_flags})
endif()

Expand Down
40 changes: 21 additions & 19 deletions addon/cppExamples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
# Example for Compiling and linking C++ executables using thermopack.
# This example assumes that libthermopack.dylib has already been built. The path to libthermopack.dylib
# is set in `libthermopack_path`, you will likely need to modify this.
#
# Note: If you want to build with static linkage, you also need to link libgfortran.a, libquadmath.a, and
# lapack, as shown in CMakelists_static.txt.
# This example assumes that libthermopack.dylib has already been built and installed with `make install`
# The environment variable THERMOPACK_DIR should point to the root directory of ThermoPack (where thermopack-config.cmake is found)
# this can be set with `export THERMOPACK_DIR=<path/to/thermopack>`.
#
# Note: On macOS (arm64), you might need to
# export CC=/opt/homebrew/bin/gcc-13
# export CXX=/opt/homebrew/bin/g++-13
# before running cmake, in order to force compilation for arm64.

project(cppExamples)
cmake_minimum_required(VERSION 3.2)

string(ASCII 27 Esc)
set(ColourRed "${Esc}[31m")
set(ColourBlue "${Esc}[34m")

set(libthermopack_path "${CMAKE_SOURCE_DIR}/../cppThermopack/libthermopack${CMAKE_SHARED_LIBRARY_SUFFIX}")
set(THERMOPACK_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../..")

set(THERMOPACK_HEADERS "${CMAKE_SOURCE_DIR}/../cppThermopack")
# Searches for thermopack-config.cmake in the directory ${THERMOPACK_DIR}, which can be set with `export THERMOPACK_DIR=<path/to/thermopack>`
# Once thermopack is found, it provides some convenience variables shown below, as well as the exported target `thermopack` which can be used for linking directly.
find_package(THERMOPACK REQUIRED)
if (NOT THERMOPACK_INSTALLED)
message("${ColourRed}Thermopack was found but is not installed. Exiting ...")
return()
endif()

message("${ColourBlue}Using libthermopack at : ${libthermopack_path}")
message("${ColourBlue}Using cppThermopack headers at : ${THERMOPACK_HEADERS}")
message("${ColourBlue}Thermopack was found at : ${THERMOPACK_ROOT}")
message("${ColourBlue}Using libthermopack at : ${THERMOPACK_LIB}")
message("${ColourBlue}Using cppThermopack headers at : ${THERMOPACK_INCLUDE}")
message("${ColourBlue}Linking thermopack using exported target thermopack")

set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wfatal-errors -std=c++17")
Expand All @@ -31,21 +38,16 @@ set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")


add_executable(basic basic.cpp)
target_include_directories(basic PUBLIC ${THERMOPACK_HEADERS})
target_link_libraries(basic PUBLIC ${libthermopack_path})
target_link_libraries(basic PUBLIC thermopack)

add_executable(tp_properties tp_properties.cpp)
target_include_directories(tp_properties PUBLIC ${THERMOPACK_HEADERS})
target_link_libraries(tp_properties PUBLIC ${libthermopack_path})
target_link_libraries(tp_properties PUBLIC thermopack)

add_executable(tv_properties tv_properties.cpp)
target_include_directories(tv_properties PUBLIC ${THERMOPACK_HEADERS})
target_link_libraries(tv_properties PUBLIC ${libthermopack_path})
target_link_libraries(tv_properties PUBLIC thermopack)

add_executable(flashes flashes.cpp)
target_include_directories(flashes PUBLIC ${THERMOPACK_HEADERS})
target_link_libraries(flashes PUBLIC ${libthermopack_path})
target_link_libraries(flashes PUBLIC thermopack)

add_executable(saturation saturation.cpp)
target_include_directories(saturation PUBLIC ${THERMOPACK_HEADERS})
target_link_libraries(saturation PUBLIC ${libthermopack_path})
target_link_libraries(saturation PUBLIC thermopack)
1 change: 1 addition & 0 deletions external/lapack
Submodule lapack added at 3c351a
6 changes: 2 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ else(MSVC)
add_library(thermopack SHARED $<TARGET_OBJECTS:libthermopack>)
endif(MSVC)

set_target_properties(libthermopack PROPERTIES
Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set_target_properties(libthermopack PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(libthermopack PUBLIC ${TREND_DIR})
set_target_properties(thermopack PROPERTIES
Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set_target_properties(thermopack PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(thermopack PUBLIC ${TREND_DIR})

install(TARGETS thermopack DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../addon/pycThermopack/thermopack)
Expand Down
8 changes: 8 additions & 0 deletions thermopack-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,30 @@
# thermopack : Imported shared library target with headers


message(STATUS "ThermoPack found at: ${CMAKE_CURRENT_LIST_DIR}")
set(THERMOPACK_LIB ${CMAKE_CURRENT_LIST_DIR}/addon/cppThermopack/libthermopack${CMAKE_SHARED_LIBRARY_SUFFIX})
set(THERMOPACK_ROOT ${CMAKE_CURRENT_LIST_DIR})

if(NOT EXISTS ${THERMOPACK_LIB})
unset(THERMOPACK_LIB)
set(THERMOPACK_INSTALLED FALSE)
message(STATUS "ThermoPack has not been properly installed.")
return()
endif()

set(THERMOPACK_FOUND TRUE)
set(THERMOPACK_INSTALLED TRUE)
set(THERMOPACK_INCLUDE ${CMAKE_CURRENT_LIST_DIR}/addon/cppThermopack)

message(STATUS "Setting ThermoPack cmake variables ...")
message(STATUS "THERMOPACK_ROOT: ${THERMOPACK_ROOT}")
message(STATUS "THERMOPACK_LIB: ${THERMOPACK_LIB}")
message(STATUS "THERMOPACK_INCLUDE: ${THERMOPACK_INCLUDE}")

if(NOT TARGET thermopack)
add_library(thermopack SHARED IMPORTED)
set_target_properties(thermopack PROPERTIES
IMPORTED_LOCATION ${THERMOPACK_LIB}
INTERFACE_INCLUDE_DIRECTORIES ${THERMOPACK_INCLUDE})
message(STATUS "ThermoPack exported target: thermopack")
endif()

0 comments on commit 20940ce

Please sign in to comment.