File: Common.cmake

package info (click to toggle)
allegro4.4 2:4.4.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 20,744 kB
  • sloc: ansic: 164,458; asm: 17,620; cpp: 3,848; objc: 1,687; sh: 1,107; python: 676; pascal: 179; makefile: 55; perl: 29; lisp: 1
file content (98 lines) | stat: -rw-r--r-- 3,429 bytes parent folder | download | duplicates (5)
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
# For OS X frameworks to work you must add headers to the target's sources.
function(add_our_library target)
    add_library(${target} ${ARGN})
    set_target_properties(${target}
        PROPERTIES
        DEBUG_POSTFIX -debug
        PROFILE_POSTFIX -profile
        )
endfunction(add_our_library)

function(set_our_framework_properties target nm)
    if(WANT_FRAMEWORKS)
        if(WANT_EMBED)
            set(install_name_dir "@executable_path/../Frameworks")
        else()
            set(install_name_dir "${FRAMEWORK_INSTALL_PREFIX}")
        endif(WANT_EMBED)
        set_target_properties(${target}
            PROPERTIES
            FRAMEWORK on
            OUTPUT_NAME ${nm}
            INSTALL_NAME_DIR "${install_name_dir}"
            )
    endif(WANT_FRAMEWORKS)
endfunction(set_our_framework_properties)

function(install_our_library target)
    install(TARGETS ${target}
            LIBRARY DESTINATION "lib${LIB_SUFFIX}"
            ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
            FRAMEWORK DESTINATION "${FRAMEWORK_INSTALL_PREFIX}"
            RUNTIME DESTINATION "bin"
            # Doesn't work, see below.
            # PUBLIC_HEADER DESTINATION "include"
            )
endfunction(install_our_library)

# Unfortunately, CMake's PUBLIC_HEADER support doesn't install into nested
# directories well, otherwise we could rely on install(TARGETS) to install
# header files associated with the target.  Instead we use the install(FILES)
# to install headers.  We reuse the MACOSX_PACKAGE_LOCATION property,
# substituting the "Headers" prefix with "include".
function(install_our_headers)
    foreach(hdr ${ARGN})
        get_source_file_property(LOC ${hdr} MACOSX_PACKAGE_LOCATION)
        string(REGEX REPLACE "^Headers" "include" LOC ${LOC})
        install(FILES ${hdr} DESTINATION ${LOC})
    endforeach()
endfunction(install_our_headers)

function(add_our_executable nm)
    add_executable(${nm} ${ARGN})
    target_link_libraries(${nm} allegro)
    if(PSP)
        add_psp_executable(${nm})
    endif(PSP)
endfunction()

# Oh my. CMake really is bad for this - but I couldn't find a better
# way.
function(sanitize_cmake_link_flags return)
   SET(acc_libs)
   foreach(lib ${ARGN})
      # Watch out for -framework options (OS X)
      IF (NOT lib MATCHES "-framework.*|.*framework")
         # Remove absolute path.
         string(REGEX REPLACE "/.*/(.*)" "\\1" lib ${lib})

         # Remove .a/.so/.dylib.
         string(REGEX REPLACE "lib(.*)\\.(a|so|dylib)" "\\1" lib ${lib})

         # Remove -l prefix if it's there already.
         string(REGEX REPLACE "-l(.*)" "\\1" lib ${lib})

        set(acc_libs "${acc_libs} -l${lib}")
      ENDIF()
   endforeach(lib)
   set(${return} ${acc_libs} PARENT_SCOPE)
endfunction(sanitize_cmake_link_flags)

function(copy_files target)
    if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
        return()
    endif()
    foreach(file ${ARGN})
        # The "./" is NOT redundant as CMAKE_CFG_INTDIR may be "/".
        add_custom_command(
            OUTPUT  "./${CMAKE_CFG_INTDIR}/${file}"
            DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${file}"
            COMMAND "${CMAKE_COMMAND}" -E copy
                    "${CMAKE_CURRENT_SOURCE_DIR}/${file}"
                    "./${CMAKE_CFG_INTDIR}/${file}"
            )
    endforeach()
    add_custom_target(${target} ALL DEPENDS ${ARGN})
endfunction()

# vim: set sts=4 sw=4 et: