From c7e6f6ab0e6cb583965f1fe0ed8a67c71412436b Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Fri, 27 Nov 2020 17:02:57 +0100 Subject: [PATCH] (#3695) cspice: add utilities option + extract license from source code * add utilities * rename option * append bin to PATH if utilities enabled * extract license from main public header * explicit cpp_info.libs * don't modify source subfolder content during build --- recipes/cspice/all/CMakeLists.txt | 97 ++++++++++++++++++++++++++++--- recipes/cspice/all/TSPA.txt | 22 ------- recipes/cspice/all/conanfile.py | 29 +++++++-- 3 files changed, 113 insertions(+), 35 deletions(-) delete mode 100644 recipes/cspice/all/TSPA.txt diff --git a/recipes/cspice/all/CMakeLists.txt b/recipes/cspice/all/CMakeLists.txt index 6c5a8eba9e..4f280145ac 100644 --- a/recipes/cspice/all/CMakeLists.txt +++ b/recipes/cspice/all/CMakeLists.txt @@ -4,8 +4,12 @@ project(cspice C) include(conanbuildinfo.cmake) conan_basic_setup() -file(GLOB SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/source_subfolder/src/cspice/*.c) -add_library(cspice ${SRC_FILES}) +option(BUILD_UTILITIES "Build cspice utilities" ON) + +set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/source_subfolder/src) + +file(GLOB CSPICE_SRC_FILES ${SRC_DIR}/cspice/*.c) +add_library(cspice ${CSPICE_SRC_FILES}) if(WIN32) target_compile_definitions(cspice PRIVATE "_COMPLEX_DEFINED;MSDOS;OMIT_BLANK_CC;NON_ANSI_STDIO") @@ -15,20 +19,97 @@ elseif(UNIX) target_compile_options(cspice PRIVATE -ansi) endif() +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + target_link_libraries(cspice PRIVATE m) +endif() + # Behavior of implicitly defined functions changed in AppleClang 12 # https://developer.apple.com/documentation/xcode-release-notes/xcode-12-release-notes -if(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND +if(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "12") - target_compile_options(cspice PRIVATE -Wno-error=implicit-function-declaration) + target_compile_options(cspice PRIVATE -Wno-error=implicit-function-declaration) endif() install( TARGETS cspice - EXPORT cspice - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) file(GLOB INCLUDE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/source_subfolder/include/*.h) install(FILES ${INCLUDE_FILES} DESTINATION include) + +if(BUILD_UTILITIES) + # csupport is common to all utilities + file(GLOB CSUPPORT_SRC_FILES "${SRC_DIR}/csupport/*.c") + add_library(csupport OBJECT ${CSUPPORT_SRC_FILES}) + + # Walk into all utilities subfolders and build them (except cook_c which only contains examples) + file(GLOB CSPICE_UTILITIES_SUBDIRS RELATIVE ${SRC_DIR} "${SRC_DIR}/*_c") + list(REMOVE_ITEM CSPICE_UTILITIES_SUBDIRS "cook_c") + foreach(CSPICE_SUBDIR ${CSPICE_UTILITIES_SUBDIRS}) + set(UTILITY_SRC_DIR "${SRC_DIR}/${CSPICE_SUBDIR}") + + # Each .pgm file is the entry point of an executable + file(GLOB PGM_FILES "${UTILITY_SRC_DIR}/*.pgm") + + # Source files common to all executables in this subfolder + # Ignore these files: main.c, .c, _main.c + # (might have been pre-generated, specially in Windows source code) + file(GLOB CSPICE_UTILITY_SRC_FILES ${UTILITY_SRC_DIR}/*.c) + get_filename_component(MAIN_SRC_FILE "${UTILITY_SRC_DIR}/main.c" ABSOLUTE) + list(REMOVE_ITEM CSPICE_UTILITY_SRC_FILES "${MAIN_SRC_FILE}") + foreach(PGM_FILE ${PGM_FILES}) + get_filename_component(CSPICE_UTILITY ${PGM_FILE} NAME_WE) + get_filename_component(PGM_MAIN_SRC_FILE "${UTILITY_SRC_DIR}/${CSPICE_UTILITY}_main.c" ABSOLUTE) + get_filename_component(GENERIC_MAIN_SRC_FILE "${UTILITY_SRC_DIR}/${CSPICE_UTILITY}.c" ABSOLUTE) + list(REMOVE_ITEM CSPICE_UTILITY_SRC_FILES "${PGM_MAIN_SRC_FILE}" "${GENERIC_MAIN_SRC_FILE}") + endforeach() + if(CSPICE_UTILITY_SRC_FILES) + add_library(${CSPICE_SUBDIR}_commonlib OBJECT ${CSPICE_UTILITY_SRC_FILES}) + endif() + + # Build one executable per pgm file + foreach(PGM_FILE ${PGM_FILES}) + get_filename_component(CSPICE_UTILITY ${PGM_FILE} NAME_WE) + + # Generate _main.c file from .pgm file + set(PGM_MAIN_SRC_FILE "${CMAKE_CURRENT_BINARY_DIR}/cspice_generated/${CSPICE_SUBDIR}/${CSPICE_UTILITY}_main.c") + add_custom_target(${CSPICE_UTILITY}_PGM DEPENDS ${PGM_FILE} ${PGM_MAIN_SRC_FILE}) + add_custom_command( + OUTPUT ${PGM_MAIN_SRC_FILE} + DEPENDS ${PGM_FILE} + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PGM_FILE} ${PGM_MAIN_SRC_FILE} + ) + + # Generate .c from main.x file if it exists + set(INPUT_MAIN_FILE "${UTILITY_SRC_DIR}/main.x") + set(GENERIC_MAIN_SRC_FILE "") + if(EXISTS ${INPUT_MAIN_FILE}) + set(GENERIC_MAIN_SRC_FILE "${CMAKE_CURRENT_BINARY_DIR}/cspice_generated/${CSPICE_SUBDIR}/${CSPICE_UTILITY}.c") + add_custom_target(${CSPICE_UTILITY}_MAIN DEPENDS ${INPUT_MAIN_FILE} ${GENERIC_MAIN_SRC_FILE}) + add_custom_command( + OUTPUT ${GENERIC_MAIN_SRC_FILE} + DEPENDS ${INPUT_MAIN_FILE} + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${INPUT_MAIN_FILE} ${GENERIC_MAIN_SRC_FILE} + ) + endif() + + add_executable(${CSPICE_UTILITY} ${PGM_MAIN_SRC_FILE} ${GENERIC_MAIN_SRC_FILE}) + add_dependencies(${CSPICE_UTILITY} ${CSPICE_UTILITY}_PGM) + if(TARGET ${CSPICE_UTILITY}_MAIN) + add_dependencies(${CSPICE_UTILITY} ${CSPICE_UTILITY}_MAIN) + endif() + target_include_directories(${CSPICE_UTILITY} PRIVATE ${UTILITY_SRC_DIR}) + target_link_libraries(${CSPICE_UTILITY} PRIVATE csupport cspice) + if(TARGET ${CSPICE_SUBDIR}_commonlib) + target_link_libraries(${CSPICE_UTILITY} PRIVATE ${CSPICE_SUBDIR}_commonlib) + endif() + if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + target_link_libraries(${CSPICE_UTILITY} PRIVATE m) + endif() + install(TARGETS ${CSPICE_UTILITY} DESTINATION ${CMAKE_INSTALL_BINDIR}) + endforeach() + endforeach() +endif() diff --git a/recipes/cspice/all/TSPA.txt b/recipes/cspice/all/TSPA.txt deleted file mode 100644 index 36c1e85607..0000000000 --- a/recipes/cspice/all/TSPA.txt +++ /dev/null @@ -1,22 +0,0 @@ -THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE -CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. -GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE -ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE -PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" TO -THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY -WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A -PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES -UCC§2312-§2313) OR FOR ANY PURPOSE WHATSOEVER, -FOR THE SOFTWARE AND RELATED MATERIALS, HOWEVER USED. - -IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA BE -LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT LIMITED TO, -INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING -ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, -REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE -REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. - -RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE -SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY -CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE -ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE diff --git a/recipes/cspice/all/conanfile.py b/recipes/cspice/all/conanfile.py index b8c2da3619..29b8dbb114 100644 --- a/recipes/cspice/all/conanfile.py +++ b/recipes/cspice/all/conanfile.py @@ -11,11 +11,18 @@ class CspiceConan(ConanFile): homepage = "https://naif.jpl.nasa.gov/naif/toolkit.html" url = "https://github.com/conan-io/conan-center-index" exports_sources = ["CMakeLists.txt", "patches/**"] - exports = ["TSPA.txt"] generators = "cmake" settings = "os", "arch", "compiler", "build_type" - options = {"shared": [True, False], "fPIC": [True, False]} - default_options = {"shared": False, "fPIC": True} + options = { + "shared": [True, False], + "fPIC": [True, False], + "utilities": [True, False] + } + default_options = { + "shared": False, + "fPIC": True, + "utilities": True + } _cmake = None @@ -83,15 +90,27 @@ class CspiceConan(ConanFile): if self._cmake: return self._cmake self._cmake = CMake(self) + self._cmake.definitions["BUILD_UTILITIES"] = self.options.utilities self._cmake.configure() return self._cmake def package(self): - self.copy("TSPA.txt", dst="licenses") + tools.save(os.path.join(self.package_folder, "licenses", "LICENSE"), self._extract_license()) cmake = self._configure_cmake() cmake.install() + def _extract_license(self): + spiceusr_header = tools.load(os.path.join(self._source_subfolder, "include", "SpiceUsr.h")) + begin = spiceusr_header.find("-Disclaimer") + end = spiceusr_header.find("-Required_Reading", begin) + return spiceusr_header[begin:end] + def package_info(self): - self.cpp_info.libs = tools.collect_libs(self) + self.cpp_info.libs = ["cspice"] if self.settings.os == "Linux": self.cpp_info.system_libs.append("m") + + if self.options.utilities: + bin_path = os.path.join(self.package_folder, "bin") + self.output.info("Appending PATH environment variable: {}".format(bin_path)) + self.env_info.PATH.append(bin_path)