Unbounded include() recursion crashes CMake
Description
I'm trying to extend the functionality, of some Find modules provided by CMake. From the documentation, I should be able to do this via the "include()" function. What I'm wanting to do, is the runtime libraries for found packages into the "CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS" variables, so CPack is able build installation packages for different operating systems.
According to the CMake the include() function should ignore the path specified in CMAKE_MODULE_PATH (and use the System CMAKE module path) if the module calling the function is currently located in the path specified by CMAKE_MODULE_PATH. However, on my system when doing this, this causes a segmentation fault.
Relevant documentation:
https://cmake.org/cmake/help/v3.5/command/include.html
If a module is specified instead of a file, the file with name .cmake is searched first in CMAKE_MODULE_PATH, then in the CMake module directory. There is one exception to this: if the file which calls include() is located itself in the CMake module directory, then first the CMake module directory is searched and CMAKE_MODULE_PATH afterwards. See also policy CMP0017.
Note: This happens whether policy CMP0017 is set or not. i.e.: cmake_policy( SET CMP0017 NEW )
CMake/Operating System Information
> cmake --version
cmake version 3.5.2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
> uname -a
Linux [hostname] 4.6.6-300.fc24.x86_64 #1 SMP Wed Aug 10 21:07:35 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
> ls -l /usr/share/cmake/Modules/FindLibArchive.cmake
-rw-r--r--. 1 root root 2993 Apr 15 09:41 /usr/share/cmake/Modules/FindLibArchive.cmake
To reproduce:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" )
find_package( LibArchive )
FindLibArchive.cmake:
include( FindLibArchive )
Output:
> cmake .
Segmentation fault (core dumped)
Expected Result:###
- Does not crash
- The include call in the FindLibArchive.cmake (within the CMAKE_MODULE_PATH); would include the FindLibArchive.cmake in the cmake system module directory (/usr/share/cmake/Modules/FindLibArchive.cmake)