0

I'm trying to write modules to use CMake with a custom compiler, however I'm stuck in CMakeDetermineCUSTOMCompiler.cmake. I'd like the modules to work either installed inside of CMake's Modules directory or an external directoy specified by CMAKE_MODULE_PATH.

To make it work installed in CMake's directory I can put:

configure_file(${CMAKE_ROOT}/Modules/CMakeCUSTOMCompiler.cmake.in

but then it doesn't work with CMAKE_MODULE_PATH. Is there any where I can reference the location of the current module? Or search the locations specified in CMAKE_MODULE_PATH?

dlasalle
  • 1,615
  • 3
  • 19
  • 25
  • 1
    Looks like variable [CMAKE_CURRENT_LIST_DIR](https://cmake.org/cmake/help/v3.7/variable/CMAKE_CURRENT_LIST_DIR.html) is what you seek: it refers to the location of the currently processed file. Note, that for use such reference inside function or macro, you need firstly to [cache it](https://stackoverflow.com/questions/31939360/can-we-know-the-directory-where-the-macro-or-functions-are-located-in-cmake/31940031#31940031). – Tsyvarev Aug 05 '17 at 11:13
  • I had thought it referred only to the current `CMakeLists.txt`, but you're right, it worked. Thanks! – dlasalle Aug 05 '17 at 14:41

1 Answers1

1

Variable CMAKE_CURRENT_LIST_DIR is what you seek: it refers to the location of the currently processed file.

Note, that for use such reference inside function or macro, you need firstly to cache it.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153