~aleteoryx/muditaos

ref: sign_test muditaos/cmake/modules/Utils.cmake -rw-r--r-- 2.0 KiB
a217eeb3 — Dawid Wojtas [BH-2024] Fix lack of alarm directory after updating software 1 year, 5 months ago
                                                                                
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
# An equivalent of install() which allows to declare multiple components using
# a custom 'COMPONENTS' clause. This clause must be the last on the
# argument list. The original 'COMPONENT' from install() clause must not appear
# on the argument list.  
function(multicomp_install)
    list(FIND ARGN "COMPONENTS" CLAUSE_INDEX)
    list(SUBLIST ARGN 0 ${CLAUSE_INDEX} INSTALL_ARGN)
    math(EXPR COMPS_INDEX "${CLAUSE_INDEX}+1")
    list(SUBLIST ARGN ${COMPS_INDEX} ${ARGC} COMPONENTS)
    foreach(COMP IN LISTS COMPONENTS)
        install(${INSTALL_ARGN} COMPONENT ${COMP})
    endforeach()
endfunction()

macro(print_var VARIABLE)
    if(${VARIABLE})
        message(STATUS "${Green}${VARIABLE}: '${Orange}${${VARIABLE}}${ColourReset}'")
    else()
        message(STATUS "${Orange}No such variable: '${Red}${VARIABLE}${ColourReset}'")
    endif()
endmacro()

function(strip_executable TARGET)
    if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
        set(STRIP_PARAMS "-S")
    else()
        set(STRIP_PARAMS --strip-debug --strip-unneeded)
    endif ()

    if (${CMAKE_BUILD_TYPE} STREQUAL "Release")
        add_custom_command(TARGET ${TARGET} POST_BUILD
            COMMAND ${CMAKE_STRIP} ${STRIP_PARAMS} $<TARGET_FILE:${TARGET}>
            COMMENT "Striping  ${TARGET}"
            )
    endif()

    if (${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
        add_custom_command(TARGET ${TARGET} POST_BUILD
            COMMAND ${CMAKE_OBJCOPY} --only-keep-debug
                    $<TARGET_FILE:${TARGET}>
                    $<TARGET_FILE:${TARGET}>.debug
            COMMAND ${CMAKE_STRIP} ${STRIP_PARAMS} $<TARGET_FILE:${TARGET}>
            COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=$<TARGET_FILE:${TARGET}>.debug
                    $<TARGET_FILE:${TARGET}>
            COMMENT "Striping  ${TARGET}"
            )
    endif()
endfunction()

function(add_subdirectory_if_exists)
    set(_DIR ${ARGV0})
    if(IS_DIRECTORY ${_DIR})
        add_subdirectory(${_DIR})
    endif()
endfunction()