You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gentoo-overlay/sci-astronomy/kstars/files/kstars-3.5.5-FindERFA.cmake...

126 lines
4.0 KiB

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