summaryrefslogtreecommitdiff
blob: 920cdf9c72b5c62d5e48092b30ed0ddf784e101d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
From b920b785f8193414fd66fe2a6d69c2e2ebf22023 Mon Sep 17 00:00:00 2001
From: Heiko Becker <heiko.becker@kde.org>
Date: Tue, 21 Sep 2021 16:56:02 +0200
Subject: [PATCH] Add FindERFA cmake module

ERFA doesn't seem to come with a cmake find module or a config file,
so I wrote one, which also provides an imported target.
---
 CMakeLists.txt                  |  5 +--
 Tests/skyobjects/CMakeLists.txt |  5 ++-
 cmake/modules/FindERFA.cmake    | 72 +++++++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 5 deletions(-)
 create mode 100644 cmake/modules/FindERFA.cmake

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b7b02258a..052987438 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -229,10 +229,7 @@ if(BUILD_TESTING)
     # Find liberfa, which we check our computation against
     find_package(ERFA)
     MACRO_BOOL_TO_01(ERFA_FOUND HAVE_LIBERFA)
-    set_package_properties(ERFA PROPERTIES DESCRIPTION "Essential Routines for Fundamental Astronomy" URL "https://github.com/liberfa/erfa" TYPE OPTIONAL PURPOSE "BSD-compatible version of SOFA, used to test core computations of KStars (only needed by tests)")
-    if (ERFA_FOUND)
-    include_directories(${ERFA_INCLUDE_DIR})
-    endif()
+    set_package_properties(ERFA PROPERTIES TYPE OPTIONAL PURPOSE "BSD-compatible version of SOFA, used to test core computations of KStars (only needed by tests)")
 endif ()
 
 ## Libraw
diff --git a/Tests/skyobjects/CMakeLists.txt b/Tests/skyobjects/CMakeLists.txt
index 7dc9b918c..ca2d06209 100644
--- a/Tests/skyobjects/CMakeLists.txt
+++ b/Tests/skyobjects/CMakeLists.txt
@@ -5,5 +5,8 @@ ADD_TEST( NAME TestSkyPoint COMMAND test_skypoint )
 endif()
 
 ADD_EXECUTABLE( test_starobject test_starobject.cpp )
-TARGET_LINK_LIBRARIES( test_starobject ${TEST_LIBRARIES} ${ERFA_LIBRARIES})
+TARGET_LINK_LIBRARIES( test_starobject ${TEST_LIBRARIES} )
+if (TARGET ERFA::ERFA)
+    TARGET_LINK_LIBRARIES( test_starobject ERFA::ERFA )
+endif()
 ADD_TEST( NAME TestStarobject COMMAND test_starobject )
diff --git a/cmake/modules/FindERFA.cmake b/cmake/modules/FindERFA.cmake
new file mode 100644
index 000000000..ea6f3e7d8
--- /dev/null
+++ b/cmake/modules/FindERFA.cmake
@@ -0,0 +1,72 @@
+# SPDX-FileCopyrightText: 2021 Heiko Becker <heiko.becker@kde.org>
+#
+# SPDX-License-Identifier: BSD-3-Clause
+
+#[=======================================================================[.rst:
+FindERFA
+----------
+
+Try to find the ERFA (Essential Routines for Fundamental Astronomy) library.
+
+This will define the following variables:
+
+``ERFA_FOUND``
+      True if the system has the ERFA library of at least the minimum
+      version specified by the version parameter to find_package()
+``ERFA_INCLUDE_DIRS``
+      The ERFA include dirs for use with target_include_directories
+``ERFA_LIBRARIES``
+      The ERFA libraries for use with target_link_libraries()
+``ERFA_VERSION``
+      The version of ERFA that was found
+
+If ``ERFA_FOUND` is TRUE, it will also define the following imported
+target:
+
+``ERFA::ERFA``
+      The ERFA library
+
+#]=======================================================================]
+
+find_package(PkgConfig QUIET)
+
+pkg_check_modules(PC_ERFA QUIET erfa)
+
+find_path(ERFA_INCLUDE_DIRS
+    NAMES erfa.h
+    HINTS ${PC_ERFA_INCLUDEDIR}
+)
+
+find_library(ERFA_LIBRARIES
+    NAMES erfa
+    HINTS ${PC_ERFA_LIBDIR}
+)
+
+set(ERFA_VERSION ${PC_ERFA_VERSION})
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(ERFA
+    FOUND_VAR
+        ERFA_FOUND
+    REQUIRED_VARS
+        ERFA_LIBRARIES
+        ERFA_INCLUDE_DIRS
+    VERSION_VAR
+        ERFA_VERSION
+)
+
+if (ERFA_FOUND AND NOT TARGET ERFA::ERFA)
+    add_library(ERFA::ERFA UNKNOWN IMPORTED)
+    set_target_properties(ERFA::ERFA PROPERTIES
+        IMPORTED_LOCATION "${ERFA_LIBRARIES}"
+        INTERFACE_INCLUDE_DIRECTORIES "${ERFA_INCLUDE_DIRS}"
+    )
+endif()
+
+mark_as_advanced(ERFA_LIBRARIES ERFA_INCLUDE_DIRS)
+
+include(FeatureSummary)
+set_package_properties(ERFA PROPERTIES
+    URL "https://github.com/liberfa/erfa/"
+    DESCRIPTION "Essential Routines for Fundamental Astronomy"
+)
-- 
GitLab