Skip to content

Commit c123d3b

Browse files
committed
Add a CMake debug include, with simple variables dump for development
1 parent 64b6a44 commit c123d3b

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

cmake/CMakeDebugMacros.cmake

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Macros/functions for debugging CMake
2+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
#
4+
# Copyright (c) 2016, Larry Shaffer, <lshaffer (at) boundlessgeo (dot) com>>
5+
# Redistribution and use is allowed according to the terms of the BSD license.
6+
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
7+
8+
9+
# Dump current CMake variables to file
10+
#
11+
# Usage:
12+
# INCLUDE(CMakeDebugMacros)
13+
# DUMP_CMAKE_VARS() or DUMP_CMAKE_VARS("regex")
14+
#
15+
# regex: optional ARGV0 regular expression for filtering output variable names
16+
#
17+
# Outputs the result relative to the current CMake file being processed and
18+
# writes to a file with name "<file-basename>_cmake-vars.txt" to the current
19+
# build (binary) directory
20+
#
21+
function(DUMP_CMAKE_VARS)
22+
23+
get_filename_component(_basename ${CMAKE_CURRENT_LIST_FILE} NAME_WE)
24+
set(_out "${CMAKE_CURRENT_BINARY_DIR}/${_basename}_cmake-vars.txt")
25+
26+
set(_cmake_vars "")
27+
get_cmake_property(_varNames VARIABLES)
28+
foreach(_varName ${_varNames})
29+
if(ARGV0)
30+
string(REGEX MATCH "${ARGV0}" _match "${_varName}")
31+
if(_match)
32+
set(_cmake_vars "${_cmake_vars}\n\n${_varName}=${${_varName}}")
33+
endif()
34+
else()
35+
set(_cmake_vars "${_cmake_vars}\n\n${_varName}=${${_varName}}")
36+
endif()
37+
endforeach()
38+
39+
message(STATUS "Dumping current CMake variables to ...\n ${_out}")
40+
file(WRITE "${_out}" "${_cmake_vars}")
41+
42+
endfunction(DUMP_CMAKE_VARS)

0 commit comments

Comments
 (0)