File: zxing.cmake

package info (click to toggle)
zxing-cpp 3.0.0%2Bds-1~exp2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 30,204 kB
  • sloc: ansic: 69,384; cpp: 34,587; php: 2,790; python: 199; makefile: 30; sh: 3
file content (75 lines) | stat: -rw-r--r-- 2,620 bytes parent folder | download | duplicates (4)
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

macro(zxing_add_package_stb)
    unset (STB_FOUND CACHE)

    if (ZXING_DEPENDENCIES STREQUAL "AUTO")
        find_package(PkgConfig)
        pkg_check_modules (STB IMPORTED_TARGET stb)
    elseif (ZXING_DEPENDENCIES STREQUAL "LOCAL")
        find_package(PkgConfig REQUIRED)
        pkg_check_modules (STB REQUIRED IMPORTED_TARGET stb)
    endif()

    if (NOT STB_FOUND)
        include(FetchContent)
        FetchContent_Declare (stb
            GIT_REPOSITORY https://github.com/nothings/stb.git)
        FetchContent_MakeAvailable (stb)
        add_library(stb::stb INTERFACE IMPORTED)
        target_include_directories(stb::stb INTERFACE ${stb_SOURCE_DIR})
    else()
        add_library(stb::stb ALIAS PkgConfig::STB)
    endif()
endmacro()

macro(zxing_add_package name depname git_repo git_rev)
    unset(${name}_FOUND CACHE) # see https://github.com/zxing-cpp/zxing-cpp/commit/8db14eeead45e0f1961532f55061d5e4dd0f78be#commitcomment-66464026

    if (ZXING_DEPENDENCIES STREQUAL "AUTO")
        find_package (${name} CONFIG)
    elseif (ZXING_DEPENDENCIES STREQUAL "LOCAL")
        find_package (${name} REQUIRED CONFIG)
    endif()

    if (NOT ${name}_FOUND)
        include(FetchContent)

        if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.28")
            FetchContent_Declare(
                ${depname}
                GIT_REPOSITORY ${git_repo}
                GIT_TAG ${git_rev}
                EXCLUDE_FROM_ALL
            )

            if (${depname} STREQUAL "googletest")
                # Prevent overriding the parent project's compiler/linker settings on Windows
                set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
            endif()

            FetchContent_MakeAvailable(${depname})
        else()
            FetchContent_Declare(
                ${depname}
                GIT_REPOSITORY ${git_repo}
                GIT_TAG ${git_rev}
            )

            if (${depname} STREQUAL "googletest")
                # Prevent overriding the parent project's compiler/linker settings on Windows
                set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
            endif()

            FetchContent_GetProperties(${depname})
            if (NOT ${depname}_POPULATED)
                FetchContent_Populate(${depname})
                add_subdirectory(
                    ${${depname}_SOURCE_DIR}
                    ${${depname}_BINARY_DIR}
                    EXCLUDE_FROM_ALL
                )
            endif()
        # set (${name}_POPULATED TRUE) # this is supposed to be done in MakeAvailable but it seems not to?!?
        endif()
    endif()
endmacro()