3

Consider the following example of a FindXXX.cmake:

find_path(XXX_INCLUDE_DIR NAMES XXX/XXX.h)
find_path(XXXYYY_INCLUDE_DIR NAMES YYY.h)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(XXX DEFAULT_MSG
        XXX_INCLUDE_DIR XXXYYY_INCLUDE_DIR)

set(XXX_INCLUDE_DIRS "${XXX_INCLUDE_DIR} ${XXXYYY_INCLUDE_DIR}")

As it is in this example, XXX_INCLUDE_DIRS is a string with a space in the middle, and, thus, when added in CMakeLists.txt using

 target_include_directories(a PRIVATE ${XXX_INCLUDE_DIRS})

it is invoked by the compiler as

-I"XXXpath XXXYYYpath"

How should I modify the line

set(XXX_INCLUDE_DIRS ${XXX_INCLUDE_DIR} ${XXXYYY_INCLUDE_DIR})

which sets the value for the variable XXX_INCLUDE_DIRS?

The same question arises for multiple library paths in XXX_LIBRARIES.

usr1234567
  • 21,601
  • 16
  • 108
  • 128
Jorge Leitao
  • 19,085
  • 19
  • 85
  • 121
  • 1
    As a semicolon separated list? `set(xx_include_dirs "${dir_a};${dir_b})` – usr1234567 Jan 24 '17 at 14:19
  • 1
    I also like to quote from [CMake's documentation](https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html#find-modules): "The traditional approach is to use variables for everything, including libraries and executables. This is what most of the existing find modules provided by CMake do. The more modern approach is to behave as much like config file packages files as possible, by providing imported target. This has the advantage of propagating Transitive Usage Requirements to consumers." – Florian Jan 24 '17 at 14:20
  • Yes, I tried (updated question). @Florian, I do not even understand what they are trying to say with that quote, sorry. – Jorge Leitao Jan 24 '17 at 14:36
  • 1
    @J.C.Leitão Just that by using imported targets you could avoid such kind of problems and make it easier to use your package (see e.g. [here](http://stackoverflow.com/questions/33462209/making-cmake-library-accessible-by-other-cmake-packages-automatically)). – Florian Jan 24 '17 at 14:41
  • Good to know about that. Unfortunately, I am not writing a package; I am writing a Find* for a dependency that I have. – Jorge Leitao Jan 24 '17 at 14:42
  • It is indeed semicolon, but because of caching, the result was not being updated. Thanks a lot. – Jorge Leitao Jan 24 '17 at 15:00

1 Answers1

5

You provide multiple entries for variables like XXX_LIBRARIES and XXX_INCLUDE_DIRS as a semicolon-separated list.

set(XXX_INCLUDE_DIRS "${XXX_INCLUDE_DIR};${XXXYYY_INCLUDE_DIR}")
usr1234567
  • 21,601
  • 16
  • 108
  • 128