Skip to content

Commit

Permalink
Use pkg-config to find installed bmi-fortran spec
Browse files Browse the repository at this point in the history
  • Loading branch information
mdpiper committed Mar 11, 2024
1 parent 6909f22 commit e45f5cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
24 changes: 7 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,16 @@ include(GNUInstallDirs)
set(model_name heatf)
set(bmi_name bmi${model_name})

# Determine the Fortran BMI version.
if(DEFINED ENV{BMIF_VERSION})
set(bmif_version $ENV{BMIF_VERSION})
else()
set(bmif_version "2.0")
endif()
string(REPLACE "." "_" bmif_module_version ${bmif_version})
message("-- BMIF version - ${bmif_version}")
message("-- BMIF module version - ${bmif_module_version}")
find_package(PkgConfig REQUIRED)
pkg_check_modules(BMIF REQUIRED IMPORTED_TARGET bmif)
string(REPLACE "." "_" bmif_module_version ${BMIF_VERSION})
message("-- bmif module version - ${bmif_module_version}")
message("-- bmif library path - ${BMIF_LINK_LIBRARIES}")
message("-- bmif include dir - ${BMIF_INCLUDE_DIRS}")
include_directories(${BMIF_INCLUDE_DIRS})

set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/mod)

# Locate the installed Fortran BMI bindings (bmif library and module file)
# through CMAKE_PREFIX_PATH.
find_library(bmif_lib bmif)
find_path(bmif_inc bmif_${bmif_module_version}.mod)
include_directories(${bmif_inc})
message("-- bmif_lib - ${bmif_lib}")
message("-- bmif_inc - ${bmif_inc}")

add_subdirectory(heat)
add_subdirectory(bmi_heat)
add_subdirectory(test)
Expand Down
2 changes: 1 addition & 1 deletion bmi_heat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if(WIN32)
else()
add_library(${bmi_name} SHARED bmi_heat.f90)
endif()
target_link_libraries(${bmi_name} ${model_name} ${bmif_lib})
target_link_libraries(${bmi_name} ${model_name} ${BMIF_LINK_LIBRARIES})

add_executable(run_${bmi_name} bmi_main.f90)
target_link_libraries(run_${bmi_name} ${bmi_name})
Expand Down

0 comments on commit e45f5cc

Please sign in to comment.