summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-dev-kit/cmake/test/abi-interface-test.cmake
blob: 2e620349423612ded5cbbc081a4df0c0a2450bbc (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
option(DEVKIT_TEST "To test dev-kit" TRUE)
option(DEVKIT_TEST_CPP "To test dev-kit headers correct in \"C++\" compile" FALSE)
option(DEVKIT_TEST_STOP_ON_ERROR "To stop build if during \"C\" ABI test an error was found" FALSE)

if(NOT DEVKIT_TEST)
  return()
endif()

include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)

list(APPEND CMAKE_REQUIRED_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/include/kodi
                                    ${CMAKE_CURRENT_SOURCE_DIR}/../..)

message(STATUS "################################################################################")
message(STATUS "# Run test about dev-kit headers for correct style")
message(STATUS "#")

# Set minimal required defines
if(CORE_SYSTEM_NAME STREQUAL android)
  set(DEVKIT_TEST_DEFINES "\
#define HAS_GLES 3
#define TARGET_POSIX
#define TARGET_LINUX
#define TARGET_ANDROID
")
elseif(CORE_SYSTEM_NAME STREQUAL darwin_embedded)
  set(DEVKIT_TEST_DEFINES "\
#define HAS_GLES 2
#define TARGET_POSIX
#define TARGET_DARWIN
#define TARGET_DARWIN_EMBEDDED
")
elseif(CORE_SYSTEM_NAME STREQUAL osx)
  set(DEVKIT_TEST_DEFINES "\
#define HAS_GL 1
#define TARGET_DARWIN
#define TARGET_DARWIN_OSX
")
elseif(CORE_SYSTEM_NAME STREQUAL windows)
  set(DEVKIT_TEST_DEFINES "\
#define HAS_DX 1
#define WIN32
#define TARGET_WINDOWS
#define TARGET_WINDOWS_DESKTOP
")
elseif(CORE_SYSTEM_NAME STREQUAL linux)
  set(DEVKIT_TEST_DEFINES "\
#define HAS_GL 1
#define TARGET_POSIX
#define TARGET_LINUX
")
else()
  set(DEVKIT_TEST_DEFINES "\
#define HAS_GL 1
#define TARGET_POSIX
#define TARGET_FREEBSD
")
endif()

# Read list of all available headers
file(GLOB_RECURSE DEVKIT_HEADERS
  include/kodi/*.h
)

##
# Check the "C" headers itself with compile in "C"
#

message(STATUS "")
message(STATUS "================================================================================")
message(STATUS "Run \"C\" headers:")

set(DEVKIT_HEADER_NO 0)
foreach(DEVKIT_HEADER ${DEVKIT_HEADERS})
  if(NOT DEVKIT_HEADER MATCHES "c-api")
    continue()
  endif()

  string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/include/" "" DEVKIT_HEADER_NAME ${DEVKIT_HEADER})

  message(STATUS "--------------------------------------------------------------------------------")
  message(STATUS "Checking \"C\" ABI about \"#include <${DEVKIT_HEADER_NAME}>\":")

  math(EXPR DEVKIT_HEADER_NO "${DEVKIT_HEADER_NO}+1")
  set(DEVKIT_TEST_NAME "C_TEST_BUILD_A_${DEVKIT_HEADER_NO}")

  check_c_source_compiles("\
${DEVKIT_TEST_DEFINES}
#include \"${DEVKIT_HEADER}\"
int main()
{
  return 0;
}" ${DEVKIT_TEST_NAME})

  if (NOT ${DEVKIT_TEST_NAME} EQUAL 1)
    if(${DEVKIT_TEST_STOP_ON_ERROR})
      message(FATAL_ERROR " - Header not match needed \"C\" ABI: \"#include <${DEVKIT_HEADER_NAME}>\" (see CMakeError.log)")
    else()
      message(STATUS " - WARNING: Header not match needed \"C\" ABI: \"#include <${DEVKIT_HEADER_NAME}>\" (see CMakeError.log)")
    endif()
  endif()
endforeach()

##
# Check the "C++" headers itself with compile in "C"
#
message(STATUS "")
message(STATUS "================================================================================")
message(STATUS "Run \"C++\" headers (to confirm there a safe within \"C\"):")

set(DEVKIT_HEADER_NO 0)
foreach(DEVKIT_HEADER ${DEVKIT_HEADERS})
  if(DEVKIT_HEADER MATCHES "c-api")
    continue()
  endif()

  string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/include/" "" DEVKIT_HEADER_NAME ${DEVKIT_HEADER})

  message(STATUS "--------------------------------------------------------------------------------")
  message(STATUS "Checking \"C\" ABI about \"#include <${DEVKIT_HEADER_NAME}>\":")

  math(EXPR DEVKIT_HEADER_NO "${DEVKIT_HEADER_NO}+1")
  set(DEVKIT_TEST_NAME "C_TEST_BUILD_B_${DEVKIT_HEADER_NO}")

  check_c_source_compiles("\
${DEVKIT_TEST_DEFINES}
#include \"${DEVKIT_HEADER}\"
int main()
{
  return 0;
}" ${DEVKIT_TEST_NAME})

  if (NOT ${DEVKIT_TEST_NAME} EQUAL 1)
    if(${DEVKIT_TEST_STOP_ON_ERROR})
      message(FATAL_ERROR " - \"C++\" header not safe about \"C\" ABI: \"#include <${DEVKIT_HEADER_NAME}>\" (see CMakeError.log)")
    else()
      message(STATUS " - WARNING: \"C++\" header not safe about \"C\" ABI: \"#include <${DEVKIT_HEADER_NAME}>\" (see CMakeError.log)")
    endif()
  endif()
endforeach()

##
# Check the "C++" headers itself with compile in "C++"
#
if(DEVKIT_TEST_CPP)
  message(STATUS "")
  message(STATUS "================================================================================")
  message(STATUS "Run \"C++\" headers (to confirm there a correct within \"C++\"):")

  set(DEVKIT_HEADER_NO 0)
  foreach(DEVKIT_HEADER ${DEVKIT_HEADERS})
    if(DEVKIT_HEADER MATCHES "c-api")
      continue()
    endif()

    string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/include/" "" DEVKIT_HEADER_NAME ${DEVKIT_HEADER})

    message(STATUS "--------------------------------------------------------------------------------")
    message(STATUS "Checking \"C++\" about \"#include <${DEVKIT_HEADER_NAME}>\":")

    math(EXPR DEVKIT_HEADER_NO "${DEVKIT_HEADER_NO}+1")
    set(DEVKIT_TEST_NAME "CPP_TEST_BUILD_${DEVKIT_HEADER_NO}")

    check_cxx_source_compiles("\
${DEVKIT_TEST_DEFINES}
#include \"${DEVKIT_HEADER}\"
int main()
{
  return 0;
}" ${DEVKIT_TEST_NAME})

    if (NOT ${DEVKIT_TEST_NAME} EQUAL 1)
      if(${DEVKIT_TEST_STOP_ON_ERROR})
        message(FATAL_ERROR " - \"C++\" header failed to build: \"#include <${DEVKIT_HEADER_NAME}>\" (see CMakeError.log)")
      else()
        message(STATUS " - \"C++\" header failed to build: \"#include <${DEVKIT_HEADER_NAME}>\" (see CMakeError.log)")
      endif()
    endif()
  endforeach()
endif()