sandboxed-api/contrib/libxls/CMakeLists.txt
Christian Blichmann 4ec1c6be64 CMake: Update policy settings to 3.26
This avoids a warning in newer CMake versions. For `CMP0083`, we still need to
explicitly select `NEW` behavior. `check_pie_supported()` will error if it is
unset even on later CMake versions.

PiperOrigin-RevId: 531200735
Change-Id: Icb17a00cac087bd6888f8a9b9f8dd837358a6090
2023-05-11 07:50:52 -07:00

112 lines
3.3 KiB
CMake

# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.13..3.26)
project(sapi_libxls C CXX)
include(CTest)
include(GoogleTest)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
if(NOT TARGET sapi::sapi)
set(SAPI_ROOT "../.." CACHE PATH "Path to the Sandboxed API source tree")
add_subdirectory("${SAPI_ROOT}"
"${CMAKE_BINARY_DIR}/sandboxed-api-build"
EXCLUDE_FROM_ALL)
endif()
FetchContent_Declare(libxls
GIT_REPOSITORY https://github.com/libxls/libxls.git
GIT_TAG 448240067919707eb95fb009f76f3fdb439b1427 # 2021-01-04
)
FetchContent_GetProperties(libxls)
if(NOT libxls_POPULATED)
FetchContent_Populate(libxls)
set(libxls_STATUS_FILE "${libxls_SOURCE_DIR}/config.status")
if(EXISTS "${libxls_STATUS_FILE}")
file(SHA256 "${libxls_STATUS_FILE}" _sapi_CONFIG_STATUS)
endif()
if(NOT _sapi_CONFIG_STATUS STREQUAL "${libxls_CONFIG_STATUS}")
message("-- Configuring libxls...")
execute_process(
COMMAND autoreconf -i
WORKING_DIRECTORY "${libxls_SOURCE_DIR}"
RESULT_VARIABLE _sapi_libxls_autoreconf_result
)
if(NOT _sapi_libxls_autoreconf_result EQUAL "0")
message(FATAL_ERROR "Configuration for libxls failed: "
"${_sapi_libxls_autoreconf_result}")
endif()
execute_process(
COMMAND ./configure --disable-dependency-tracking
--disable-shared
--quiet
WORKING_DIRECTORY "${libxls_SOURCE_DIR}"
RESULT_VARIABLE _sapi_libxls_config_result
)
if(NOT _sapi_libxls_config_result EQUAL "0")
message(FATAL_ERROR "Configuration for libxls failed: "
"${_sapi_libxls_config_result}")
endif()
file(SHA256 "${libxls_SOURCE_DIR}/config.status" _sapi_CONFIG_STATUS)
set(libxls_CONFIG_STATUS "${_sapi_CONFIG_STATUS}" CACHE INTERNAL "")
endif()
endif()
add_library(libxls STATIC
"${libxls_SOURCE_DIR}/src/endian.c"
"${libxls_SOURCE_DIR}/src/locale.c"
"${libxls_SOURCE_DIR}/src/ole.c"
"${libxls_SOURCE_DIR}/src/xls.c"
"${libxls_SOURCE_DIR}/src/xlstool.c"
)
target_include_directories(libxls PUBLIC
"${libxls_SOURCE_DIR}"
"${libxls_SOURCE_DIR}/include"
)
configure_file(xls.gen.h.in xls.gen.h)
add_sapi_library(sapi_libxls
FUNCTIONS xls_open_file
xls_getWorkSheet
xls_parseWorkSheet
xls_cell
xls_close_WS
xls_close_WB
xls_getError
INPUTS "${PROJECT_BINARY_DIR}/xls.gen.h"
LIBRARY libxls
LIBRARY_NAME Libxls
NAMESPACE ""
)
add_library(sapi_contrib::libxls ALIAS sapi_libxls)
target_include_directories(sapi_libxls INTERFACE
"${PROJECT_BINARY_DIR}"
)
if(SAPI_BUILD_EXAMPLES)
add_subdirectory(example)
endif()
if(BUILD_TESTING AND SAPI_BUILD_TESTING)
add_subdirectory(test)
endif()