"Fossies" - the Fresh Open Source Software Archive

Member "udunits-2.2.28/CMakeLists.txt" (8 Dec 2020, 10268 Bytes) of package /linux/privat/udunits-2.2.28.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "CMakeLists.txt": 2.2.26_vs_2.2.28.

    1 CMAKE_MINIMUM_REQUIRED(VERSION 3.19)
    2 
    3 PROJECT(udunits VERSION 2.2.28
    4         DESCRIPTION "C library and utility for units of physical quantities")
    5 set(CMAKE_PROJECT_HOMEPAGE_URL https://www.unidata.ucar.edu/software/udunits)
    6 
    7 # Specify the C standard
    8 set(CMAKE_C_STANDARD 99)
    9 set(CMAKE_C_STANDARD_REQUIRED True)
   10 
   11 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
   12   set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/.." CACHE PATH
   13         "Installation root directory" FORCE)
   14 endif()
   15 
   16 # Ensure a path in the format common to both Unix and MinGW.
   17 FUNCTION(to_common_path input result)
   18     FILE(TO_NATIVE_PATH ${input} tmp)
   19     STRING(REGEX REPLACE "^(.):" "/\\1" tmp ${tmp})
   20     SET(${result} ${tmp} PARENT_SCOPE)
   21 ENDFUNCTION(to_common_path)
   22 
   23 # Build a shared library by default
   24 INCLUDE(GenerateExportHeader)
   25 option(BUILD_SHARED_LIBS "Build a shared library" ON)
   26 if(BUILD_SHARED_LIBS)
   27     set(CMAKE_POSITION_INDEPENDENT_CODE ON)
   28     IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
   29         set(CMAKE_BUILD_RPATH "$ORIGIN/../lib")
   30         set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
   31     ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
   32         set(CMAKE_BUILD_RPATH "@executable_path/../../lib")
   33         set(CMAKE_INSTALL_RPATH "@executable_path/../../lib")
   34     ELSE()
   35         MESSAGE(WARNING "Relocatable binary distribution is not supported for "
   36                 "O/S \"${CMAKE_SYSTEM_NAME}\"")
   37     ENDIF()
   38 endif()
   39 
   40 # A little bit of Windows/Visual Studio housekeeping.
   41 IF(MSVC)
   42     # Set a property used with Visual Studio
   43     SET(GLOBAL PROPERTY USE_FOLDERS ON)
   44 
   45     # Suppress CRT warnings.
   46     ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
   47 
   48     OPTION(ENABLE_DLL "Build a Windows DLL." ${BUILD_SHARED_LIBS})
   49     MESSAGE(STATUS "Building Windows DLL: ${ENABLE_DLL}")
   50     IF(ENABLE_DLL)
   51        SET(BUILD_DLL ON CACHE BOOL "")
   52        ADD_DEFINITIONS(-DDLL_UDUNITS2)
   53        ADD_DEFINITIONS(-DDLL_EXPORT)
   54     ENDIF()
   55 ENDIF()
   56 
   57 ###
   58 # Fix to make sure we don't try to include unistd.h
   59 # when using Visual Studio.
   60 ###
   61 INCLUDE(${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
   62 CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
   63 IF(NOT HAVE_UNISTD_H)
   64   SET(YY_NO_UNISTD_H TRUE)
   65 ENDIF()
   66 
   67 # Ensures a path in the native format.
   68 #FUNCTION(to_native_path input result)
   69 #    FILE(TO_NATIVE_PATH ${input} tmp)
   70 #    IF (WIN32 AND NOT UNIX)
   71 #        STRING(REGEX REPLACE "/" "\\\\" tmp "${tmp}")
   72 #    ENDIF()
   73 #    SET(${result} "${tmp}" PARENT_SCOPE)
   74 #ENDFUNCTION(to_native_path)
   75 
   76 #FILE(TO_NATIVE_PATH "${CMAKE_INSTALL_PREFIX}/share/udunits/udunits2.xml"
   77 #    DEFAULT_UDUNITS2_XML_PATH)
   78 FILE(TO_NATIVE_PATH "${CMAKE_INSTALL_PREFIX}/share/udunits/udunits2.xml" tmp)
   79 #MESSAGE("tmp = \"${tmp}\"")
   80 
   81 STRING(REGEX REPLACE "\\\\ " " " tmp "${tmp}")
   82 #MESSAGE("tmp = \"${tmp}\"")
   83 #STRING(REGEX REPLACE "\\\\" "\\\\\\\\" DEFAULT_UDUNITS2_XML_PATH "${tmp}")
   84 
   85 # Replace '\' with '\\' on Windows.
   86 IF(MSVC)
   87     STRING(REPLACE "\\" "\\\\" tmp "${tmp}")
   88 ENDIF(MSVC)
   89 
   90 SET(DEFAULT_UDUNITS2_XML_PATH "${tmp}")
   91 MESSAGE("DEFAULT_UDUNITS2_XML_PATH = \"${DEFAULT_UDUNITS2_XML_PATH}\"")
   92 
   93 INCLUDE(CheckFunctionExists)
   94 INCLUDE(CTest)
   95 enable_testing()
   96 
   97 # The following fails on Gilda:
   98 #INCLUDE(GNUInstallDirs)
   99 # Hence:
  100 SET(CMAKE_INSTALL_INFODIR share/info)
  101 SET(CMAKE_INSTALL_DOCDIR share/doc/udunits)
  102 
  103 to_common_path(${CMAKE_SOURCE_DIR} common_source_dir)
  104 to_common_path(${CMAKE_INSTALL_INFODIR} common_install_infodir)
  105 
  106 # Determines if the top-level info(1)-file, "dir", should be modified.
  107 find_program(INSTALL_INFO install-info)
  108 IF (NOT INSTALL_INFO)
  109     MESSAGE("install-info(1) not found. Top-level info(1)-file will not be modified.")
  110 ELSE()
  111     EXECUTE_PROCESS(COMMAND ${INSTALL_INFO} --version OUTPUT_QUIET
  112             RESULT_VARIABLE status)
  113     IF(NOT status EQUAL "0")
  114         MESSAGE("install-info(1) failure. Top-level info(1)-file will not be modified.")
  115         SET(INSTALL_INFO "NO")
  116     ELSE()
  117         EXECUTE_PROCESS(COMMAND ${INSTALL_INFO} --version COMMAND head -1
  118             COMMAND grep -q -i -v debian RESULT_VARIABLE status)
  119         IF(NOT status EQUAL "0")
  120             MESSAGE("Debian system. Top-level info(1)-file will not be modified.")
  121             SET(INSTALL_INFO "NO")
  122         ENDIF()
  123     ENDIF()
  124 ENDIF()
  125 
  126 # Declares documentation in texinfo(5) format. If "input" is relative, then it's
  127 # resolved using the current source-directory. A custom target is derived from
  128 # the filename and added to the default build target. The resulting
  129 # documentation files are added to the "install" target.
  130 find_program(MAKEINFO makeinfo)
  131 IF (NOT MAKEINFO)
  132     MESSAGE(WARNING "makeinfo(1) not found. Existing documentation will be used.")
  133 ENDIF()
  134 FUNCTION(texi_doc input)
  135     string(REGEX REPLACE ".*/" "" basename ${input})
  136     string(REGEX REPLACE "\\..*" "" file ${basename})
  137     to_common_path(${input} common_input)
  138     IF (NOT MAKEINFO)
  139         MESSAGE("Texinfo-file \"${common_input}\" will not be processed.")
  140     ELSE()
  141         add_custom_command(
  142             WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  143             OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${file}.info"
  144                 "${CMAKE_CURRENT_SOURCE_DIR}/${file}.html"
  145             MAIN_DEPENDENCY ${input}
  146             DEPENDS ${ARGN}
  147             COMMAND ${MAKEINFO} -o ${file}.info -I ${common_source_dir}
  148                 ${common_input}
  149             COMMAND ${MAKEINFO} -o ${file}.html -I ${common_source_dir}
  150                 --html --no-split ${common_input}
  151             VERBATIM
  152             COMMENT "Creating documentation from ${common_input}")
  153     ENDIF()
  154     add_custom_target(${file}_doc ALL
  155         DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.info
  156             ${CMAKE_CURRENT_SOURCE_DIR}/${file}.html)
  157     install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/${file}.info" DESTINATION
  158             ${CMAKE_INSTALL_INFODIR})
  159     install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/${file}.html" DESTINATION
  160             ${CMAKE_INSTALL_DOCDIR})
  161     if(INSTALL_INFO)
  162         SET(outpath "${common_install_infodir}/${file}.info")
  163         add_custom_command(
  164             OUTPUT "${CMAKE_INSTALL_INFODIR}/dir"
  165             MAIN_DEPENDENCY "${outpath}"
  166             COMMAND ${INSTALL_INFO} --info-dir="${common_install_infodir}"
  167                 "${outpath}"
  168             VERBATIM
  169             COMMENT "Adjusting top-level info(1)-file according to ${outpath}")
  170     endif()
  171 ENDFUNCTION(texi_doc)
  172 
  173 # This package uses math functions
  174 CHECK_FUNCTION_EXISTS(log10 HAVE_LOG10)
  175 IF (NOT HAVE_LOG10)
  176     FIND_LIBRARY(MATH_LIBRARY NAMES m math)
  177     IF(NOT MATH_LIBRARY)
  178         MESSAGE(FATAL_ERROR "Unable to find a C math library.")
  179     ENDIF()
  180 ENDIF()
  181 
  182 # The EXPAT library, which implements a SAX XML parser, is used to parse the
  183 # units database
  184 INCLUDE(FindEXPAT)
  185 IF(NOT EXPAT_FOUND)
  186     MESSAGE(FATAL_ERROR "Unable to find an EXPAT library.")
  187     IF(NOT EXPAT_INCLUDE_DIRS)
  188         MESSAGE(FATAL_ERROR "Unable to find an EXPAT header-file.")
  189     ENDIF()
  190 ENDIF()
  191 
  192 # The CUnit library is used for unit-testing
  193 FIND_LIBRARY(CUNIT_LIBRARY cunit)
  194 IF(CUNIT_LIBRARY)
  195     FIND_PATH(CUNIT_INCLUDE_DIR "CUnit/CUnit.h")
  196     IF (NOT CUNIT_INCLUDE_DIR)
  197         MESSAGE(STATUS "Unable to find CUnit header-file. Unit-testing not enabled.")
  198     ELSE()
  199         MESSAGE(STATUS "Found CUnit. Unit-testing enabled.")
  200         ENABLE_TESTING()
  201     ENDIF()
  202 ELSE()
  203     MESSAGE(STATUS "Unable to find CUnit library. Unit-testing not enabled.")
  204 ENDIF()
  205 
  206 CONFIGURE_FILE(
  207     "${PROJECT_SOURCE_DIR}/config.h.cmake"
  208     "${PROJECT_BINARY_DIR}/config.h")
  209 # Necessary for the compiler to find "config.h":
  210 INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}")
  211 
  212 ADD_SUBDIRECTORY (lib)
  213 
  214 # Import symbols instead of export them.
  215 IF(BUILD_DLL)
  216     REMOVE_DEFINITIONS(-DDLL_EXPORT)
  217 ENDIF()
  218 
  219 ADD_SUBDIRECTORY (prog)
  220 
  221 # The documentation is in texinfo(5) format
  222 texi_doc(udunits2.texi version.texi COPYRIGHT)
  223 
  224 # Install CHANGE_LOG and COPYRIGHT
  225 install(FILES "${CMAKE_SOURCE_DIR}/CHANGE_LOG" DESTINATION
  226             ${CMAKE_INSTALL_DOCDIR})
  227 install(FILES "${CMAKE_SOURCE_DIR}/COPYRIGHT" DESTINATION
  228             ${CMAKE_INSTALL_DOCDIR})
  229 
  230 # Test the installation
  231 SET(util "${CMAKE_INSTALL_PREFIX}/bin/udunits2")
  232 IF(WIN32)
  233     STRING(REGEX REPLACE "/" "\\\\" util "${util}")
  234 ENDIF()
  235 #MESSAGE("util = \"${util}\"")
  236 ADD_CUSTOM_TARGET(install_test "${util}" -A -H km -W m
  237     COMMENT "Checking installation...")
  238 
  239 # Create an installer
  240 INCLUDE(InstallRequiredSystemLibraries)
  241 # Apparently, CMAKE_SYSTEM_PROCESSOR can't be overridden via the "-D..." option.
  242 IF (WIN32)
  243     SET(CPACK_GENERATOR "NSIS")
  244     GET_FILENAME_COMPONENT(CPACK_NSIS_INSTALL_ROOT "${CMAKE_INSTALL_PREFIX}" PATH)
  245     GET_FILENAME_COMPONENT(CPACK_PACKAGE_INSTALL_DIRECTORY "${CMAKE_INSTALL_PREFIX}" NAME)
  246     STRING(REGEX REPLACE "/" "\\\\" CPACK_PACKAGE_INSTALL_DIRECTORY
  247         "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
  248     SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} UDUNITS-2")
  249     SET(CPACK_NSIS_HELP_LINK "http://www.unidata.ucar.edu/software/udunits")
  250     SET(CPACK_NSIS_MODIFY_PATH ON)
  251     SET(CPACK_NSIS_URL_INFO_ABOUT "${CPACK_NSIS_HELP_LINK}")
  252 #   # There is a bug in NSI that does not handle full unix paths properly. Make
  253 #   # sure there is at least one set of four (4) backslashes.
  254 #   SET(CPACK_PACKAGE_ICON "${CMake_SOURCE_DIR}/Utilities/Release\\\\InstallIcon.bmp")
  255 #   SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\MyExecutable.exe")
  256 ENDIF()
  257 
  258 SET(CPACK_DEBIAN_PACKAGE_DEPENDS "expat, libexpat-dev")
  259 SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CMAKE_HOST_SYSTEM_PROCESSOR}")
  260 SET(CPACK_RPM_PACKAGE_REQUIRES "expat, expat-devel")
  261 SET(CPACK_RPM_PACKAGE_PROVIDES "udunits2(1), libudunits2, udunits2.h, converter.h")
  262 
  263 SET(CPACK_PACKAGE_FILE_NAME
  264         "${CMAKE_PROJECT_NAME}-${CMAKE_PROJECT_VERSION}-${CMAKE_HOST_SYSTEM_PROCESSOR}")
  265 SET(CPACK_PACKAGE_CONTACT "support-udunits@unidata.ucar.edu")
  266 SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README")
  267 SET(CPACK_PACKAGE_EXECUTABLES "udunits2")
  268 SET(CPACK_PACKAGE_VENDOR "University Corporation for Atmospheric Research")
  269 SET(CPACK_PACKAGING_INSTALL_PREFIX "/usr/local")
  270 SET(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README")
  271 SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYRIGHT")
  272 SET(CPACK_PACKAGE_RELOCATABLE "ON")
  273 SET(CPACK_GENERATOR "RPM;DEB")
  274 # The following causes cpack(1) to fail
  275 INCLUDE(CPack)
  276 #include(UseRPMTools)
  277 #    if(RPMTools_ADD_RPM_TARGETS("udunits"))
  278 #endif()