From 85936d68613d533b02fb9503a464d5098281285e Mon Sep 17 00:00:00 2001 From: Kyle Gerheiser <3209794+kgerheiser@users.noreply.github.com> Date: Tue, 7 Sep 2021 17:12:23 -0400 Subject: [PATCH 1/4] Create Findwgrib2.cmake --- Modules/Findwgrib2.cmake | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Modules/Findwgrib2.cmake diff --git a/Modules/Findwgrib2.cmake b/Modules/Findwgrib2.cmake new file mode 100644 index 0000000..7ceabba --- /dev/null +++ b/Modules/Findwgrib2.cmake @@ -0,0 +1,23 @@ +# This module produces the target wgrib2::wgrib2 + +find_path(WGRIB2_INCLUDES wgrib2api.mod) + +find_library(WGRIB2_LIBRARIES libwgrib2.a) + +find_program(WGRIB2_EXE wgrib2) +execute_process(COMMAND ${WGRIB2_EXE} --version OUTPUT_VARIABLE version_str) +string(SUBSTRING ${version_str} 3 5 version) + +mark_as_advanced(WGRIB2_INCLUDES WGRIB2_LIBRARIES) + +add_library(wgrib2::wgrib2 UNKNOWN IMPORTED) + +set_target_properties(wgrib2::wgrib2 PROPERTIES + IMPORTED_LOCATION "${WGRIB2_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${WGRIB2_INCLUDES}" + INTERFACE_LINK_LIBRARIES "${WGRIB2_LIBRARIES}") + +find_package_handle_standard_args(wgrib2 + REQUIRED_VARS WGRIB2_LIBRARIES WGRIB2_INCLUDES WGRIB2_EXE + VERSION_VAR version +) From 69a6bc62930016c511f06dbbdc8bc546d64cf36b Mon Sep 17 00:00:00 2001 From: Kyle Gerheiser <3209794+kgerheiser@users.noreply.github.com> Date: Wed, 8 Sep 2021 15:39:53 -0400 Subject: [PATCH 2/4] Add quotes --- Modules/Findwgrib2.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Findwgrib2.cmake b/Modules/Findwgrib2.cmake index 7ceabba..e689bdc 100644 --- a/Modules/Findwgrib2.cmake +++ b/Modules/Findwgrib2.cmake @@ -6,7 +6,7 @@ find_library(WGRIB2_LIBRARIES libwgrib2.a) find_program(WGRIB2_EXE wgrib2) execute_process(COMMAND ${WGRIB2_EXE} --version OUTPUT_VARIABLE version_str) -string(SUBSTRING ${version_str} 3 5 version) +string(SUBSTRING "${version_str}" 3 5 version) mark_as_advanced(WGRIB2_INCLUDES WGRIB2_LIBRARIES) From a7c9c0e99f0080f4cec8151c3da72e31ab502abc Mon Sep 17 00:00:00 2001 From: Kyle Gerheiser <3209794+kgerheiser@users.noreply.github.com> Date: Wed, 8 Sep 2021 16:39:43 -0400 Subject: [PATCH 3/4] Update Findwgrib2.cmake --- Modules/Findwgrib2.cmake | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/Modules/Findwgrib2.cmake b/Modules/Findwgrib2.cmake index e689bdc..44b9106 100644 --- a/Modules/Findwgrib2.cmake +++ b/Modules/Findwgrib2.cmake @@ -1,23 +1,36 @@ # This module produces the target wgrib2::wgrib2 find_path(WGRIB2_INCLUDES wgrib2api.mod) - -find_library(WGRIB2_LIBRARIES libwgrib2.a) - -find_program(WGRIB2_EXE wgrib2) -execute_process(COMMAND ${WGRIB2_EXE} --version OUTPUT_VARIABLE version_str) -string(SUBSTRING "${version_str}" 3 5 version) - -mark_as_advanced(WGRIB2_INCLUDES WGRIB2_LIBRARIES) +find_library(WGRIB2_LIB libwgrib2.a) +find_library(WGRIB2_API_LIB libwgrib2_api.a) add_library(wgrib2::wgrib2 UNKNOWN IMPORTED) +# Library builds are different between CMake build and the make build. +# libwgrib2_api.a is only necessary in the CMake build and must come first when linking +if(WGRIB2_API_LIB) + # CMake build. Need both. + set(first_lib ${WGRIB2_API_LIB}) + set(second_lib ${WGRIB2_LIB}) +else() + # Makefile build. Only need libwgrib2.a + set(FIRST_LIB ${WGRIB2_LIB}) + set(second_lib "") +endif() + set_target_properties(wgrib2::wgrib2 PROPERTIES - IMPORTED_LOCATION "${WGRIB2_LIBRARIES}" + IMPORTED_LOCATION "${first_lib}" INTERFACE_INCLUDE_DIRECTORIES "${WGRIB2_INCLUDES}" - INTERFACE_LINK_LIBRARIES "${WGRIB2_LIBRARIES}") + INTERFACE_LINK_LIBRARIES "${second_lib}") + +set(WGRIB2_LIBRARIES "${first_lib}" "${second_lib}") + +find_program(WGRIB2_EXE wgrib2) +execute_process(COMMAND ${WGRIB2_EXE} --version OUTPUT_VARIABLE version_str) +string(SUBSTRING "${version_str}" 3 5 version) find_package_handle_standard_args(wgrib2 REQUIRED_VARS WGRIB2_LIBRARIES WGRIB2_INCLUDES WGRIB2_EXE VERSION_VAR version -) + ) + From fc43e85b78ec187048dec417cc351a2d7f678f3c Mon Sep 17 00:00:00 2001 From: Kyle Gerheiser <3209794+kgerheiser@users.noreply.github.com> Date: Mon, 13 Sep 2021 15:05:12 -0400 Subject: [PATCH 4/4] Update Findwgrib2.cmake --- Modules/Findwgrib2.cmake | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Modules/Findwgrib2.cmake b/Modules/Findwgrib2.cmake index 44b9106..48ba573 100644 --- a/Modules/Findwgrib2.cmake +++ b/Modules/Findwgrib2.cmake @@ -27,7 +27,13 @@ set(WGRIB2_LIBRARIES "${first_lib}" "${second_lib}") find_program(WGRIB2_EXE wgrib2) execute_process(COMMAND ${WGRIB2_EXE} --version OUTPUT_VARIABLE version_str) -string(SUBSTRING "${version_str}" 3 5 version) + +# Wgrib2 changed how it output --version from "v0.x.y.z" to "vx.y.z" starting in wgrib2 3.0 +if(version_str MATCHES "^v0.*") + string(SUBSTRING "${version_str}" 3 5 version) +else() + string(SUBSTRING "${version_str}" 1 5 version) +endif() find_package_handle_standard_args(wgrib2 REQUIRED_VARS WGRIB2_LIBRARIES WGRIB2_INCLUDES WGRIB2_EXE