-
Notifications
You must be signed in to change notification settings - Fork 47
/
logging.cmake
191 lines (172 loc) · 6.73 KB
/
logging.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# Copyright (C) 2008-2014 LAAS-CNRS, JRL AIST-CNRS.
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
# ##############################################################################
# README #
# ##############################################################################
#
# This file implements an Autotools-like config.log logging file. This file is
# generated at each project configuration and contains all information about the
# system, the environment variables, the flags passed to CMake, etc.
#
# Logging file.
set(JRL_CMAKEMODULE_LOGGING_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/config.log")
get_directory_property(has_parent_scope PARENT_DIRECTORY)
if(has_parent_scope)
set(JRL_CMAKEMODULE_LOGGING_FILENAME
${JRL_CMAKEMODULE_LOGGING_FILENAME}
PARENT_SCOPE)
endif(has_parent_scope)
# Watched variables list. All watched variables final value will be displayed in
# the logging file.
set(LOGGING_WATCHED_VARIABLES "")
# Watched targets list. All watched target properties will be displayed in the
# logging file.
set(LOGGING_WATCHED_TARGETS "")
# Watched targets properties list.
set(LOGGING_WATCHED_TARGETS_PROPERTIES
COMPILE_DEFINITIONS
COMPILE_FLAGS
DEFINE_SYMBOL
ENABLE_EXPORTS
EXCLUDE_FROM_ALL
LINK_FLAGS
SOVERSION
VERSION)
# Define character separating values in a portable way.
if(UNIX)
set(LIST_SEPARATOR ":")
elseif(WIN32)
set(LIST_SEPARATOR ";")
else(UNIX)
message(FATAL_ERROR "Your platform is not supported.")
endif(UNIX)
# LOGGING_INITIALIZE()
# --------------
#
# This initializes the logging process by: - cleaning any previous config.log -
# writing global information.
#
function(LOGGING_INITIALIZE)
# Retrieve interesting information.
site_name(HOSTNAME)
# Write logging file.
file(REMOVE ${JRL_CMAKEMODULE_LOGGING_FILENAME})
file(APPEND ${JRL_CMAKEMODULE_LOGGING_FILENAME}
"This file contains any messages produced by compilers while\n"
"running CMake, to aid debugging if configure makes a mistake.\n\n")
file(
APPEND ${JRL_CMAKEMODULE_LOGGING_FILENAME}
"It was created by ${CMAKE_PROJECT_NAME} CMake configuration process "
"${PROJECT_VERSION}, which was\n"
"generated by CMake ${CMAKE_VERSION}.\n\n")
file(
APPEND ${JRL_CMAKEMODULE_LOGGING_FILENAME}
"## --------- ##\n"
"## Platform. ##\n"
"## --------- ##\n"
"\n"
"hostname = ${HOSTNAME}\n"
"system = ${CMAKE_SYSTEM}\n"
"processor = ${CMAKE_SYSTEM_PROCESSOR}\n"
"generator = ${CMAKE_GENERATOR}\n"
"\n")
if(NOT "$ENV{PATH}" STREQUAL "")
string(REPLACE "${LIST_SEPARATOR}" "\nPATH " PATH "$ENV{PATH}")
else()
set(PATH undefined)
endif()
file(APPEND ${JRL_CMAKEMODULE_LOGGING_FILENAME} "PATH " ${PATH} "\n\n")
if(NOT "$ENV{PKG_CONFIG_PATH}" STREQUAL "")
string(REPLACE "${LIST_SEPARATOR}" "\nPKG_CONFIG_PATH " PKG_CONFIG_PATH
"$ENV{PKG_CONFIG_PATH}")
else()
set(PKG_CONFIG_PATH "undefined")
endif()
file(APPEND ${JRL_CMAKEMODULE_LOGGING_FILENAME} "PKG_CONFIG_PATH "
${PKG_CONFIG_PATH} "\n\n")
endfunction(LOGGING_INITIALIZE)
# LOGGING_FINALIZE()
# --------------
#
# This finalizes the logging process by: - logging the watched variables
#
function(LOGGING_FINALIZE)
file(
APPEND ${JRL_CMAKEMODULE_LOGGING_FILENAME}
"## ---------------- ##\n"
"## CMake variables. ##\n"
"## ---------------- ##\n"
"\n"
"CMAKE_ROOT = ${CMAKE_ROOT}\n"
"CMAKE_INCLUDE_PATH = ${CMAKE_INCLUDE_PATH}\n"
"CMAKE_LIBRARY_PATH = ${CMAKE_LIBRARY_PATH}\n"
"CMAKE_PREFIX_PATH = ${CMAKE_PREFIX_PATH}\n"
"CMAKE_INSTALL_ALWAYS = ${CMAKE_INSTALL_ALWAYS}\n"
"CMAKE_SKIP_RPATH = ${CMAKE_SKIP_RPATH}\n"
"CMAKE_SUPPRESS_REGENERATION = ${CMAKE_SUPPRESS_REGENERATION}\n"
"BUILD_SHARED_LIBS = ${BUILD_SHARED_LIBS}\n"
"\n"
"CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}\n"
"PROJECT_SOURCE_DIR = ${PROJECT_SOURCE_DIR}\n"
"PROJECT_SOURCE_DIR = ${PROJECT_SOURCE_DIR}\n"
"PROJECT_BINARY_DIR = ${PROJECT_BINARY_DIR}\n"
"CMAKE_BINARY_DIR = ${CMAKE_BINARY_DIR}\n"
"\n"
"CMAKE_AR = ${CMAKE_AR}\n"
"CMAKE_RANLIB = ${CMAKE_RANLIB}\n"
"CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}\n"
"CMAKE_CONFIGURATION_TYPES = ${CMAKE_CONFIGURATION_TYPES}\n"
"CMAKE_SHARED_LINKER_FLAGS = ${CMAKE_SHARED_LINKER_FLAGS}\n"
"\n"
"CMAKE_C_COMPILER = ${CMAKE_C_COMPILER}\n"
"CMAKE_C_FLAGS = ${CMAKE_C_FLAGS}\n"
"CMAKE_C_FLAGS_DEBUG = ${CMAKE_C_FLAGS_DEBUG}\n"
"CMAKE_C_FLAGS_RELEASE = ${CMAKE_C_FLAGS_RELEASE}\n"
"CMAKE_CXX_COMPILER = ${CMAKE_CXX_COMPILER}\n"
"CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}\n"
"CMAKE_CXX_FLAGS_DEBUG = ${CMAKE_CXX_FLAGS_DEBUG}\n"
"CMAKE_CXX_FLAGS_RELEASE = ${CMAKE_CXX_FLAGS_RELEASE}\n"
"CMAKE_CXX_FLAGS_RELWITHDEBINFO = ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}\n"
"\n"
"CMAKE_STATIC_LIBRARY_PREFIX = ${CMAKE_STATIC_LIBRARY_PREFIX}\n"
"CMAKE_STATIC_LIBRARY_SUFFIX = ${CMAKE_STATIC_LIBRARY_SUFFIX}\n"
"CMAKE_SHARED_LIBRARY_PREFIX = ${CMAKE_SHARED_LIBRARY_PREFIX}\n"
"CMAKE_SHARED_LIBRARY_SUFFIX = ${CMAKE_SHARED_LIBRARY_SUFFIX}\n"
"CMAKE_SHARED_MODULE_PREFIX = ${CMAKE_SHARED_MODULE_PREFIX}\n"
"CMAKE_SHARED_MODULE_SUFFIX = ${CMAKE_SHARED_MODULE_SUFFIX}\n"
"\n")
file(APPEND ${JRL_CMAKEMODULE_LOGGING_FILENAME}
"## ------------------ ##\n" "## Watched variables. ##\n"
"## ------------------ ##\n" "\n")
list(REMOVE_DUPLICATES LOGGING_WATCHED_VARIABLES)
foreach(VAR ${LOGGING_WATCHED_VARIABLES})
if(NOT DEFINED ${VAR})
set(${VAR} "undefined")
endif()
file(APPEND ${JRL_CMAKEMODULE_LOGGING_FILENAME} "${VAR} = ${${VAR}}\n")
endforeach()
file(APPEND ${JRL_CMAKEMODULE_LOGGING_FILENAME}
"## ---------------- ##\n" "## Watched targets. ##\n"
"## ---------------- ##\n" "\n")
list(REMOVE_DUPLICATES LOGGING_WATCHED_TARGETS)
foreach(TARGET ${LOGGING_WATCHED_TARGETS})
foreach(PROPERTY ${LOGGING_WATCHED_TARGETS_PROPERTIES})
get_target_property(VALUE ${TARGET} ${PROPERTY})
file(APPEND ${JRL_CMAKEMODULE_LOGGING_FILENAME}
"${TARGET}_${PROPERTY} = ${VALUE}\n")
endforeach()
file(APPEND ${JRL_CMAKEMODULE_LOGGING_FILENAME} "\n")
endforeach()
endfunction(LOGGING_FINALIZE)