forked from qgis/QGIS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeDebugMacros.cmake
42 lines (36 loc) · 1.35 KB
/
CMakeDebugMacros.cmake
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
# Macros/functions for debugging CMake
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2016, Larry Shaffer, <lshaffer (at) boundlessgeo (dot) com>>
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
# Dump current CMake variables to file
#
# Usage:
# INCLUDE(CMakeDebugMacros)
# DUMP_CMAKE_VARS() or DUMP_CMAKE_VARS("regex")
#
# regex: optional ARGV0 regular expression for filtering output variable names
#
# Outputs the result relative to the current CMake file being processed and
# writes to a file with name "<file-basename>_cmake-vars.txt" to the current
# build (binary) directory
#
function(DUMP_CMAKE_VARS)
get_filename_component(_basename ${CMAKE_CURRENT_LIST_FILE} NAME_WE)
set(_out "${CMAKE_CURRENT_BINARY_DIR}/${_basename}_cmake-vars.txt")
set(_cmake_vars "")
get_cmake_property(_varNames VARIABLES)
foreach(_varName ${_varNames})
if(ARGV0)
string(REGEX MATCH "${ARGV0}" _match "${_varName}")
if(_match)
set(_cmake_vars "${_cmake_vars}\n\n${_varName}=${${_varName}}")
endif()
else()
set(_cmake_vars "${_cmake_vars}\n\n${_varName}=${${_varName}}")
endif()
endforeach()
message(STATUS "Dumping current CMake variables to ...\n ${_out}")
file(WRITE "${_out}" "${_cmake_vars}")
endfunction(DUMP_CMAKE_VARS)