forked from bilke/cmake-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUseBackportedModules.cmake
More file actions
114 lines (99 loc) · 3.53 KB
/
UseBackportedModules.cmake
File metadata and controls
114 lines (99 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# - Do a version-dependent check and auto-include backported modules dirs
#
# Name your module directories cmake-*-modules where * is the full
# (maj.min.patch) version number that they came from. You can use
# subdirectories within those directories, if you like - all directories
# inside of a cmake-*-modules dir for a newer version of CMake that what
# we're running, that contain one or more .cmake files, will be appended
# to the CMAKE_MODULE_PATH.
#
# When backporting modules, be sure to test them and follow copyright
# instructions (usually updating copyright notices)
#
# Requires these CMake modules:
# CleanDirectoryList
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
if(NOT CMAKE_VERSION) # defined in >=2.6.3
set(_cmver
"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}")
else()
set(_cmver "${CMAKE_VERSION}")
endif()
include(CleanDirectoryList)
# No debugging output please
set(USE_BACKPORTED_MODULES_VERBOSE NO)
get_filename_component(_moddir ${CMAKE_CURRENT_LIST_FILE} PATH)
file(GLOB _globbed "${_moddir}/cmake-*-modules")
if(USE_BACKPORTED_MODULES_VERBOSE)
message(STATUS
"UseBackportedModules: Detected use of CMake version ${_cmver}")
message(STATUS "Checking these base directories: ${_globbed}")
endif()
foreach(_dir ${_globbed})
string(REGEX
MATCH
"cmake-[0-9].[0-9].[0-9]-modules"
_dirname
"${_dir}")
string(REGEX
REPLACE
"cmake-([0-9].[0-9].[0-9])-modules"
"\\1"
_ver
"${_dirname}")
string(REGEX
REPLACE
"cmake-([0-9]).([0-9]).([0-9])-modules"
"\\1_\\2_\\3"
_ver_clean
"${_dirname}")
if(USE_BACKPORTED_MODULES_VERBOSE)
message(STATUS "${_dir}: ${_ver} ${_ver_clean}")
endif()
if("${_cmver}" VERSION_LESS "${_ver}")
list(APPEND _upgradever "${_ver_clean}")
file(GLOB_RECURSE _modules "${_dir}/*.cmake")
foreach(_mod ${_modules})
get_filename_component(_path "${_mod}" PATH)
list(APPEND _paths_${_ver_clean} "${_path}")
endforeach()
endif()
endforeach()
# Autoinclude files from oldest version to newest version
if(_upgradever)
set(_save_cmake_module_path ${CMAKE_MODULE_PATH})
list(REMOVE_DUPLICATES _upgradever)
list(SORT _upgradever)
foreach(_ver_clean ${_upgradever})
clean_directory_list(_paths_${_ver_clean})
foreach(_dir ${_paths_${_ver_clean}})
set(CMAKE_MODULE_PATH ${_dir} ${_save_cmake_module_path})
include("${_dir}/autoinclude.cmake" OPTIONAL RESULT_VARIABLE _result)
if(USE_BACKPORTED_MODULES_VERBOSE)
message(STATUS "${_dir} - Autoincluded: ${_result}")
endif()
endforeach()
endforeach()
set(CMAKE_MODULE_PATH ${_save_cmake_module_path})
endif()
# Add the module path from newest version to oldest version
set(_added_module_path)
if(_upgradever)
list(REVERSE _upgradever)
foreach(_ver_clean ${_upgradever})
list(APPEND _added_module_path ${_paths_${_ver_clean}})
endforeach()
endif()
list(APPEND CMAKE_MODULE_PATH ${_added_module_path})
if(USE_BACKPORTED_MODULES_VERBOSE)
message(STATUS "New module path: ${CMAKE_MODULE_PATH}")
endif()