Skip to content

Commit 3dba7fb

Browse files
authored
perf: optimize printable variables (#132)
Signed-off-by: l.feng <43399351+msclock@users.noreply.github.com>
1 parent 6f48ce8 commit 3dba7fb

3 files changed

Lines changed: 31 additions & 11 deletions

File tree

cmake/configure/Common.cmake

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,28 @@ include_guard(GLOBAL)
88
Show project version friendly
99
]]
1010
macro(show_project_version)
11-
message(STATUS "CMAKE_PROJECT_VERSION finally:${CMAKE_PROJECT_VERSION}")
12-
message(STATUS "CMAKE_PROJECT_VERSION_MAJOR: ${CMAKE_PROJECT_VERSION_MAJOR}")
13-
message(STATUS "CMAKE_PROJECT_VERSION_MINOR: ${CMAKE_PROJECT_VERSION_MINOR}")
14-
message(STATUS "CMAKE_PROJECT_VERSION_PATCH: ${CMAKE_PROJECT_VERSION_PATCH}")
15-
message(STATUS "CMAKE_PROJECT_VERSION_TWEAK: ${CMAKE_PROJECT_VERSION_TWEAK}")
11+
message(STATUS "CMake Project Version:")
12+
message(STATUS "\tCMAKE_PROJECT_VERSION:${CMAKE_PROJECT_VERSION}")
13+
message(
14+
STATUS "\tCMAKE_PROJECT_VERSION_MAJOR: ${CMAKE_PROJECT_VERSION_MAJOR}")
15+
message(
16+
STATUS "\tCMAKE_PROJECT_VERSION_MINOR: ${CMAKE_PROJECT_VERSION_MINOR}")
17+
message(
18+
STATUS "\tCMAKE_PROJECT_VERSION_PATCH: ${CMAKE_PROJECT_VERSION_PATCH}")
19+
message(
20+
STATUS "\tCMAKE_PROJECT_VERSION_TWEAK: ${CMAKE_PROJECT_VERSION_TWEAK}")
1621
endmacro()
1722

1823
#[[
1924
Show vcpkg configurition
2025
]]
2126
function(show_vcpkg_configuration)
2227
# Print all vcpkg variables
28+
message(STATUS "Vcpkg Integration:")
2329
get_cmake_property(_vars VARIABLES)
2430
foreach(_var IN LISTS _vars)
2531
if(_var MATCHES "^VCPKG_")
26-
message(STATUS "${_var} ${${_var}}")
32+
message(STATUS "\t${_var} ${${_var}}")
2733
endif()
2834
endforeach()
2935
endfunction()

cmake/configure/GitTools.cmake

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,26 @@ inline const StringOrView Describe() {
333333

334334
configure_file("${arg_CONFIGURE_HEADER_FILE}" "${arg_DESTINATION}" @ONLY)
335335

336-
get_filename_component(arg_DESTINATION_PATH ${arg_DESTINATION} DIRECTORY)
336+
get_filename_component(_destination_dir ${arg_DESTINATION} DIRECTORY)
337+
338+
string(REPLACE "${CMAKE_CURRENT_BINARY_DIR}" "" _binary_include_dir
339+
"${_destination_dir}")
340+
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}" "" _source_include_dir
341+
"${_destination_dir}")
342+
343+
if(NOT "${_binary_include_dir}" STREQUAL "${_destination_dir}")
344+
set(_include_dir_for_target
345+
"\${CMAKE_CURRENT_BINARY_DIR}${_binary_include_dir}")
346+
else()
347+
set(_include_dir_for_target
348+
"\${CMAKE_CURRENT_SOURCE_DIR}${_source_include_dir}")
349+
endif()
337350

338351
message(
339352
STATUS
340353
"Generated a git-based version header including project metadata in ${arg_DESTINATION} from ${arg_CONFIGURE_HEADER_FILE}
341354
Usage:
342-
target_include_directories(${arg_DESTINATION_PATH})
343-
# Or refer to https://github.com/msclock/cmake-modules/blob/master/cmake/configure/GitTools.cmake
344-
target_include_interface_directories(${arg_DESTINATION_PATH})")
355+
target_include_directories(${_include_dir_for_target})
356+
# or
357+
target_include_interface_directories(${_include_dir_for_target})")
345358
endfunction()

cmake/install/Common.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ include_guard(GLOBAL)
88
Show installation directories
99
]]
1010
macro(show_installation)
11+
message(STATUS "Installation Paths:")
1112
foreach(_p LIB BIN INCLUDE CMAKE)
1213
file(TO_NATIVE_PATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_${_p}DIR} _path)
13-
message(STATUS "Show ${_p} components installation path: ${_path}")
14+
message(STATUS "\t${_p} installation path: ${_path}")
1415
unset(_path)
1516
endforeach()
1617
endmacro()

0 commit comments

Comments
 (0)