3

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?

Jepessen
  • 11,744
  • 14
  • 82
  • 149
  • What does it say for the library `XercesC_LIBRARY`? (also known as, are you sure you seleted the same target, 32 or 64bits, for noth?) – Matthieu Brucher Jan 28 '19 at 10:34
  • What do you mean exactly? In the error message it says that's missing. And I've selected the right target (64 bit) – Jepessen Jan 28 '19 at 10:36
  • Why would it be missing as it's obviously there? What does the error log say (CMakeFiles/CMakeError.log) – Matthieu Brucher Jan 28 '19 at 10:39
  • `CMakeFiles\CMakeError.log` is not created. `CMakeFiles\CMakeOutput.log` is empty. – Jepessen Jan 28 '19 at 10:43
  • That's odd. Neither should be empty. Are you sure you looked at the proper location? There is an error, so it should be int he error log (never saw it not happening). – Matthieu Brucher Jan 28 '19 at 10:44
  • @MatthieuBrucher: Given error is emitted by `message(FATAL_ERROR)` command, why do you think that `CMakeError.log` or `CMakeOutput.log` should contain a record about that error? – Tsyvarev Jan 28 '19 at 10:53
  • @Tsyvarev Because it failed finding XercesC libraries first. That should be int he error log, just as finding the include path should be there as well. The FATAL is due to the validation process after this step. So the FATAL is not the first error. – Matthieu Brucher Jan 28 '19 at 10:54
  • @MatthieuBrucher: I have never seen logging of `find_path` or `find_library` calls even if they failed. – Tsyvarev Jan 28 '19 at 10:56
  • I've just cleaned the build directory and perform the entire build again. It's the same. No CMakeErrors.log created. The CMakeOutput.log is too long to be posted here, but it does not contain any errors. just a bunch of Visual Studio project settings. Complete ouput is here https://pastebin.com/4m4p5hEW – Jepessen Jan 28 '19 at 10:57
  • OK, and nothing odd in the general log about this missing library? – Matthieu Brucher Jan 28 '19 at 11:00
  • Generally, in CMake projects INCLUDE_PATH is **not** a ROOT one and usually ends with `/include`. In your case include path should be `D:/lib/xercesc/3.2.2/include`. For find a library, you need to specify `CMAKE_LIBRARY_PATH` variable. Alternatively, you may specify (add) `CMAKE_PREFIX_PATH` variable: this variable affects on both library and headers searching and it contains exactly ROOT's of the packages. – Tsyvarev Jan 28 '19 at 11:01
  • @Tsyvarev Thanks! Using `CMAKE_PREFIX_PATH` solved my problem. Can you write an aswer so I can accept it? Thanks to everyone for helping me. – Jepessen Jan 28 '19 at 11:17

1 Answers1

4

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.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153