From f039f55963f17029369a0c06cb5329b5ef5962c2 Mon Sep 17 00:00:00 2001 From: Hleb Valoshka <375gnu@gmail.com> Date: Sat, 19 Jan 2019 15:49:06 +0300 Subject: [PATCH] [cmake] add cspice support --- CMakeLists.txt | 5 +++ cmake/FindCspice.cmake | 70 +++++++++++++++++++++++++++++++++++++ src/celephem/CMakeLists.txt | 3 ++ 3 files changed, 78 insertions(+) create mode 100644 cmake/FindCspice.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d1471280..721c6bae5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,11 @@ if(ENABLE_NLS) link_libraries(${Intl_LIBRARIES}) endif() +if(ENABLE_SPICE) + include(FindCspice) + find_package(Cspice REQUIRED) +endif() + if(_UNIX) find_package(PkgConfig) endif() diff --git a/cmake/FindCspice.cmake b/cmake/FindCspice.cmake new file mode 100644 index 000000000..ccaed0d45 --- /dev/null +++ b/cmake/FindCspice.cmake @@ -0,0 +1,70 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#.rst: +# FindCspice +# -------- +# +# Find the NAIF toolkit cspice headers and libraries. +# +# This module reports information about the Gettext cspice +# installation in several variables. General variables:: +# +# CSPICE_FOUND - true if the cspice headers and libraries were found +# CSPICE_INCLUDE_DIRS - the directory containing the cspice headers +# CSPICE_LIBRARIES - cspice libraries to be linked +# +# The following cache variables may also be set:: +# +# CSPICE_INCLUDE_DIR - the directory containing the cspice headers +# CSPICE_LIBRARY - the cspice library (if any) + +# Find include directory +find_path(CSPICE_INCLUDE_DIR + NAMES "SpiceOsc.h" + DOC "cspice include directory") +mark_as_advanced(CSPICE_INCLUDE_DIR) + +# Find CSPICE library +find_library(CSPICE_LIBRARY + NAMES "cspice" "libcspice" "cspice.a" + DOC "cspice libraries") +mark_as_advanced(CSPICE_LIBRARY) + +# Find CSPICE's csupport libraries +find_library(CSPICE_CSUPPORT_LIBRARY + NAMES "csupport" "libcsupport" "csupport.a" + DOC "cspice's csupport libraries") +mark_as_advanced(CSPICE_CSUPPORT_LIBRARY) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(CSPICE + FOUND_VAR CSPICE_FOUND + REQUIRED_VARS CSPICE_INCLUDE_DIR CSPICE_LIBRARY + FAIL_MESSAGE "Failed to find cspice") + +if(CSPICE_FOUND) + set(CSPICE_INCLUDE_DIRS "${CSPICE_INCLUDE_DIR}") + if(CSPICE_LIBRARY) + set(CSPICE_LIBRARIES "${CSPICE_LIBRARY}") + else() + unset(CSPICE_LIBRARIES) + endif() + + if(NOT TARGET CSPICE::CSPICE) + add_library(CSPICE::CSPICE UNKNOWN IMPORTED) + set_target_properties(CSPICE::CSPICE PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CSPICE_INCLUDE_DIRS}") + set_target_properties(CSPICE::CSPICE PROPERTIES + IMPORTED_LOCATION "${CSPICE_LIBRARY}") + endif() + + if(NOT TARGET CSPICE::CSUPPORT) + add_library(CSPICE::CSUPPORT UNKNOWN IMPORTED) + if(CSPICE_CSUPPORT_LIBRARY) + set_target_properties(CSPICE::CSUPPORT PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CSPICE_INCLUDE_DIRS}") + set_target_properties(CSPICE::CSUPPORT PROPERTIES + IMPORTED_LOCATION "${CSPICE_CSUPPORT_LIBRARY}") + endif() + endif() +endif() diff --git a/src/celephem/CMakeLists.txt b/src/celephem/CMakeLists.txt index a9e7d59f1..85776629c 100644 --- a/src/celephem/CMakeLists.txt +++ b/src/celephem/CMakeLists.txt @@ -45,6 +45,9 @@ if(ENABLE_CELX) endif() add_library(celephem STATIC ${CELEPHEM_SOURCES}) +if(ENABLE_SPICE) + target_link_libraries(celephem CSPICE::CSPICE CSPICE::CSUPPORT) +endif() cotire(celephem) #[[ add_library(celephem SHARED ${CELEPHEM_SOURCES})