xref: /aosp_15_r20/external/sandboxed-api/contrib/lodepng/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.13..3.26)
16
17project(lodepng_sapi C CXX)
18include(CTest)
19include(GoogleTest)
20
21set(CMAKE_CXX_STANDARD 17)
22set(CMAKE_CXX_STANDARD_REQUIRED 17)
23
24if(NOT TARGET sapi::sapi)
25  set(SAPI_ROOT "../.." CACHE PATH "Path to the Sandboxed API source tree")
26  add_subdirectory("${SAPI_ROOT}"
27                   "${CMAKE_BINARY_DIR}/sandboxed-api-build"
28                   EXCLUDE_FROM_ALL)
29endif()
30
31FetchContent_Declare(lodepng
32  GIT_REPOSITORY https://github.com/lvandeve/lodepng.git
33  GIT_TAG        3d9fda048393e32cc11d0c3d3caba0a85c1c2dfe # 2022-05-22
34)
35FetchContent_MakeAvailable(lodepng)
36
37# lodepng can be compiled as both C++ and C. We want the latter, so enforce
38# C as the language. set_source_files_properties() does not work here.
39configure_file(lodepng.gen.h.in
40              "${lodepng_BINARY_DIR}/lodepng.gen.h")
41configure_file("${lodepng_SOURCE_DIR}/lodepng.cpp"
42               "${lodepng_BINARY_DIR}/lodepng.c" COPYONLY)
43
44# Build static library
45add_library(lodepng STATIC
46  "${lodepng_BINARY_DIR}/lodepng.c"
47  "${lodepng_BINARY_DIR}/lodepng.gen.h"
48  "${lodepng_SOURCE_DIR}/lodepng.h"
49)
50target_include_directories(lodepng PUBLIC
51  "${lodepng_BINARY_DIR}"
52  "${lodepng_SOURCE_DIR}"
53)
54target_compile_definitions(lodepng PUBLIC
55  LODEPNG_NO_COMPILE_CPP
56)
57
58# Build SAPI library
59add_sapi_library(lodepng_sapi
60  FUNCTIONS lodepng_decode_memory
61            lodepng_decode32
62            lodepng_decode24
63
64            lodepng_decode_file
65            lodepng_decode32_file
66            lodepng_decode24_file
67
68            lodepng_encode_memory
69            lodepng_encode32
70            lodepng_encode24
71
72            lodepng_encode_file
73            lodepng_encode32_file
74            lodepng_encode24_file
75
76            lodepng_save_file
77            lodepng_load_file
78
79  INPUTS "${lodepng_BINARY_DIR}/lodepng.gen.h"
80  LIBRARY lodepng
81  LIBRARY_NAME Lodepng
82  NAMESPACE ""
83)
84add_library(sapi_contrib::lodepng ALIAS lodepng_sapi)
85target_include_directories(lodepng_sapi INTERFACE
86  "${PROJECT_BINARY_DIR}"  # To find the generated SAPI header
87)
88
89# Examples and tests
90add_subdirectory(examples)
91