-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathliblibinfo.cmake
45 lines (40 loc) · 1.71 KB
/
liblibinfo.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
# Lib²Info ; https://github.com/bkaestner/liblibinfo
# SPDX-License-Identifier: MIT
find_package(Git)
set(LIBLIBINFO_LOC "${CMAKE_CURRENT_LIST_DIR}")
function(add_libinfo TARGET)
set(options STRIP_LIBINFO_BANNER)
set(singleValueArguments LICENSE DESCRIPTION)
cmake_parse_arguments(PC "${options}" "${singleValueArguments}" "" ${ARGN})
if(NOT TARGET ${TARGET})
message(FATAL_ERROR "Cannot add library info to target \"${TARGET}\" which is not built by this project.")
endif()
# Version string creation
get_target_property(version "${TARGET}" VERSION)
if(version)
set(INFO_VERSION " - Version: ${version}")
elseif(PROJECT_VERSION)
set(INFO_VERSION " - Version: ${PROJECT_VERSION}")
endif()
string(TIMESTAMP TODAY "%Y-%m-%d")
if(DEFINED ENV{USER})
set(INFO_AUTHOR "by $ENV{USER}")
endif()
if(GIT_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short "HEAD" OUTPUT_VARIABLE GIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${GIT_EXECUTABLE} status --porcelain OUTPUT_VARIABLE GIT_STATUS OUTPUT_STRIP_TRAILING_WHITESPACE)
if(GIT_STATUS)
set(GIT_HASH "${GIT_HASH}*dirty")
endif()
set(GIT_HASH "(${GIT_HASH})")
endif()
if(NOT PC_STRIP_LIBINFO_BANNER)
set(INFO_STRING "\\n\\nThis library was made executable via liblibinfo.\\n (https://github.com/bkaestner/liblibinfo)")
else()
set(INFO_STRING "")
endif()
set(LIBINFO_ADDITIONAL_SOURCE "${CMAKE_BINARY_DIR}/${TARGET}.d/libinfo.c")
configure_file("${LIBLIBINFO_LOC}/libinfo.c.in" "${LIBINFO_ADDITIONAL_SOURCE}")
set_property(TARGET ${TARGET} APPEND PROPERTY SOURCES "${LIBINFO_ADDITIONAL_SOURCE}")
target_link_libraries(${TARGET} PRIVATE "-e liblibinfo_print")
endfunction()