TriBITS icon indicating copy to clipboard operation
TriBITS copied to clipboard

`INCLUDE()`s without proper path specification

Open nschloe opened this issue 11 years ago • 9 comments

TriBITS contains heaps of INCLUDE() statements

$ grep -r "INCLUDE(" package_arch/ | wc -l 
256

referencing its own files à la

INCLUDE(TribitsAddAdvancedTest)

The directories in which CMake searches for include files does by default not include the current directory, however. Even if this should work, this naive include path can be overridden by setting CMAKE_MODULE_PATH.

A more robust solution would be to includes files like

INCLUDE(${CMAKE_CURRENT_LIST_DIR}/TribitsAddAdvancedTest.cmake)

nschloe avatar Sep 24 '14 09:09 nschloe

CMAKE_CURRENT_LIST_DIR appears to not work correctly when used with CTest (and a lot of the TriBITS code is actually run directly under CTest as well as CMake). However, explicitly prepending the right paths to CMAKE_MODULE_PATH seems to work robustly. See https://github.com/TriBITSPub/TriBITS/commit/4ac493c4a30cd57e05c9816875a7f0fbcc3e6aa2 for more details. What exactly is the problem?

bartlettroscoe avatar Sep 24 '14 10:09 bartlettroscoe

What exactly is the problem?

I'm doing

set(CMAKE_MODULE_PATH
  ${CMAKE_MODULE_PATH}
  "/absolute/path/to/tribits/"
  "/absolute/path/to/tribits/package_arch/"
  )
include(TriBITS)

in a project of mine and get

CMake Error at /absolute/path/to/tribits/package_arch/TribitsProject.cmake:69 (INCLUDE):
  include could not find load file:

    TribitsCMakePolicies

and heaps of errors of the same kind. Using ${CMAKE_CURRENT_LIST_DIR} works.

nschloe avatar Sep 24 '14 13:09 nschloe

CMAKE_CURRENT_LIST_DIR appears to not work correctly when used with CTest

How can I reproduce this?

nschloe avatar Sep 24 '14 13:09 nschloe

Nico,

To use TriBITS, just:

INCLUDE(${${PROJECT_NAME}_TRIBITS_DIR}/TriBITS.cmake)

This will add any module paths you need.

I don't recommend manually trying to to CMAKE_MODULE_PATH because TriBITS will likely be refactored soon and move things around. However, if you really want to see the what the full CMAKE_MODULE_PATH is for all of TriBITS, see:

TriBITS/package_arch/TribitsProjectImpl.cmake

that will always be correct.

I will have to fabricate an example of the problem with CTest that demonstrate the issue. Given what I saw, it should not be very hard to do.

bartlettroscoe avatar Sep 24 '14 13:09 bartlettroscoe

INCLUDE(${${PROJECT_NAME}_TRIBITS_DIR}/TriBITS.cmake)

This will add any module paths you need.

I'm still getting the same errors.

I don't recommend manually trying to to CMAKE_MODULE_PATH because TriBITS will likely be refactored soon and move things around.

I will have to fabricate an example of the problem with CTest that demonstrate the issue.

Indeed. Just copy and paste the above example code into a separate CMakeLists.txt in some other place.

nschloe avatar Sep 24 '14 13:09 nschloe

Exactly what is causing your errors?

bartlettroscoe avatar Sep 24 '14 20:09 bartlettroscoe

Well, CMake can't find TribitsCMakePolicies. I'm not sure why, that is to say, I'm not sure why it should be able to find them. Can you reproduce the error from my comment above?

nschloe avatar Sep 24 '14 20:09 nschloe

I was not able to reproduce the error with a simple example. Something about the more complex use case must be changing behavior of CMAKE_CURRENT_LIST_DIR (or some other evil code is setting it to override it). If you don't mind, can you apply whatever explicit includes that fix your problem to branch and then I can take a look at them? The use case that causes the problem is related to the less than pretty and not at all unit tested TribitsDasbaordDriver code and it is hard to set up even a manual test case to test it.

bartlettroscoe avatar Sep 25 '14 15:09 bartlettroscoe

I just got hit by some defect with CMAKE_CURRENT_LIST_DIR with CMake 2.8.11 while working on VERA. For some reason it was reporting CMAKE_CURRENT_LIST_DIR being one directory below where it should be. I could not explain it. And that was with CMake, not CTest!

bartlettroscoe avatar Mar 11 '15 14:03 bartlettroscoe