xref: /aosp_15_r20/external/sandboxed-api/contrib/libxls/CMakeLists.txt (revision ec63e07ab9515d95e79c211197c445ef84cefa6a)
1# Copyright 2022 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)
16project(sapi_libxls C CXX)
17include(CTest)
18include(GoogleTest)
19
20set(CMAKE_CXX_STANDARD 17)
21set(CMAKE_CXX_STANDARD_REQUIRED True)
22
23if(NOT TARGET sapi::sapi)
24  set(SAPI_ROOT "../.." CACHE PATH "Path to the Sandboxed API source tree")
25  add_subdirectory("${SAPI_ROOT}"
26                   "${CMAKE_BINARY_DIR}/sandboxed-api-build"
27                   EXCLUDE_FROM_ALL)
28endif()
29
30FetchContent_Declare(libxls
31  GIT_REPOSITORY https://github.com/libxls/libxls.git
32  GIT_TAG        448240067919707eb95fb009f76f3fdb439b1427 # 2021-01-04
33)
34
35FetchContent_GetProperties(libxls)
36if(NOT libxls_POPULATED)
37  FetchContent_Populate(libxls)
38  set(libxls_STATUS_FILE "${libxls_SOURCE_DIR}/config.status")
39  if(EXISTS "${libxls_STATUS_FILE}")
40    file(SHA256 "${libxls_STATUS_FILE}" _sapi_CONFIG_STATUS)
41  endif()
42  if(NOT _sapi_CONFIG_STATUS STREQUAL "${libxls_CONFIG_STATUS}")
43    message("-- Configuring libxls...")
44    execute_process(
45      COMMAND autoreconf -i
46      WORKING_DIRECTORY "${libxls_SOURCE_DIR}"
47      RESULT_VARIABLE _sapi_libxls_autoreconf_result
48    )
49    if(NOT _sapi_libxls_autoreconf_result EQUAL "0")
50      message(FATAL_ERROR "Configuration for libxls failed: "
51                          "${_sapi_libxls_autoreconf_result}")
52    endif()
53    execute_process(
54      COMMAND ./configure --disable-dependency-tracking
55                          --disable-shared
56                          --quiet
57      WORKING_DIRECTORY "${libxls_SOURCE_DIR}"
58      RESULT_VARIABLE _sapi_libxls_config_result
59    )
60    if(NOT _sapi_libxls_config_result EQUAL "0")
61      message(FATAL_ERROR "Configuration for libxls failed: "
62                          "${_sapi_libxls_config_result}")
63    endif()
64    file(SHA256 "${libxls_SOURCE_DIR}/config.status" _sapi_CONFIG_STATUS)
65    set(libxls_CONFIG_STATUS "${_sapi_CONFIG_STATUS}" CACHE INTERNAL "")
66  endif()
67endif()
68
69add_library(libxls STATIC
70  "${libxls_SOURCE_DIR}/src/endian.c"
71  "${libxls_SOURCE_DIR}/src/locale.c"
72  "${libxls_SOURCE_DIR}/src/ole.c"
73  "${libxls_SOURCE_DIR}/src/xls.c"
74  "${libxls_SOURCE_DIR}/src/xlstool.c"
75)
76target_include_directories(libxls PUBLIC
77  "${libxls_SOURCE_DIR}"
78  "${libxls_SOURCE_DIR}/include"
79)
80
81configure_file(xls.gen.h.in xls.gen.h)
82
83add_sapi_library(sapi_libxls
84  FUNCTIONS xls_open_file
85
86            xls_getWorkSheet
87            xls_parseWorkSheet
88
89            xls_cell
90
91            xls_close_WS
92            xls_close_WB
93
94            xls_getError
95  INPUTS "${PROJECT_BINARY_DIR}/xls.gen.h"
96  LIBRARY libxls
97  LIBRARY_NAME Libxls
98  NAMESPACE ""
99)
100add_library(sapi_contrib::libxls ALIAS sapi_libxls)
101target_include_directories(sapi_libxls INTERFACE
102  "${PROJECT_BINARY_DIR}"
103)
104
105if(SAPI_BUILD_EXAMPLES)
106  add_subdirectory(example)
107endif()
108
109if(BUILD_TESTING AND SAPI_BUILD_TESTING)
110  add_subdirectory(test)
111endif()
112