aboutsummaryrefslogtreecommitdiff
path: root/src/CMakeLists.txt
blob: 2048a64cc182bafded66cb2f8fcce84adca12f47 (plain)
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
99
100
101
102
103
104
105
project(cmocka-library C)

set(CMOCKA_PLATFORM_INCLUDE CACHE PATH "Path to include directory for cmocka_platform.h")
mark_as_advanced(CMOCKA_PLATFORM_INCLUDE)

set(CMOCKA_LINK_LIBRARIES
    ${CMOCKA_REQUIRED_LIBRARIES}
    CACHE INTERNAL "cmocka link libraries"
)

set(cmocka_SRCS
    cmocka.c
)

if (WIN32)
    set(cmocka_SRCS
        ${cmocka_SRCS}
        cmocka.def
    )
endif (WIN32)

add_library(cmocka ${cmocka_SRCS})

target_include_directories(cmocka
                           PRIVATE
                               ${CMOCKA_PLATFORM_INCLUDE}
                               ${cmocka_BINARY_DIR}
                           PUBLIC
                               $<BUILD_INTERFACE:${cmocka-header_SOURCE_DIR}>
                               $<INSTALL_INTERFACE:include>)

target_compile_options(cmocka
                       PRIVATE
                           ${DEFAULT_C_COMPILE_FLAGS}
                           -DHAVE_CONFIG_H)
if (CMOCKA_PLATFORM_INCLUDE)
    target_compile_options(cmocka
                           PRIVATE
                               -DCMOCKA_PLATFORM_INCLUDE)
endif()

target_link_libraries(cmocka PRIVATE ${CMOCKA_LINK_LIBRARIES})
set_property(TARGET
                 cmocka
             PROPERTY
                 DEFINE_SYMBOL
                     CMOCKA_EXPORTS
)

set_property(TARGET
                 cmocka
             PROPERTY
                VERSION
                    ${LIBRARY_VERSION}
)
set_property(TARGET
                 cmocka
             PROPERTY
                SOVERSION
                    ${LIBRARY_SOVERSION})

set_property(TARGET
                cmocka
             PROPERTY
                LINK_FLAGS
                "${DEFAULT_LINK_FLAGS}")

add_library(cmocka::cmocka ALIAS cmocka)

install(TARGETS cmocka
        EXPORT cmocka-config
        ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
        COMPONENT ${PROJECT_NAME})

install(EXPORT cmocka-config
        DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cmocka)

if (UNIT_TESTING)
    # Internal library
    add_library(cmocka-static STATIC ${cmocka_SRCS})

    target_include_directories(cmocka-static
                               PRIVATE
                                   ${CMOCKA_PLATFORM_INCLUDE}
                                   ${cmocka_BINARY_DIR}
                               PUBLIC
                                   ${cmocka-header_SOURCE_DIR})


    target_compile_options(cmocka-static
                           PRIVATE
                               ${DEFAULT_C_COMPILE_FLAGS}
                               -DHAVE_CONFIG_H)
    if (CMOCKA_PLATFORM_INCLUDE)
        target_compile_options(cmocka-static
                               PRIVATE
                                   -DCMOCKA_PLATFORM_INCLUDE)
    endif()

    target_link_libraries(cmocka-static PRIVATE ${CMOCKA_LINK_LIBRARIES})

    add_library(cmocka::static ALIAS cmocka-static)
endif()