xref: /aosp_15_r20/external/sandboxed-api/oss-internship-2020/libpng/CMakeLists.txt (revision ec63e07ab9515d95e79c211197c445ef84cefa6a)
1# Copyright 2020 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15cmake_minimum_required(VERSION 3.12)
16
17project(sandboxed_libpng CXX)
18
19set(CMAKE_CXX_STANDARD 17)
20set(CMAKE_CXX_STANDARD_REQUIRED True)
21
22# Set this on the command-line
23set(SAPI_ROOT "" CACHE PATH "Path to the Sandboxed API source tree")
24# To obtain a full SAPI_ROOT check out its source separately:
25#   git clone https://github.com/google/sandboxed-api.git /path/to/sapi_root
26# Then configure:
27#   mkdir -p build && cd build
28#   cmake .. -G Ninja -DSAPI_ROOT=/path/to/sapi_root
29
30option(LIBPNG_SAPI_BUILD_EXAMPLES "" OFF)
31option(LIBPNG_SAPI_BUILD_TESTING "" OFF)
32
33set(SAPI_BUILD_EXAMPLES ${LIBPNG_SAPI_BUILD_EXAMPLES} CACHE BOOL "" FORCE)
34set(SAPI_BUILD_TESTING ${LIBPNG_SAPI_BUILD_TESTING} CACHE BOOL "" FORCE)
35
36set (CMAKE_FIND_LIBRARY_SUFFIXES .a $ {CMAKE_FIND_LIBRARY_SUFFIXES})
37find_package(PNG REQUIRED)
38list(GET PNG_INCLUDE_DIRS 0 PNG_INCLUDE_DIR)
39
40add_subdirectory(wrapper)
41
42add_subdirectory(
43  "${SAPI_ROOT}"
44  "${CMAKE_BINARY_DIR}/sandboxed-api-build"
45  # Omit this to have the full Sandboxed API in IDE
46  EXCLUDE_FROM_ALL
47)
48
49add_sapi_library(libpng_sapi
50  # List of functions that we want to include in the
51  # generated sandboxed API class
52
53  FUNCTIONS png_image_free
54            png_image_finish_read
55            png_image_write_to_file
56            png_image_begin_read_from_file
57
58            png_get_rowbytes
59            png_get_bit_depth
60            png_get_color_type
61            png_get_image_width
62            png_get_image_height
63
64            png_set_IHDR
65            png_set_sig_bytes
66            png_set_interlace_handling
67
68            png_read_info
69            png_read_image_wrapper
70            png_read_update_info
71
72            png_write_end
73            png_write_info
74            png_write_image_wrapper
75
76            png_create_info_struct
77            png_create_read_struct_wrapper
78            png_create_write_struct_wrapper
79
80            png_init_io_wrapper
81
82            png_sig_cmp
83
84            png_fread
85            png_fdopen
86            png_rewind
87            png_fclose
88
89            png_setjmp
90
91  INPUTS "${PNG_INCLUDE_DIR}/png.h"
92         wrapper/func.h
93                          # Header files or .cc files that should be parsed
94  LIBRARY wrapper
95                          # Library dependency from the add_library() above
96  LIBRARY_NAME LibPNG     # Name prefix for the generated header. Will be
97                          # suffixed with "Api" and "Sandbox" as needed.
98  NAMESPACE ""            # Optional C++ namespace to wrap the generated code
99)
100
101target_include_directories(libpng_sapi INTERFACE
102  "${PROJECT_BINARY_DIR}"  # To find the generated SAPI header
103)
104
105if (LIBPNG_SAPI_BUILD_EXAMPLES)
106  add_subdirectory(examples)
107endif()
108
109if (LIBPNG_SAPI_BUILD_TESTING)
110  add_subdirectory(tests)
111endif()
112
113