diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cffe4c..af7d232 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/bmi_heat/CMakeLists.txt b/bmi_heat/CMakeLists.txt index 8f86d3b..178e226 100644 --- a/bmi_heat/CMakeLists.txt +++ b/bmi_heat/CMakeLists.txt @@ -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})