diff --git a/CMakeLists.txt b/CMakeLists.txt index e6e6a5f1..32d37da3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ cmake_policy(VERSION 3.12...3.15) # Project ###################################################################### set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) include(FairMQLib) +include(FairFindPackage2) get_git_version() diff --git a/cmake/FairFindPackage2.cmake b/cmake/FairFindPackage2.cmake new file mode 100644 index 00000000..b67c770a --- /dev/null +++ b/cmake/FairFindPackage2.cmake @@ -0,0 +1,114 @@ +################################################################################ +# Copyright (C) 2018-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH # +# # +# This software is distributed under the terms of the # +# GNU Lesser General Public Licence (LGPL) version 3, # +# copied verbatim in the file "LICENSE" # +################################################################################ + +# +# find_package2(PRIVATE|PUBLIC|INTERFACE +# [VERSION ] +# [COMPONENTS ] +# [ADD_REQUIREMENTS_OF ] +# [any other option the native find_package supports]...) +# +# Wrapper around CMake's native find_package command to add some features and bookkeeping. +# +# The qualifier (PRIVATE|PUBLIC|INTERFACE|BUNDLED) to the package to populate +# the variables PROJECT_[INTERFACE]__([VERSION]|[COMPONENTS]|PACKAGE_DEPENDENCIES) +# accordingly. This bookkeeping information is used to print our dependency found summary +# table and to generate a part of our CMake package. BUNDLED decays to PUBLIC if the variable +# _BUNDLED is false and to PRIVATE otherwise. +# +# When a dependending package is listed with ADD_REQUIREMENTS_OF the variables +# __VERSION|COMPONENTS are looked up to and added to the native +# VERSION (selected highest version) and COMPONENTS (deduplicated) args. +# +# COMPONENTS and VERSION args are then just passed to the native find_package. +# +macro(find_package2 qualifier pkgname) + cmake_parse_arguments(ARGS "" "VERSION" "COMPONENTS;ADD_REQUIREMENTS_OF" ${ARGN}) + + string(TOUPPER ${pkgname} pkgname_upper) + set(__old_cpp__ ${CMAKE_PREFIX_PATH}) + set(CMAKE_PREFIX_PATH ${${pkgname_upper}_ROOT} $ENV{${pkgname_upper}_ROOT} ${CMAKE_PREFIX_PATH}) + + # build lists of required versions and components + unset(__required_versions__) + unset(__components__) + if(ARGS_VERSION) + list(APPEND __required_versions__ ${ARGS_VERSION}) + endif() + if(ARGS_COMPONENTS) + list(APPEND __components__ ${ARGS_COMPONENTS}) + endif() + if(ARGS_ADD_REQUIREMENTS_OF) + foreach(dep_pkgname IN LISTS ARGS_ADD_REQUIREMENTS_OF) + if(${dep_pkgname}_${pkgname}_VERSION) + list(APPEND __required_versions__ ${${dep_pkgname}_${pkgname}_VERSION}) + endif() + if(${dep_pkgname}_${pkgname}_COMPONENTS) + list(APPEND __components__ ${${dep_pkgname}_${pkgname}_COMPONENTS}) + endif() + endforeach() + endif() + + # select highest required version + unset(__version__) + if(__required_versions__) + list(GET __required_versions__ 0 __version__) + foreach(v IN LISTS __required_versions__) + if(${v} VERSION_GREATER ${__version__}) + set(__version__ ${v}) + endif() + endforeach() + endif() + # deduplicate required component list + if(__components__) + list(REMOVE_DUPLICATES __components__) + endif() + + # call native find_package + if(__components__) + find_package(${pkgname} ${__version__} QUIET COMPONENTS ${__components__} ${ARGS_UNPARSED_ARGUMENTS}) + else() + find_package(${pkgname} ${__version__} QUIET ${ARGS_UNPARSED_ARGUMENTS}) + endif() + + if(${qualifier} STREQUAL BUNDLED) + if(${pkgname}_BUNDLED) + set(__qualifier__ PRIVATE) + else() + set(__qualifier__ PUBLIC) + endif() + else() + set(__qualifier__ ${qualifier}) + endif() + + if(${pkgname}_FOUND) + if(${__qualifier__} STREQUAL PRIVATE) + set(PROJECT_${pkgname}_VERSION ${__version__}) + set(PROJECT_${pkgname}_COMPONENTS ${__components__}) + set(PROJECT_PACKAGE_DEPENDENCIES ${PROJECT_PACKAGE_DEPENDENCIES} ${pkgname}) + elseif(${__qualifier__} STREQUAL PUBLIC) + set(PROJECT_${pkgname}_VERSION ${__version__}) + set(PROJECT_${pkgname}_COMPONENTS ${__components__}) + set(PROJECT_PACKAGE_DEPENDENCIES ${PROJECT_PACKAGE_DEPENDENCIES} ${pkgname}) + set(PROJECT_INTERFACE_${pkgname}_VERSION ${__version__}) + set(PROJECT_INTERFACE_${pkgname}_COMPONENTS ${__components__}) + set(PROJECT_INTERFACE_PACKAGE_DEPENDENCIES ${PROJECT_INTERFACE_PACKAGE_DEPENDENCIES} ${pkgname}) + elseif(${__qualifier__} STREQUAL INTERFACE) + set(PROJECT_INTERFACE_${pkgname}_VERSION ${__version__}) + set(PROJECT_INTERFACE_${pkgname}_COMPONENTS ${__components__}) + set(PROJECT_INTERFACE_PACKAGE_DEPENDENCIES ${PROJECT_INTERFACE_PACKAGE_DEPENDENCIES} ${pkgname}) + endif() + endif() + + unset(__qualifier__) + unset(__version__) + unset(__components__) + unset(__required_versions__) + set(CMAKE_PREFIX_PATH ${__old_cpp__}) + unset(__old_cpp__) +endmacro() diff --git a/cmake/FairMQLib.cmake b/cmake/FairMQLib.cmake index df4ea15a..6259420b 100644 --- a/cmake/FairMQLib.cmake +++ b/cmake/FairMQLib.cmake @@ -1,5 +1,5 @@ ################################################################################ -# Copyright (C) 2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH # +# Copyright (C) 2018-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH # # # # This software is distributed under the terms of the # # GNU Lesser General Public Licence (LGPL) version 3, # @@ -337,113 +337,6 @@ macro(install_cmake_package) ) endmacro() -# -# find_package2(PRIVATE|PUBLIC|INTERFACE -# [VERSION ] -# [COMPONENTS ] -# [ADD_REQUIREMENTS_OF ] -# [any other option the native find_package supports]...) -# -# Wrapper around CMake's native find_package command to add some features and bookkeeping. -# -# The qualifier (PRIVATE|PUBLIC|INTERFACE|BUNDLED) to the package to populate -# the variables PROJECT_[INTERFACE]__([VERSION]|[COMPONENTS]|PACKAGE_DEPENDENCIES) -# accordingly. This bookkeeping information is used to print our dependency found summary -# table and to generate a part of our CMake package. BUNDLED decays to PUBLIC if the variable -# _BUNDLED is false and to PRIVATE otherwise. -# -# When a dependending package is listed with ADD_REQUIREMENTS_OF the variables -# __VERSION|COMPONENTS are looked up to and added to the native -# VERSION (selected highest version) and COMPONENTS (deduplicated) args. -# -# COMPONENTS and VERSION args are then just passed to the native find_package. -# -macro(find_package2 qualifier pkgname) - cmake_parse_arguments(ARGS "" "VERSION" "COMPONENTS;ADD_REQUIREMENTS_OF" ${ARGN}) - - string(TOUPPER ${pkgname} pkgname_upper) - set(__old_cpp__ ${CMAKE_PREFIX_PATH}) - set(CMAKE_PREFIX_PATH ${${pkgname_upper}_ROOT} $ENV{${pkgname_upper}_ROOT} ${CMAKE_PREFIX_PATH}) - - # build lists of required versions and components - unset(__required_versions__) - unset(__components__) - if(ARGS_VERSION) - list(APPEND __required_versions__ ${ARGS_VERSION}) - endif() - if(ARGS_COMPONENTS) - list(APPEND __components__ ${ARGS_COMPONENTS}) - endif() - if(ARGS_ADD_REQUIREMENTS_OF) - foreach(dep_pkgname IN LISTS ARGS_ADD_REQUIREMENTS_OF) - if(${dep_pkgname}_${pkgname}_VERSION) - list(APPEND __required_versions__ ${${dep_pkgname}_${pkgname}_VERSION}) - endif() - if(${dep_pkgname}_${pkgname}_COMPONENTS) - list(APPEND __components__ ${${dep_pkgname}_${pkgname}_COMPONENTS}) - endif() - endforeach() - endif() - - # select highest required version - unset(__version__) - if(__required_versions__) - list(GET __required_versions__ 0 __version__) - foreach(v IN LISTS __required_versions__) - if(${v} VERSION_GREATER ${__version__}) - set(__version__ ${v}) - endif() - endforeach() - endif() - # deduplicate required component list - if(__components__) - list(REMOVE_DUPLICATES __components__) - endif() - - # call native find_package - if(__components__) - find_package(${pkgname} ${__version__} QUIET COMPONENTS ${__components__} ${ARGS_UNPARSED_ARGUMENTS}) - else() - find_package(${pkgname} ${__version__} QUIET ${ARGS_UNPARSED_ARGUMENTS}) - endif() - - if(${qualifier} STREQUAL BUNDLED) - if(${pkgname}_BUNDLED) - set(__qualifier__ PRIVATE) - else() - set(__qualifier__ PUBLIC) - endif() - else() - set(__qualifier__ ${qualifier}) - endif() - - if(${pkgname}_FOUND) - if(${__qualifier__} STREQUAL PRIVATE) - set(PROJECT_${pkgname}_VERSION ${__version__}) - set(PROJECT_${pkgname}_COMPONENTS ${__components__}) - set(PROJECT_PACKAGE_DEPENDENCIES ${PROJECT_PACKAGE_DEPENDENCIES} ${pkgname}) - elseif(${__qualifier__} STREQUAL PUBLIC) - set(PROJECT_${pkgname}_VERSION ${__version__}) - set(PROJECT_${pkgname}_COMPONENTS ${__components__}) - set(PROJECT_PACKAGE_DEPENDENCIES ${PROJECT_PACKAGE_DEPENDENCIES} ${pkgname}) - set(PROJECT_INTERFACE_${pkgname}_VERSION ${__version__}) - set(PROJECT_INTERFACE_${pkgname}_COMPONENTS ${__components__}) - set(PROJECT_INTERFACE_PACKAGE_DEPENDENCIES ${PROJECT_INTERFACE_PACKAGE_DEPENDENCIES} ${pkgname}) - elseif(${__qualifier__} STREQUAL INTERFACE) - set(PROJECT_INTERFACE_${pkgname}_VERSION ${__version__}) - set(PROJECT_INTERFACE_${pkgname}_COMPONENTS ${__components__}) - set(PROJECT_INTERFACE_PACKAGE_DEPENDENCIES ${PROJECT_INTERFACE_PACKAGE_DEPENDENCIES} ${pkgname}) - endif() - endif() - - unset(__qualifier__) - unset(__version__) - unset(__components__) - unset(__required_versions__) - set(CMAKE_PREFIX_PATH ${__old_cpp__}) - unset(__old_cpp__) -endmacro() - macro(exec cmd) join("${ARGN}" " " args) file(APPEND ${${package}_BUILD_LOGFILE} ">>> ${cmd} ${args}\n")