1# Copyright (c) 2025 Niclas Schroeter
4# SPDX-License-Identifier: Apache-2.0
6# This find module defines the following targets and variables:
7# - Adds eccodes and eccodes_f90 as targets
8# - Sets eccodes_INCLUDE_DIRS
9# - Sets eccodes{_f90}_LIBRARY_DIRS
11find_package(eccodes CONFIG)
13 get_target_property(eccodes_INCLUDE_DIRS eccodes INTERFACE_INCLUDE_DIRECTORIES)
14 get_target_property(eccodes_f90_LIB eccodes_f90 LOCATION)
15 get_target_property(eccodes_LIB eccodes LOCATION)
17 if(eccodes_f90_LIB-NOTFOUND)
18 set(eccodes_f90_FOUND 0)
20 set(eccodes_f90_FOUND 1)
21 cmake_path(GET eccodes_f90_LIB PARENT_PATH eccodes_f90_LIBRARY_DIRS)
22 cmake_path(GET eccodes_LIB PARENT_PATH eccodes_LIBRARY_DIRS)
26if(NOT (eccodes_FOUND AND eccodes_f90_FOUND))
27 find_package(PkgConfig)
29 pkg_check_modules(eccodes eccodes IMPORTED_TARGET GLOBAL)
30 pkg_check_modules(eccodes_f90 eccodes_f90 IMPORTED_TARGET GLOBAL)
31 if(eccodes_FOUND AND eccodes_f90_FOUND)
32 add_library(eccodes ALIAS PkgConfig::eccodes)
33 add_library(eccodes_f90 ALIAS PkgConfig::eccodes_f90)
38if(NOT (eccodes_FOUND AND eccodes_f90_FOUND))
39 message(STATUS "Manually looking for eccodes")
40 find_library(eccodes_LIB eccodes REQUIRED)
41 cmake_path(GET eccodes_LIB PARENT_PATH eccodes_LIBRARY_DIRS)
43 find_library(eccodes_f90_LIB eccodes_f90 REQUIRED)
44 cmake_path(GET eccodes_f90_LIB PARENT_PATH eccodes_f90_LIBRARY_DIRS)
46 find_path(eccodes_INCLUDE_DIRS NAMES "eccodes.h" REQUIRED)
48 add_library(eccodes UNKNOWN IMPORTED)
49 add_library(eccodes_f90 UNKNOWN IMPORTED)
50 message(STATUS "Found eccodes")