HPCW 3.0
Loading...
Searching...
No Matches
Findeccodes.cmake
Go to the documentation of this file.
1# Copyright (c) 2025 Niclas Schroeter
2# All rights reserved.
3#
4# SPDX-License-Identifier: Apache-2.0
5
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
10
11find_package(eccodes CONFIG)
12if(eccodes_FOUND)
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)
16
17 if(eccodes_f90_LIB-NOTFOUND)
18 set(eccodes_f90_FOUND 0)
19 else()
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)
23 endif()
24endif()
25
26if(NOT (eccodes_FOUND AND eccodes_f90_FOUND))
27 find_package(PkgConfig)
28 if(PKG_CONFIG_FOUND)
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)
34 endif()
35 endif()
36endif()
37
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)
42
43 find_library(eccodes_f90_LIB eccodes_f90 REQUIRED)
44 cmake_path(GET eccodes_f90_LIB PARENT_PATH eccodes_f90_LIBRARY_DIRS)
45
46 find_path(eccodes_INCLUDE_DIRS NAMES "eccodes.h" REQUIRED)
47
48 add_library(eccodes UNKNOWN IMPORTED)
49 add_library(eccodes_f90 UNKNOWN IMPORTED)
50 message(STATUS "Found eccodes")
51endif()