1

I have two packages that are under the same catkin workspace

I have package A and package B where B needs to get include files and library files of A.

in CMakeLists.txt of A, I had

set(TEST_VAR "TEST")

configure_package_config_file(
  fooConfig.cmake.in
  ${CMAKE_CURRENT_BINARY_DIR}/fooConfig.cmake
  INSTALL_DESTINATION ...
  PATH_VARS
  TEST_VAR)

and defined fooConfig.cmake.in as following

set(foo_VERSION 0.0.1)
@PACKAGE_INIT@
set_and_check(foo_TEST "@PACKAGE_TEST_VAR@")

check_required_components(foo)

With the above set of codes, I should be able to use find_package keywords from B

find_package(foo REQUIRED)

In the scenario that I expect, foo_LIBRARIES should not be empty (filled in automatically) and foo_TEST should not be empty as I provided it through PATH_VARS

But I was seeing the following results

${foo_FOUND} - TRUE
${foo_TEST} - EMPTY !!!
${foo_INCLUDE_DIRS} - .../build/foo/usr/include
${foo_LIBRARIES} - EMPTY !!!

To understand the behavior in more depth, I have directly added message to generated fooConfig.cmake and printed out foo_TEST variable. However, I noticed that it was empty.

To summarize, I want to understand

  1. why ${foo_LIBRARIES} is not set correctly
  2. whether ${foo_TEST} being empty inside CMakeLists.txt of B is expected or not.
  3. why ${foo_TEST} is unavailable inside cmake.in

Thank you

Brandon Lee
  • 695
  • 1
  • 10
  • 22
  • "In the scenario that I expect, `foo_LIBRARIES` should not be empty (filled in automatically)" - none of scripts automatically generated by CMake doesn't set `XXX_LIBRARIES` variable automatically. Why do you thing this variable should be set automatically? – Tsyvarev Aug 19 '20 at 06:26
  • BTW, you may read generated `fooConfig.cmake` and check whether your expectations are actually take a place. This file contains some generated code, but also contains the whole code from your `.in` file with `@..@` substitution already performed. – Tsyvarev Aug 19 '20 at 06:37
  • @Tsyvarev Thank you for your feedbacks 1. I was expecting `XXX_LIBRARIES` to be defined as I saw some lines in generated `fooConfig.cmake` which set this variable. 2. I did not see any line related to `foo_TEST` variable inside generated cmake even though (as you said) substitution should've happened. Is it possible that `configure_package_config_file` has not processed the `cmake.in` file even though it locates it correctly? I noticed that it throws an error if it doesn't find it, which is not the case for me. – Brandon Lee Aug 19 '20 at 13:21
  • Are you sure you are inspecting the file `${CMAKE_CURRENT_BINARY_DIR}/fooConfig.cmake`, which is created by the code you show, and are not inspecting some other file (e.g. generated by the previous code)? – Tsyvarev Aug 19 '20 at 15:45
  • yes I was, after some investigation, it seems like `foo_INCLUDE_DIRS` and `foo_LIBRARIES` are set by catkin_package – Brandon Lee Aug 20 '20 at 22:28

0 Answers0