为MacOS框架安装CMake软件包配置文件

时间:2019-02-13 12:28:52

标签: macos cmake

我用CMake创建了一个版本化的MacOS框架,偶然发现了在何处安装软件包配置文件sample-config.cmakesample-config-version.cmakesample-exports.cmakesample-exports-release.cmake的问题。

该框架已版本化,因此其结构大致如下:

<sample.framework>
   |-- Headers                 # link to Versions/Current/Headers
   |-- Resources               # link to Versions/Current/Resources
   +-- Versions
       |-- Current             # link to B
       +-- B
           |-- Headers
           +-- Resources
               |-- CMake
               +-- Info.plist

我使用CMakes CMakePackageConfigHelpers宏从包含内容的模板sample-config.cmake.in生成程序包配置文件

@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/sample-export.cmake")

CMake没有提到版本控制框架,建议将文件安装到目录Resources/CMake中。

我是通过致电

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sample-config.cmake"
  DESTINATION sample.framework/Resources/CMake
  COMPONENT development
)

生成的文件如下:

####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
####### Any changes to this file will be overwritten by the next CMake run ####
####### The input file was sample-config.cmake.in                            ########

get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)

macro(set_and_check _var _file)
  set(${_var} "${_file}")
  if(NOT EXISTS "${_file}")
    message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
  endif()
endmacro()

macro(check_required_components _NAME)
  foreach(comp ${${_NAME}_FIND_COMPONENTS})
    if(NOT ${_NAME}_${comp}_FOUND)
      if(${_NAME}_FIND_REQUIRED_${comp})
        set(${_NAME}_FOUND FALSE)
      endif()
    endif()
  endforeach()
endmacro()

include("${CMAKE_CURRENT_LIST_DIR}/sample-export.cmake")

错误:

尽管我将这些文件安装到Resources/CMake还是安装到Versions/B/Resources/CMake,但它们都指向同一目录,所以生成的配置文件有所不同。

通过Resources链接到Resources/CMake进行安装时,设置为PACKAGE_PREFIX_DIR的调用生成为

`get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)`

但是通过Versions/B/Resources/CMake安装时,它生成为

`get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../../../" ABSOLUTE)`

因此,安装到find_package(sample CONFIG)Versions/B/Resources/CMake无法找到该软件包。

以前有人遇到过此错误吗?

感谢您对此的任何投入。

0 个答案:

没有答案