c++cmakexercesxerces-c

Failing to use XercesC in a CMAKE project


I'm trying to create a CMAKE project that links to xerces-c on Windows. Xerces-C was built with cmake and installed in a folder. This is the layout of the installation:

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

This is my 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 is a variable defined in my master CMakeLists.txt

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

I execute cmake with following command:

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

When I execute cmake, I print the content of CMAKE_INCLUDE_PATH:

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

That's the correct location. I set this variable right before the find_package(XercesC REQUIRED) line.

But the package is not found. This is the error message:

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!

What I'm doing wrong? What can I do in order to tell CMAKE where to find Xerces? Maybe CMAKE_INCLUDE_PATH usage is wrong?


Solution

  • For hint CMake about the root of external packages, used in your project, one may hint that root in CMAKE_PREFIX_PATH variable:

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

    Such way, your CMakeLists.txt doesn't need to bother about these hints at all: it just uses find_package() and expect everything to work.

    See also that my answer about other ways of using CMAKE_PREFIX_PATH variable and others features of that variable.