代码之家  ›  专栏  ›  技术社区  ›  Jepessen

未能在CMAKE项目中使用XercesC

  •  1
  • Jepessen  · 技术社区  · 5 年前

    我正在尝试创建一个链接到Windows上xerces-c的CMAKE项目。Xerces-C是用cmake构建的,安装在一个文件夹中。这是安装的布局:

    xercesc/3.2.2
      |
      |-bin
      |  |-xerces-c_3_2.dll
      |  |-xerces-c_3_2D.dll
      |  |-(many executables)
      |
      |-cmake
      |  |-XercesCConfig.cmake
      |  |-XercesCConfigInterna.cmale
      |  |-(other .cmake)
      |
      |-include
      |  |-xercesc
      |     |-dom
      |     |-framework
      |     |-internal
      |     |-parsers
      |     |-util
      |     |-(other folders)
      |
      |-lib
      |  |-xerces-c_3.lib
      |  |-xerces-c_3D.lib
      |
      |-share
         |-doc
            |-(documentation
    

    这是我的CMakeFile.txt

    cmake_minimum_required (VERSION 3.10.0)
    
    project (myproject)
    
    set (CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} ${XERCES_ROOT})
    message (STATUS "CMAKE_INCLUDE_PATH is ${CMAKE_INCLUDE_PATH}")
    find_package (XercesC REQUIRED)
    
    set (CMAKE_INCLUDE_CURRENT_DIR ON)
    include_directories (${CMAKE_CURRENT_SOURCE_DIR}/..)
    include_directories (${XercesC_INCLUDE_DIR})
    
    set (PROJECT_SRC
      Dummy.cpp
      )
    
    add_library (${PROJECT_NAME} SHARED ${PROJECT_SRC})
    

    XERCES_ROOT 是在我的master CMakeLists.txt中定义的变量

    set (XERCES_ROOT "" CACHE FILEPATH "Root directory of the Xerces-C installation")
    

     cmake -DBOOST_ROOT=D:\lib\Boost\1.69.0\ -DXERCES_ROOT=d:\lib\xercesc\3.2.2\ -G "Visual Studio 15 2017 Win64" ../
    

    当我执行cmake时,我打印 CMAKE_INCLUDE_PATH :

    -- CMAKE_INCLUDE_PATH is D:/lib/xercesc/3.2.2
    

    那是正确的位置。我将这个变量设置在 find_package(XercesC REQUIRED)

    但是找不到包。这是错误消息:

    CMake Error at C:/Program Files/CMake/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
      Failed to find XercesC (missing: XercesC_LIBRARY XercesC_INCLUDE_DIR
      XercesC_VERSION)
    Call Stack (most recent call first):
      C:/Program Files/CMake/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
      C:/Program Files/CMake/share/cmake-3.13/Modules/FindXercesC.cmake:98 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
      src/myproject/CMakeLists.txt:7 (find_package)
    
    
    -- Configuring incomplete, errors occurred!
    

    我做错了什么?我该怎么做才能告诉CMAKE在哪里可以找到Xerces?大概 CMAKE_INCLUDE_路径

    1 回复  |  直到 5 年前
        1
  •  3
  •   Tsyvarev    5 年前

    对于在您的项目中使用的关于外部包根的提示CMake,可以提示root-in CMAKE_PREFIX_PATH 变量:

    cmake -DCMAKE_PREFIX_PATH=d:\lib\xercesc\3.2.2\ <other-options>
    

    这样,你的 CMakeLists.txt 根本不需要担心这些提示:它只是使用 find_package()

    另见 that my answer 关于其他使用方法 CMAKE_前缀_路径 变量和该变量的其他特性。